public GameGui(Game game, Individual opponent) { InitializeComponent(); this.game = game; this.playerTwo = opponent; playerOne = new Individual(game.getBoard(), "Player One", false, null, null); playerOne.setValue(1); playerOne.setIsHumanPlayer(true); this.playerTwo.setBoard(game.getBoard()); drawTree = new DrawTree(opponent.getStrategy()); }
public void playHumanVsBest(Individual best) { Board board = new Board(); Game game = new Game(board); best.setValue(2); //TreeDraw td = new TreeDraw(best); GameGui gui = new GameGui(game, best); gui.ShowDialog(); }
private void playAgainst_Click(object sender, EventArgs e) { initializeFunctionTerminalSets(); Board board = new Board(); Game game = new Game(board); selectRandomMaxIndex = bestEvalSelectMethod.SelectedIndex == 0; Individual PlayerOne = new Individual(board, "Player One", selectRandomMaxIndex, functionList, terminalList); Individual PlayerTwo = new Individual(board, "Player Two", selectRandomMaxIndex, functionList, terminalList); PlayerOne.setValue(1); PlayerTwo.setValue(2); GameGui gui = new GameGui(game, PlayerTwo); this.Hide(); gui.ShowDialog(); this.Show(); PlayerOne.setIsHumanPlayer(true); PlayerTwo.setIsHumanPlayer(true); PlayerOne.setBoard(board); PlayerTwo.setBoard(board); }
public int playGame(Individual startingPlayer, Individual secondPlayer) { int result = -1; // set the starting player value to 1 ('X') startingPlayer.setValue(1); // set the second player value to 2 ('O') secondPlayer.setValue(2); while (true) { // starting player code block ////////////////////////////////////// // can make either a random move or a move using the strategy tree if (!startingPlayer.makeStrategyMove()) { // an attempt to make a move on an occupied space was made // abort the game Console.WriteLine("Move " + startingPlayer.getValue() + " Failed"); Console.WriteLine("SHUTTING GAME DOWN: OBSOLETE GARBAGE"); break; } // check if the starting player move resulted in a win result = board.checkWin(startingPlayer); if (result != 0) { break; } ////////////////////////////////////// // starting player code block end // second player code block ////////////////////////////////////// if (!secondPlayer.makeStrategyMove()) { Console.WriteLine("Move " + secondPlayer.getValue() + " Failed"); Console.WriteLine("SHUTTING GAME DOWN: OBSOLETE GARBAGE"); break; } result = board.checkWin(secondPlayer); if (result != 0) { break; } ////////////////////////////////////// } // add the result accordingly switch (result) { case DRAW: startingPlayer.addDraw(true); secondPlayer.addDraw(false); break; case START_WIN: startingPlayer.addWin(true); secondPlayer.addLoss(false); break; case SECOND_WIN: secondPlayer.addWin(false); startingPlayer.addLoss(true); break; case INCOMPLETE_TREE: Console.WriteLine("Incomplete Tree Error"); break; default: Console.WriteLine("CATASTROPHIC FAILURE!!!"); break; } return(result); }