public Player GetWinnerOfGame(Player redPlayer, Player blackPlayer) { Winner w; Board gameState = new Board(); redPlayer.isRed = true; blackPlayer.isRed = false; int turns = 0; do { gameState = GameSim.GetNextMove(gameState, blackPlayer.myBrain, false); gameState = GameSim.GetNextMove(gameState, redPlayer.myBrain, true); w = gameState.GetWinner(); turns++; }while (w == Winner.noWinner && turns < 100); Interlocked.Increment(ref _gamesPlayed); if (w == Winner.noWinner)//after 100 turns, game is considered a draw. Black player "wins" but neither player gets credit for the win/loss { return(blackPlayer); } if (w == Winner.black) { blackPlayer.IncrementWins(); redPlayer.IncrementLosses(); return(blackPlayer); } else { redPlayer.IncrementWins(); blackPlayer.IncrementLosses(); return(redPlayer); } }
//Each time this method is called causes the AI whose turn it is to choose a move. public void AIMove() { if (blackTurn && !AIvsAI) { throw new InvalidOperationException("AIMove method called when it is not AI's turn"); } if (blackTurn) { _boardState = GameSim.GetNextMove(boardState, blackPlayer, false); } else { _boardState = GameSim.GetNextMove(boardState, redPlayer, true); } blackTurn = !blackTurn; }