public void resetGame(Text consoleTmp, bool human_x, bool human_o) { console = consoleTmp; board.resetBoard(); player_x = new TTTPlayer('X', human_x); if (player_o.human) { player_o = new TTTPlayer('O', human_o); } else { player_o = new TTTPlayer('O', human_o, computerO); //DEBUG } gameText = "Test Tic Tac Toe AI Test Version 0.4.\n"; gameText += "Say \"Menu\" for a list of instructions.\n"; gameText += board.getBoard(); console.text = gameText; numberOfMoves = 0; victory = false; currentPlayer = player_x; if (!player_x.human) { handleInput(-1); } }
public int getMoveFromComputer_old(TTTBoard currentBoard) { TTTBoard testBoard = new TTTBoard(); testBoard.resetBoard(); char testmarker = marker; for (int magic = 0; magic < 2; magic++) { for (int i = 0; i < 9; i++) { for (int y = 0; y < 9; y++) { testBoard.board[y] = currentBoard.board[y]; } if (testBoard.attemptMove(i, testmarker)) { if (testBoard.checkVictory()) { return(i); } } } if (testmarker == 'X') { testmarker = 'O'; } else { testmarker = 'X'; } } //Move in center if that is available if (currentBoard.checkMove(4)) { return(4); } //Move in corner if available (center is already taken...) Random random = new Random(); for (int ctr = 0; ctr < 5; ctr++) { //int move = random.Next(0, 4); int move = ctr; move *= 2; //ensure move is even (0,2,4,6,8) if (currentBoard.checkMove(move)) { return(move); } } return(random.Next(0, 9)); }