public void MakeMove(IMove move) { ReversiMove currentMove = move as ReversiMove; 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 (gameBoard[rowIndex, colIndex] != players[currentPlayer].GetPlayerID()) { gameBoard[rowIndex, colIndex] = players[currentPlayer].GetPlayerID(); rowIndex += rowDirection; colIndex += colDirection; } } ChangePlayer(); updateCounters(); lastMove = currentMove; if (this.MoveComplete != null && updateValidMoves(true)) MoveComplete.Invoke(currentMove.Row,currentMove.Column,currentMove.PlayerID); }
void square_MouseDown(object sender, MouseButtonEventArgs e) { Square square = sender as Square; if (square != null) { if (square.rectangle.Fill == Brushes.Red) { int row = (int)square.GetValue(Grid.RowProperty); int col = (int)square.GetValue(Grid.ColumnProperty); ReversiMove move = new ReversiMove(row, col, board.GetCurrentPlayerID(), 0); board.MakeMove(move); if (board.GetCurrentPlayerID() == alg.ComputerPlayerID) { computerThread = new Thread(this.computerMove); computerThread.Start(); } } } }
public List<IMove> GetLegalMoves(IPlayer player) { List<IMove> list = new List<IMove>(); for(int row =0;row<7; ++row) for (int col = 0; col < 7; ++col) { if (validMoves[row, col]) { ReversiMove move = new ReversiMove(row, col, players[currentPlayer].GetPlayerID(),0); list.Add(move); } } return list; }