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 TTTGame(Text consoleTmp, bool human_x, bool human_o) { console = consoleTmp; player_x = new TTTPlayer('X', human_x); player_o = new TTTPlayer('O', human_o); 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; displayMenuText(); currentPlayer = player_x; if (!player_x.human) { handleInput(-1); } //invalid input is used here to get the ball rolling if AI is first up. }
public void handleInput(int input) { console.text += "::"; if (numberOfMoves < 9 && !victory) { int boardIndex = 0; if (currentPlayer.human) { //HUMAN console.text += "Human\n"; boardIndex = input; } else { //AI SECTION IN-PROGRESS console.text += "AI\n"; currentPlayer.console = console; boardIndex = currentPlayer.getMoveFromComputer(board); } bool worked = board.attemptMove(boardIndex, currentPlayer.getMarker()); if (worked) { numberOfMoves++; victory = board.checkVictory(); if (currentPlayer.getMarker() == 'X') { currentPlayer = player_o; } else { currentPlayer = player_x; } console.text += "Move Completed\n"; } else { console.text += "Move Failed\n"; } console.text += board.getBoard(); if (victory) { console.text += "Player " + currentPlayer.getMarker() + " Lost!\nSay \"New Game\" to play again.\n"; if (!currentPlayer.human) { currentPlayer.getMoveFromComputer(board); } //Update AI with the loss } else if (numberOfMoves == 9) { console.text += "Cat's Game!\nSay \"New Game\" to play again.\n"; } else if (!currentPlayer.human) { handleInput(-1); }//Don't wait for human command to take AI's Turn... else { console.text += "Player " + currentPlayer.getMarker() + ", select your move.\n"; } //Prompt Human Player } else { console.text += "Cat's Game!\nSay \"New Game\" to play again.\n"; } // console.text += gameText; }