SharpChess.com Forum Index SharpChess.com
C# Chess Game
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Undo multithread

 
Post new topic   Reply to topic    SharpChess.com Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
Nimzo



Joined: 15 Mar 2005
Posts: 64

PostPosted: Mon Jul 21, 2008 5:26 pm    Post subject: Undo multithread Reply with quote

Undo multithread

Context: Vista Ultimate .NET 3.5, SharpChess v 2.52 Official Release, Level 16, Pondering.

Symptom

Unhandled exception NullReferenceException

Stack: Think, Aspirate, AlphaBeta..., Move.Undo
Board.HashCodeA ^= move.To.Piece.HashCodeA;

Diagnostic

The piece has already been moved in the main UI thread before the Move.Undo in the thread Think.
So move.To.Piece is null. One cannot access to move.To.Piece.HashCodeA.

Tool

In Move.cs, add in debug the conditional breakpoint before the exception:
Code:
      public static void Undo(Move move)
      {
#if DEBUG
         if (move.To.Piece == null)
             Debugger.Break();
#endif
         Board.HashCodeA ^= move.To.Piece.HashCodeA; // un_XOR the piece ...

Suggestion

FrmMain.cs
Code:
      private void StartNormalGame()
      {
         if (!Game.LoadBackup())
         {
            frmDifficulty formDifficulty = new frmDifficulty();
            formDifficulty.ShowDialog(this);
         }

         /* 08/07/21 Nimzo: original code
         Game.StartNormalGame();
          */

         OrientBoard();
         RenderBoard();
         RenderClocks();
         SetFormState();
         timer.Start();

         // 08/07/21 Nimzo: moved after RenderBoard
         // because SetFormState calls CanMove, GenerateLegalMoves, Undo
         Game.StartNormalGame();

        } // end StartNormalGame

Even if the problem of the concurrent access to the chess Board during pondering / thinking and the main UI thread is not fully solved, the above suggestion allows to properly restart SharpChess in the context of the scratch stored in the following BackupGame.sharpchess.

Code:
<Game FEN="8/8/5kN1/7K/8/6PP/8/8 w - - 1 70" TurnNo="138" WhitePlayer="Human" BlackPlayer="Computer" BoardOrientation="White" Version="2.5.2.0" DifficultyLevel="16" ClockMoves="120" ClockSeconds="36000" MaximumSearchDepth="0" Pondering="1" UseRandomOpeningMoves="1" />

In the Immediate Window, after 69. Kxh5
Code:
Board.DebugDisplay()
0 1 2 3 4 5 6 7 :PlayerToPlay = White
8:. . . . . . . . :7 x Ng8 Nb8 Bf8 Bc8 Rh8 Ra8 Qd8
7:. . . . . . . . :6
6:. . . . . k N . :5
5:. . . . . . . K :4
4:. . . . . . . . :3
3:. . . . . . P P :2
2:. . . . . . . . :1
1:. . . . . . . . :0 x Nb1 Bf1 Bc1 Rh1 Ra1 Qd1
  a b c d e f g h :TurnNo = 138. " "

The full game in PGN format (the time is between braces):
Code:
[Event "SharpChess"][Site "?"][Date "2008.07.21"][Round "1"]
[White "Human"][Black "Computer"][Result "1-0"]
[PlyCount "177"][Flip "1"][Ver "3.0.0.0"][Level "16"][Depth "0"]
[Ponder "1"][Book "1"][TimeControl "120/36000"]

1.e4 {11} f6 {0} 2.d4 {19} Nc6 {130} 3.d5 {32} Ne5 {315} 4.f4 {36} Nf7 {431}
5.Nf3 {42} Ngh6 {551} 6.Bd3 {48} e5 {712} 7.O-O {75} exf4 {872} 8.Bxf4 {82} Bc5+ {980}
9.Kh1 {86} Ng4 {1205} 10.Qe2 {90} O-O {1428} 11.h3 {94} Nge5 {1667} 12.Nbd2 {227} Nxd3 {2297}
13.cxd3 {231} a6 {2570} 14.d4 {313} Ba7 {2974} 15.Rac1 {353} d6 {3198}
16.Rc2 {361} Nh8 {3452} 17.Rfc1 {367} Rf7 {3672} 18.Nc4 {409} Ng6 {3919}
19.Bg3 {421} b5 {4064} 20.Na5 {433} Bb6 {4240} 21.Nc6 {449} Qd7 {4390}
22.e5 {495} dxe5 {4543} 23.dxe5 {499} Qxd5 {4779} 24.Rd1 {508} Qxa2 {4889}
25.b4 {598} Qa3 {5023} 26.e6 {608} Rf8 {5294} 27.e7 {618} Re8 {5511} 28.Rd8 {637} Qa1+ {6167}
29.Kh2 {649} Kf7 {6341} 30.Rcd2 {2307} Nxe7 {6555} 31.Rxe8 {2662} Nxc6 {6708}
32.Rxc8 {2670} Rxc8 {6912} 33.Rd7+ {2685} Kg8 {7450} 34.Rd1 {2938} Qxd1 {7892}
35.Qxd1 {2947} Rd8 {8102} 36.Qb3+ {3043} Kh8 {8310} 37.Qc3 {3195} Ne7 {8969}
38.Qa3 {3781} Ra8 {9094} 39.Qd3 {4511} Ng8 {9750} 40.Qd7 {5108} Ra7 {10006}
41.Qc6 {5476} Ne7 {10656} 42.Qe8+ {5572} Ng8 {10850} 43.Nd2 {5709} a5 {11256}
44.bxa5 {5735} Bxa5 {11615} 45.Nb3 {5748} Bb6 {12167} 46.Qxb5 {5981} Ra3 {12657}
47.Bd6 {6153} Ra8 {12986} 48.Qc6 {6766} Rb8 {13125} 49.Nc5 {6989} cxd6 {13360}
50.Nd7 {7152} Ne7 {13998} 51.Qxd6 {7189} Rd8 {14114} 52.Qxe7 {7342} Bc7+ {14664}
53.Kg1 {8406} Rg8 {14853} 54.Nxf6 {9292} Bd8 {15053} 55.Nxg8 {9939} Bxe7 {15232}
56.Nxe7 {9954} h5 {15352} 57.g3 {9964} Kh7 {15483} 58.Kg2 {10019} g6 {15972}
59.Kf3 {10111} Kg7 {16112} 60.Kf4 {10501} Kf6 {16764} 61.Nd5+ {11428} Ke6 {17029}
62.Nc3 {11521} Kd6 {17270} 63.Ne4+ {11775} Ke6 {17916} 64.Kg5 {12209} Kf7 {18234}
65.Nc5 {12772} Kg7 {18361} 66.Ne6+ {12952} Kf7 {18537} 67.Nf4 {13021} Kg7 {18904}
68.Nxg6 {13112} Kf7 {19054} 69.Kxh5 {13718} Kf6 {19168} 70.Kh6 {13839} Ke6 {19550}
71.g4 {13901} Kd5 {19673} 72.Kg7 {14082} Ke4 {19792} 73.h4 {14110} Kf3 {20132}
74.g5 {14136} Kg4 {20484} 75.Kh6 {14188} Kg3 {20700} 76.h5 {14278} Kg4 {20966}
77.Ne7 {14312} Kf4 {21091} 78.g6 {14499} Ke5 {21395} 79.Kg7 {14550} Ke6 {21541}
80.Ng8 {14602} Kd5 {21688} 81.Kf6 {14706} Ke4 {21894} 82.h6 {14872} Kd4 {22095}
83.h7 {14922} Ke4 {22267} 84.h8=Q {14973} Ke3 {22862} 85.Ne7 {15003} Kd3 {22862}
86.g7 {15024} Ke4 {22862} 87.g8=Q {15044} Kd4 {22863} 88.Qh3 {15050} Ke4 {22864}
89.Qgg4# {15063} 1-0

1... f6 is not the best defense for Black
22. e5 sacrifice of d4 and a2 to win the queen after 34. Rd1 with the threat Qe6+ winning Rc8.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    SharpChess.com Forum Index -> Bugs All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group