private void PlayMove(OthelloMove move) { if (!_board.IsValidMove(move)) { return; } SquareState previousPlayerColor = _board.CurrentPlayer; _board.PlayMove(move); _lastPlayedMove = move; _board.FixUpCurrentPlayer(); SyncBoardToUI(); this.BeginInvoke(new PostMoveMethodDelegate(DoPostMoveProcessing), new object[] { previousPlayerColor }); }
private void LoadGame_Click(object sender, System.EventArgs e) { _board = OthelloBoard.LoadFromFile("game.txt"); _lastPlayedMove = null; SyncBoardToUI(); }
static void ReadBook() { #if USE_TRANSPOSITION_TABLE StreamReader reader = null; try { reader = new StreamReader("book.txt"); } catch { // No opening book, oh well... return; } // Each line is a game, and looks like: +d3-c3+c4-e3+c2-b3+d2...-a5+a7-a8+b8-b7: -04 10 // -04 is the final score for black. 10 is always there and should be ignored for (int x = 0; ; x++) { string s = reader.ReadLine(); if (s == null) { break; } OthelloBoard board = OthelloBoard.CreateStartingBoard(); int i; i = s.LastIndexOf(':'); int val = int.Parse(s.Substring(i + 2, 3)); if (val < 0) { val -= 500; } else if (val > 0) { val += 500; } // Only use the first 10 moves to limit size for (i = 0; i < (10 * 3); i += 3) { if (s[i] == ':') { break; } OthelloMove move = new OthelloMove((s[i + 1] - 'a'), (s[i + 2] - '1')); board.PlayMove(move); board.FixUpCurrentPlayer(); _transpositionTable.AddEntry(board.GetHashCode(), 60 /*ply*/, (board.CurrentPlayer == SquareState.Black) ? val : -val, TranspositionTableElementType.Exact, -1, -1); move = null; } board.FixUpCurrentPlayer(); /* * int expectedVal = board.BlackSquares - board.WhiteSquares; * Debug.Assert(val == expectedVal); * Debug.Assert(board.GameOver); */ board = null; } reader.Close(); #endif }
public bool IsValidMove(OthelloMove move) { return(IsValidMove(move.X, move.Y)); }
public int NumberCaptured(OthelloMove move) { return(NumberCaptured(move.X, move.Y)); }
public void PlayMove(OthelloMove move) { PlayMove(move.X, move.Y); }