public ReversiBoard(ReversiBoard board, bool isVisualBoard)
 {
     this.gameBoard = new int[8, 8];
     for (int i = 0; i < 8; ++i)
         for (int j = 0; j < 8; ++j)
         {
             this.gameBoard[i, j] = board.gameBoard[i, j];
             this.safeDisc[i, j] = board.safeDisc[i, j];
         }
     this.currentPlayer = board.currentPlayer;
     this.blackCount = board.blackCount;
     this.whiteCount = board.whiteCount;
     this.emptyCount = board.emptyCount;
     GameOver += new EndGame(calculateWinner);
     this.players = board.players;
     this.validMoves = new bool[8, 8];
     if (isVisualBoard)
     {
         this.MoveComplete = board.MoveComplete;
         this.NoLegalMoveAvailable = board.NoLegalMoveAvailable;
         this.GameOver += board.GameOver;
     }
     updateValidMoves(board.previousPlayerHadMoves);
     updateCounters();
 }
 public ReversiWindow()
 {
     InitializeComponent();
     winnerLabel.Visibility = Visibility.Hidden;
     gameHistory = new List<ReversiBoard>();
     myRepaint = new Repaint(this.repaint);
     board = new ReversiBoard(0);
     ReversiPlayer player = new ReversiPlayer(ComputerPlayer);
     alg = new Algorithms(player);
     intializeVisualBoard();
     this.UpdateLabel += new ReversiWindow.GameOver(updateWinnerLabel);
     upDateGameStatus(-1, -1, 0);
     board.NoLegalMoveAvailable += new ReversiBoard.HasMoves(board_NoLegalMoveAvailable);
     board.GameOver += new ReversiBoard.EndGame(board_GameOver);
     board.MoveComplete += new ReversiBoard.BoardMove(board_MoveComplete);
     if (board.GetCurrentPlayer().GetPlayerID() == alg.ComputerPlayerID)
     {
         computerThread = new Thread(this.computerMove);
         computerThread.Start();
     }
 }
        private void moveList_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            ListView list = sender as ListView;
            if (list != null)
            {
                if (list.SelectedIndex != -1)
                {
                    MessageBoxResult result = MessageBox.Show("Do you wish to restore the game from this position? ",
                        "Restore",
                        MessageBoxButton.YesNo,
                        MessageBoxImage.Exclamation,
                        MessageBoxResult.No);
                    if (result == MessageBoxResult.Yes)
                    {
                        this.board = new ReversiBoard(gameHistory[list.SelectedIndex],true);
                        int selectedIndex = list.SelectedIndex;
                        for (int index = list.Items.Count - 1; index > selectedIndex; --index)
                        {
                            gameHistory.RemoveAt(index);
                            list.Items.RemoveAt(index);
                        }
                        this.intializeVisualBoard();
                        this.repaint(-1, -1, 0);
                        if (alg.ComputerPlayerID == board.GetCurrentPlayerID())
                        {
                            computerThread = new Thread(this.computerMove);
                            computerThread.Start();
                        }
                    }

                }
            }
            list.SelectedIndex = -1;
            e.Handled = true;
        }
        public IBoardGame TestMove(IMove move)
        {
            ReversiBoard board = new ReversiBoard(this , false);
            ReversiMove currentMove = move as ReversiMove;
            board.gameBoard[currentMove.Row, currentMove.Column] = players[currentPlayer].GetPlayerID();
            for (int rowDirection = -1; rowDirection <= 1; ++rowDirection)
                for (int colDirection = -1; colDirection <= 1; ++colDirection)
                    if (!(rowDirection == 0 && colDirection == 0) && isFlanking(currentMove.Row, currentMove.Column, rowDirection, colDirection))
                    {
                        int rowIndex = currentMove.Row + rowDirection;
                        int colIndex = currentMove.Column + colDirection;
                        while (board.gameBoard[rowIndex, colIndex] != players[currentPlayer].GetPlayerID())
                        {
                            board.gameBoard[rowIndex, colIndex] = players[currentPlayer].GetPlayerID();
                            rowIndex += rowDirection;
                            colIndex += colDirection;

                        }

                    }

            board.ChangePlayer();
            board.updateCounters();
            board.updateValidMoves(true);
            return board as IBoardGame;
        }