Ejemplo n.º 1
0
        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 });
        }
Ejemplo n.º 2
0
 private void LoadGame_Click(object sender, System.EventArgs e)
 {
     _board          = OthelloBoard.LoadFromFile("game.txt");
     _lastPlayedMove = null;
     SyncBoardToUI();
 }
Ejemplo n.º 3
0
        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
        }
Ejemplo n.º 4
0
 public bool IsValidMove(OthelloMove move)
 {
     return(IsValidMove(move.X, move.Y));
 }
Ejemplo n.º 5
0
 public int NumberCaptured(OthelloMove move)
 {
     return(NumberCaptured(move.X, move.Y));
 }
Ejemplo n.º 6
0
 public void PlayMove(OthelloMove move)
 {
     PlayMove(move.X, move.Y);
 }