Skip to content

Commit

Permalink
Fix crash when a multiplayer opponent forfeits; include leading zero …
Browse files Browse the repository at this point in the history
…in seconds of turn time
  • Loading branch information
penteract committed Jun 22, 2021
1 parent 0ead4de commit 9f4e087
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 25 deletions.
8 changes: 6 additions & 2 deletions DataInterfaceConsoleTest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ private static void DoDataDump(DataInterface di)
else if(times.Count == n){
times[n-1] = c=='w'?di.GetWT():di.GetBT();
}
if(times[0]!=0){ lastRun+=$"{{{times[n-1]}}}";}
if(times[0]!=0){
var t = times[n-1];
lastRun+=$"{{{t/60}:{t%60:00}}}";
}
}
if (movetype==0){
lastRun+=($"({mem.moveSourceL}T{mem.moveSourceT-firstT}){board.Pieces[mem.moveSourceX*board.width+mem.moveSourceY].Notation()}{(char)(97+mem.moveSourceX)}{1+mem.moveSourceY}{(char)(97+mem.moveDestX)}{1+mem.moveDestY} ");
Expand All @@ -179,7 +182,8 @@ private static void DoDataDump(DataInterface di)
if (( state==GameState.EndedBlackWon
|| state==GameState.EndedDraw
|| state==GameState.EndedWhiteWon)
&& !written){
&& !written
&& cnt>5){
written = true;
var filename = "5dpgn"+DateTime.Now.ToString("yyyyMMdd_HHmmss")+".txt";
File.WriteAllText(filename,lastRun);
Expand Down
58 changes: 36 additions & 22 deletions FiveDChessDataInterface/DataInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,36 +200,50 @@ public GameState GetCurrentGameState()
else
{
var whoWon = this.MemLocGameEndedWinner.GetValue();
var gs = this.MemLocGameState.GetValue();
Console.WriteLine($"gs: {gs}, gameendedWinner {whoWon}");

if (whoWon == -1)
if (gs == 0)
{
if(whoWon!=-1){//
Console.WriteLine("Unexpected Data - gs is 0(running) but winning player '{whoWon}' is not -1");
//throw new UnexpectedChessDataException();
}
return GameState.Running;
}
else
{
if (whoWon == 0)
{
if (gs==1){
if(whoWon==0){
return GameState.EndedWhiteWon;
}
if(whoWon==1){
return GameState.EndedWhiteWon;
}
else{
Console.WriteLine("Unexpected Data - gs is 1(ended with winner) but winning player '{whoWon}' is not 0 or 1");
return GameState.Unknown;
}
}
if (gs==2){
return GameState.EndedDraw;
}
if(gs==3){
//Forfeit
if(whoWon==0){
return GameState.EndedWhiteWon;
}
else
{
var gs = this.MemLocGameState.GetValue();

if (gs == 2)
{
return GameState.EndedDraw;
}
else if (gs == 1) // someone won, which can only be black
{
return GameState.EndedBlackWon;
}
else
{
throw new UnexpectedChessDataException();
}
if(whoWon==1){
return GameState.EndedWhiteWon;
}
else{
Console.WriteLine("Unexpected Data - gs is 1(forfeit) but winning player '{whoWon}' is not 0 or 1");
return GameState.Unknown;
}
}
else{
Console.WriteLine("Unexpected Data - gs is not 0,1,2 or 3");
return GameState.Unknown;
}
}
}
}
}
}
3 changes: 2 additions & 1 deletion FiveDChessDataInterface/Types/GameState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public enum GameState : int
Running,
EndedDraw,
EndedWhiteWon,
EndedBlackWon
EndedBlackWon,
Unknown
}
}

0 comments on commit 9f4e087

Please sign in to comment.