// Add a random tetris shape to the arraylist // Add the shape to the tool bar // Also find the ai command when ai is enabled public void addShape() { shapeTrack = new ArrayList<Integer>(); int n = (int) (Math.random() * 7); switch (n) { case (0): shapes.add(new Block(THA.WIDTH / 2 - 40, -80, new Color(0, 0, 128))); break; case (1): shapes.add(new Line(THA.WIDTH / 2 - 40, -80, new Color(75, 0, 130))); break; case (2): shapes.add(new LeftZ(THA.WIDTH / 2 - 40, -80, new Color(255, 215, 0))); break; case (3): shapes.add(new RightZ(THA.WIDTH / 2 - 40, -80, new Color(255, 20, 147))); break; case (4): shapes.add(new T(THA.WIDTH / 2 - 40, -80, new Color(205, 0, 0))); break; case (5): shapes.add(new LeftL(THA.WIDTH / 2 - 40, -80, new Color(255, 165, 0))); break; case (6): shapes.add(new RightL(THA.WIDTH / 2 - 40, -80, new Color(0, 128, 0))); break; default: System.out.println("Impossible Error!!!"); break; } ns.clear(); ns.addShape(shapes); if (shapeAI.getAI()) { aiCommand = shapeAI.initAI(map, shapes.get(0)); } }
/** * Have the computer play against itself, putting output int the default Java console. You can * also have your new AI player play from here, with no GUI output. It may be useful for testing. * If you want a human to play, use GUI.main. */ public static void main(String[] args) { /* p1 is the first player, p2 is the second player. This is set to * have to Dummy players--playing randomly. * To play the game with your own AI object, use assignments like you * see in the comments after these two assignments. In those assignments, * the second argument of the constructor is the depth to which AI * searches the game space. */ Solver p1 = new Dummy(Board.Player.RED); Solver p2 = new Dummy(Board.Player.YELLOW); // Solver p1= new AI(Board.Player.RED, 5); // Solver p2= new AI(Board.Player.YELLOW, 5); Game game = new Game(p1, p2); game.runGame(); // testGetPossibleMoves(); // Board a = new Board(); // State y = new State(Board.Player.RED, a, null); // y.initializeChildren(); // testInitializeChildren(y); Board b = new Board(); State newState = new State(Board.Player.RED, b, null); AI ai = new AI(Board.Player.RED, 2); ai.createGameTree(newState, 2); ai.minimax(newState); newState.writeToFile(); }
public void tryFlip(int player) { if (player == playerTurn && !isFacecardPickup()) { // flipping GamePanel.playNoiseFlip(); stackPot.addToTop(playerCards.get(player).removeTopCard()); log.finer(getPlayerName(player) + " flipped the " + Card.toString(stackPot.getTopCard())); if (Card.isFaceCard(stackPot.getTopCard())) { topFacecardOwner = player; topFacecardMaxSize = Card.getRank(stackPot.getTopCard()); switch (topFacecardMaxSize) { case Card.ACE: topFacecardMaxSize = stackPot.size() + 4; break; case Card.KING: topFacecardMaxSize = stackPot.size() + 3; break; case Card.QUEEN: topFacecardMaxSize = stackPot.size() + 2; break; case Card.JACK: topFacecardMaxSize = stackPot.size() + 1; break; default: throw new RuntimeException( "This should never happen. A face card was not an ace, king, queen, or jack."); } turnIncrement(); } else if (topFacecardOwner == -1) { // if no facecards have been played this hand turnIncrement(); } if (playerCards.get(player).isEmpty()) { log.fine(getPlayerName(player) + " is eliminated because they flipped their last card"); eliminatePlayer(player); } if (isSlap()) { AI.registerEvent(AI.TYPESLAP); } else { AI.registerEvent(AI.TYPEFLIP); } } else { // flipping out of turn if (playerCards.get(player).isEmpty()) { // flipping out of turn but have no cards log.finer( getPlayerName(player) + " tried to flip a card even though they have no cards..."); } else { // flipping out of turn so burning log.fine(getPlayerName(player) + " tried to flip a card illegally and had to burn a card"); burn(player); } } }
public void trySlap(int player) { log.finer(getPlayerName(player) + " is trying to slap: " + topFiveCards()); if (isSlap()) { // successful slap log.fine(getPlayerName(player) + " just slapped some cards!"); pickupPot(player); GamePanel.playNoiseSlap(); gamePanel.addRenderable( new RenderableImageKinetic(this, RenderableImageKinetic.SLAP, player)); } else if (player == topFacecardOwner && isFacecardPickup()) { // successful pickup log.fine(getPlayerName(player) + " picked up some cards"); pickupPot(player); GamePanel.playNoisePickup(); gamePanel.addRenderable( new RenderableImageKinetic(this, RenderableImageKinetic.PICKUP, player)); AI.registerEvent(AI.TYPENOTHING); // so the AI will make a move if it is their turn now } else if (stackPot.isEmpty()) { // if they slapped an empty pot // we don't punish them because this probably just means there was a slap, but someone else // has already picked it up. log.finer(getPlayerName(player) + " slapped an empty pot. (They did not have to burn)"); } else { burn(player); } }
@Override public List<CodeRangeMetrics> getCodeRangeMetrics() { Map<String, MetricValue<?>> row = new HashMap<>(); row.put(KSLOC.getName(), new MetricValue<Double>(getKsloc(), KSLOC)); row.put(PERSON_MONTH.getName(), new MetricValue<Double>(getPersonMonth(), PERSON_MONTH)); row.put(PERSON_YEARS.getName(), new MetricValue<Double>(getPersonYears(), PERSON_YEARS)); row.put( SCHEDULED_MONTH.getName(), new MetricValue<Double>(getScheduledMonth(), SCHEDULED_MONTH)); row.put( SCHEDULED_YEARS.getName(), new MetricValue<Double>(getScheduledYears(), SCHEDULED_YEARS)); row.put(TEAM_SIZE.getName(), new MetricValue<Double>(getTeamSize(), TEAM_SIZE)); row.put(COSTS.getName(), new MetricValue<Double>(getEstimatedCosts(), COSTS)); row.put(SALARY.getName(), new MetricValue<Money>(getMoney(), SALARY)); row.put(AI.getName(), new MetricValue<Double>(getProject().getAi(), AI)); row.put(BI.getName(), new MetricValue<Double>(getProject().getBi(), BI)); row.put(CI.getName(), new MetricValue<Double>(getProject().getCi(), CI)); row.put(DI.getName(), new MetricValue<Double>(getProject().getDi(), DI)); List<CodeRangeMetrics> metrics = new ArrayList<>(); metrics.add( new CodeRangeMetrics( sourceCodeLocation, CodeRangeType.FILE, sourceCodeLocation.getName(), IntermediateCoCoMoEvaluatorParameter.ALL, row)); return metrics; }
/** Controls the movements and actions of character and tetris pieces */ public void keyPressed(KeyEvent key) { String keyText = KeyEvent.getKeyText(key.getKeyCode()); if (!pause) { if (!shapeAI.getAI()) { if (keyText.equalsIgnoreCase("a")) { shapes.get(0).moveLeft(map); shapeTrack.add(1); } if (keyText.equalsIgnoreCase("d")) { shapes.get(0).moveRight(map); shapeTrack.add(2); } if (keyText.equalsIgnoreCase("w")) { shapes.get(0).turn(map, shapeTrack); } } if (keyText.equalsIgnoreCase("left")) { character.moveLeft(); } if (keyText.equalsIgnoreCase("right")) { character.moveRight(); } if (keyText.equalsIgnoreCase("up")) { character.jump(); } if (keyText.equalsIgnoreCase("Slash")) { guntrack += 1; if (guntrack > weapons.length - 1) { guntrack = 0; } } } repaint(); }
@Test public void testThatAIPlacesShips() { GameBoard gb = new GameBoard(); int[] blank = {5, 4, 3, 2, 1}; AI ai = new AI(gb, blank); ai.placeShips(); Boolean result = false; for (int r = 0; r < gb.getHeight(); r++) { for (int c = 0; c < gb.getWidth(); c++) { result = result || !(gb.getTopGrid().getGrid()[r][c] instanceof ShipCell); } } Assert.assertTrue(result); }
// Gets the AI's next move giving the current state of the board private void getAIMove(GameBoard board) { // Send the board to the AI for it to determine and return the move in an array {x,y} int[] move = ai.move(board, aiMark); TextView cell = null; // Determine the right cell to use by id first go to the right row then the right column switch (move[0]) { case 0: switch (move[1]) { case 0: cell = (TextView) findViewById(R.id.cell11); break; case 1: cell = (TextView) findViewById(R.id.cell12); break; case 2: cell = (TextView) findViewById(R.id.cell13); break; } break; case 1: switch (move[1]) { case 0: cell = (TextView) findViewById(R.id.cell21); break; case 1: cell = (TextView) findViewById(R.id.cell22); break; case 2: cell = (TextView) findViewById(R.id.cell23); break; } break; case 2: switch (move[1]) { case 0: cell = (TextView) findViewById(R.id.cell31); break; case 1: cell = (TextView) findViewById(R.id.cell32); break; case 2: cell = (TextView) findViewById(R.id.cell33); break; } break; } // Make sure there's nothing already in the cell // then place the mark with the ai's Mark, increment move count // and check to see if the game's over if (cell != null && cell.getText() == "") { board.placeMark(move[0], move[1], aiMark); cell.setText(aiMark); moveCount++; isOver = checkEnd(aiMark); } }
public r2( jpanel1 panel, Color background, Color base, ArrayList<platform> platforms, ArrayList<unit> bags, unit maincharacter, room leftroom, room rightroom, room middleroom, world w) { super( panel, background, base, platforms, bags, maincharacter, leftroom, rightroom, middleroom, w); platform wall1 = new every.wall_left(base, weap3); this.addplatform(wall1); ladder1 = new ladderdown(900, 500, constants.sworddunfloor, this.weap3, this, "LIGHT_GRAY"); this.addplatform(ladder1); platform ceiling1 = new ceiling(Color.DARK_GRAY, weap3); this.addplatform(ceiling1); AI ai1 = new basicai(); ai1.settarget(mainchar); unit bag1 = new builders.heartblob(this, 800, 500 - 1, ai1); this.addbag(bag1); bag1.setdropdead("heart"); }
public void unPause() { pause = false; moveTime.start(); fallTime.start(); bulletMoveTime.start(); waterTime.start(); bulletTime.start(); grenadeTime.start(); laserTime.start(); shotgunTime.start(); if (shapeAI.getAI()) { aiMove.start(); } }
public void pause() { pause = true; moveTime.stop(); fallTime.stop(); bulletMoveTime.stop(); waterTime.stop(); bulletTime.stop(); grenadeTime.stop(); laserTime.stop(); shotgunTime.stop(); if (shapeAI.getAI()) { aiMove.stop(); } }
@Test public void testThatAIShoots() { GameBoard gb = new GameBoard(10, 10, 3); ArrayList<Ship> ships = new ArrayList<Ship>(); ships.add(new Ship(3, 3, 3, true)); ships.add(new Ship(4, 6, 2, true)); ships.add(new Ship(1, 1, 5, false)); gb.checkAndPlaceShips(ships, "Bottom"); int[] blank = {3, 2, 1}; AI ai = new AI(gb, blank); ai.placeShips(); Boolean result = false; ai.shoot(); for (int r = 0; r < gb.getHeight(); r++) { for (int c = 0; c < gb.getWidth(); c++) { result = result || (gb.getBottomGrid().getGrid()[r][c] instanceof Hit) || (gb.getBottomGrid().getGrid()[r][c] instanceof Miss); } } Assert.assertTrue(result); }
public Memory(LinkedList<Player> players) { super("Memory -"); this.players = players; makeBoard(); this.add(panel); this.setVisible(true); this.setSize(640, 720); this.setResizable(false); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Ger den första spelaren turen players.get(0).myTurn = true; playerlabels.get(0).setForeground(Color.GREEN); // Startar endast tråden för AI-hantering om det finns något AI med i spelet for (int i = 0; i < players.size(); i++) { if (players.get(i).getClass() == ai.getClass()) { AIh.start(); break; } } }
public static void main(String... args) { boolean done = false; Scanner scanner = new Scanner(System.in); Board board = new Board(); Board.BoardValue current = Board.BoardValue.ME; do { System.out.println("Current Board State (" + current.name() + "'s Turn):"); System.out.println(board.toString()); if (current == Board.BoardValue.ME) { System.out.print("Choose a column: "); int column = scanner.nextInt(); Board.setInColumn(board, column, Board.BoardValue.ME); current = Board.BoardValue.AI; } else { board = AI.getAIChoice(board); current = Board.BoardValue.ME; } } while (!done); scanner.close(); }
public int[] calculate(Type map[][], AI parent) { int[] a = new int[5]; for (int i = parent.goodFields.size() - 1; i > -1; i--) { Field f = parent.goodFields.get(i); Path path = new PathAStarRate(parent.y, parent.x, f.y, f.x, map, parent); int[] temp = path.getDirection(); for (int u = 0; u < temp.length; u++) { a[u] += (temp[u] / 100) * (parent.rateField( f.y, f.x)); // /(parent.totalGoodRate);/// parent.goodFields.size()); // System.out.println("a" + a[u]); } } // find highest int highest = Integer.MIN_VALUE; for (int i = 0; i < a.length; i++) { if (a[i] > highest) highest = a[i]; } // find divisor double divisor; divisor = (double) highest / 100.0f; // System.out.println("d" + divisor); // normalize double OMG; for (int i = 0; i < a.length; i++) { OMG = a[i] / divisor; // System.out.println(OMG); a[i] = (int) Math.round(OMG); } return a; }
private void setupGame() { for (int x = 0; x < playersAIs; x++) { new AI(this, players + x); } playerTurn = 0; stackPot = new CardStack(true, 30); // it is rare for there to be more than 30 cards in the pot stackBurn = new CardStack(false, 10); // it is rare for more than 10 cards to be burned in a // hand; even if someone has memorized their hand and they // are deliberately burning to get a facecard playerCards = new ArrayList<CardStack>(); for (int x = 0; x < players + playersAIs; x++) { playerCards.add(new CardStack(false, 20)); } ArrayList<Integer> unshuffledDecks = new ArrayList<Integer>(); ArrayList<Integer> shuffledDecks = new ArrayList<Integer>(); for (int x = 1; x <= 52 * Config.getNumDecks(); x++) { unshuffledDecks.add(Integer.valueOf(x)); } while (!unshuffledDecks.isEmpty()) { shuffledDecks.add(unshuffledDecks.remove((int) (Math.random() * unshuffledDecks.size()))); } int playerDealingTo = 0; while (!shuffledDecks.isEmpty()) { playerCards.get(playerDealingTo).addToTop(shuffledDecks.remove(0).intValue()); playerDealingTo = (playerDealingTo + 1) % (players + playersAIs); } log.fine("initial card stacks:"); for (int x = 0; x < playerCards.size(); x++) { log.fine(getPlayerName(x) + ": " + playerCards.get(x)); } Card.reloadTextures(); AI.registerEvent(AI.TYPENOTHING); }
public void burn(int player) { CardStack playerCardStack = playerCards.get(player); if (playerCardStack.size() == 0) { JOptionPane.showMessageDialog( gamePanel, "A player with zero cards has to burn. This part of the game has not yet been coded, so they're being let off with no penalty.", "ERROR", JOptionPane.ERROR_MESSAGE); log.warning("Player with zero cards has to burn"); return; } else { stackBurn.addToTop(playerCardStack.removeTopCard()); if (playerCardStack.size() == 0 && playerTurn == player) { turnIncrement(); // if it's player's turn and they just burned their last card, it is now // the // next player's turn. AI.registerEvent(AI.TYPENOTHING); // so that if the next player is an AI, they will know its // their turn. eliminatePlayer(player); } } GamePanel.playNoiseBurn(); gamePanel.addRenderable(new RenderableImageKinetic(this, RenderableImageKinetic.BURN, player)); }
protected void setAI(AI ai) { if (ai == null) return; this.ai = ai; ai.setGameObject(this); }
public void onUpdate(float pSecondsElapsed) { if (!MainActivity.gameStartingMessage.hasParent()) aibody.setTransform(ai.update(MainActivity.ballBody, slapper), o); }
/** * Calculates the machine movement * * @return */ private Movement machinePlays() { AI ai = new AI(gameLogic.getBoard()); Movement best = ai.getBestMove(GameLogic.PLAYER_TWO); return best; }
@Override public void moveAI(int aiID, javafx.geometry.Point2D point) { RaceTrackMessage answer = null; int sessionID = getSessionFromClient(aiID); // Move player and get collisionpoint if there was one if (lobbyMap.get(sessionID) != null && sessionID != NO_LOBBY_ID && getPlayerMap().get(aiID) != null) { if (lobbyMap.get(sessionID).isFirstRound()) { setRandomStartingPoint(aiID, sessionID); return; } List<Integer> playersInSameSession = null; if (getPlayerIdsInSameSession(aiID) != null) { playersInSameSession = getPlayerIdsInSameSession(aiID); } int playerWhoMoved = getGroupPositionByPlayerID(aiID); AI ai = (AI) getPlayerMap().get(aiID); if (ai.hasCrashed() || !ai.isParticipating()) { return; } Point2D collisionPointFromPlayer = lobbyMap.get(sessionID).makeAIMoveAt(ai, point); Point2D playerPosition = ai.getCurrentPosition(); startNextRoundByPlayerID(aiID); int nextPlayerToMove = getNextPlayerToMove(aiID); int playerWhoWon = getPlayerWhoWonByPlayerID(aiID); boolean didAPlayerWin = playerWhoWon != -1; int round = getPlayerRoundByPlayerID(aiID); Point2D playerVelocity = getCurrentPlayerVelocityByPlayerID(aiID); if (didAPlayerWin) { DebugOutputHandler.printDebug( (getPlayerMap().get(playerWhoWon).isAI() ? "AI " : "Player ") + playerWhoWon + " won the game."); answer = VectorMessageServerHandler.generatePlayerWonMessage( playerWhoMoved, playerWhoWon, playerPosition); closeGameByPlayerID(aiID); } else { answer = VectorMessageServerHandler.generateBroadcastMoveMessage( playerWhoMoved, playerPosition, null, nextPlayerToMove, playerVelocity, round); } for (int p : playersInSameSession) { answer.addClientID(p); } // method on lobby and game which just moves the player by his velocity again! not just by a // specific point } sendMessage(answer); }
public void actionPerformed(ActionEvent e) { // initial for icon and mark if (countMove % 2 == 0) { mark = "X"; markIcon = new ImageIcon(this.getClass().getResource("x.png")); } else { mark = "O"; markIcon = new ImageIcon(this.getClass().getResource("o.png")); } // handle for move(set mark and icon for player's move) if (isLastMove()) { // check if ai already win // check if button already fill } else if (((e.getSource() == button1) && (button1Desc != null)) || ((e.getSource() == button2) && (button2Desc != null)) || ((e.getSource() == button3) && (button3Desc != null)) || ((e.getSource() == button4) && (button4Desc != null)) || ((e.getSource() == button5) && (button5Desc != null)) || ((e.getSource() == button6) && (button6Desc != null)) || ((e.getSource() == button7) && (button7Desc != null)) || ((e.getSource() == button8) && (button8Desc != null)) || ((e.getSource() == button9) && (button9Desc != null))) { } else { // make move if (e.getSource() == button1) { button1Desc = mark; button1.setIcon(markIcon); } else if (e.getSource() == button2) { button2Desc = mark; button2.setIcon(markIcon); } else if (e.getSource() == button3) { button3Desc = mark; button3.setIcon(markIcon); } else if (e.getSource() == button4) { button4Desc = mark; button4.setIcon(markIcon); } else if (e.getSource() == button5) { button5Desc = mark; button5.setIcon(markIcon); } else if (e.getSource() == button6) { button6Desc = mark; button6.setIcon(markIcon); } else if (e.getSource() == button7) { button7Desc = mark; button7.setIcon(markIcon); } else if (e.getSource() == button8) { button8Desc = mark; button8.setIcon(markIcon); } else if (e.getSource() == button9) { button9Desc = mark; button9.setIcon(markIcon); } countMove += 1; // set navigate text if (theChoice == 1) { if (isLastMove()) { // check if player already win navigateText.setText(" You Win!!! "); navigateText.setFont(fontDone); } else if (countMove == 9) { navigateText.setText(" Draw!!! "); navigateText.setFont(fontDone); } else { // make ai move AI aiMove = new AI(); aiMove.move(); if (isLastMove()) { // check ai win navigateText.setText(" You Lose!!! "); navigateText.setFont(fontDone); } } } else { if (countMove % 2 == 0) { if (isLastMove()) { navigateText.setText(" O Win!!! "); navigateText.setFont(fontDone); } else { navigateText.setText(" X Turn "); } } else { if (isLastMove()) { navigateText.setText(" X Win!!! "); navigateText.setFont(fontDone); } else if (countMove == 9) { navigateText.setText(" Draw!!! "); navigateText.setFont(fontDone); } else { navigateText.setText(" O Turn "); } } } } }
// set's up AI public static void setup_AI() { ai.AI_setup(); }
// run's ai public static void run_AI() { ai.AI_guess(); }
// Actionevent - vad som händer om man klickar på ett kort public void actionPerformed(ActionEvent e) { for (int i = 0; i < cards.size(); i++) { if (e.getSource() == cards.get(i)) { // Lägger till de vända korten i minnet for (int k = 0; k < players.size(); k++) { // Lägger endast till kort om spelaren är ett AI if (players.get(k).getClass() == ai.getClass()) { // Kort ska inte läggas till minnet om det redan finns i minnet if (players.get(k).cardmemory.indexOf((Card) e.getSource()) == -1) { players.get(k).cardmemory.add((Card) e.getSource()); } // Om det finns fler kort i minnet än minnets storlek, ta bort det första while (players.get(k).cardmemory.size() > players.get(k).mem) { players.get(k).cardmemory.removeFirst(); } } } // Om det är det första kortet spelaren väljer, vänd kortet if (cardsturned == 0) { cards.get(i).setIcon(cards.get(i).back); cards.get(i).setBorder(new LineBorder(Color.RED, 3)); saveid = cards.get(i).id; savepos = i; cardsturned = 1; } // Om det är det andra kortet spelaren väljer, och det är likadant som det första else if (saveid == cards.get(i).id && savepos != i && cardsturned == 1) { cards.get(i).setIcon(cards.get(i).back); cards.get(i).setBorder(new LineBorder(Color.GREEN, 3)); cards.get(savepos).setBorder(new LineBorder(Color.GREEN, 3)); cardsturned = 3; cards.get(i).taken = true; cards.get(savepos).taken = true; // Startar timer för att vända tillbaka eller ta bort kort, samt uppdatera labels timer.start(); // Om en spelare har gissat rätt tar AIn bort korten från minnet, genom att ta bort alla // tagna kort ur minnet for (int k = 0; k < cards.size(); k++) { if (cards.get(k).taken == true) { for (int j = 0; j < players.size(); j++) { players.get(j).cardmemory.remove(cards.get(k)); } } } } // Om det är det andra kortet spelaren väljer, och det inte är likadant som det första else if (saveid != cards.get(i).id && savepos != i && cardsturned == 1) { cards.get(i).setBorder(new LineBorder(Color.RED, 3)); cards.get(i).setIcon(cards.get(i).back); cardsturned = 2; // Startar timer för att vända tillbaka eller ta bort kort, samt uppdatera labels timer.start(); } // Om spelaren väljer samma kort igen händer ingenting (Ursprungligen en utskrift i // konsollen här) // Jag har helt enkelt valt att spelet inte ens ska reagera om man väljer samma kort igen // (Signalerar dock att det inte går att välja) else if (savepos == i) { } } // När två kort är valda som inte är likadana startas en timer som bestämmer när korten ska // vändas tillbaka if (e.getSource() == timer) { timer.stop(); // Om spelaren gissat fel vänds korten tillbaka, labels uppdateras med indatan true if (cardsturned == 2) { updateLabels(false); } // Om spelaren gissat rätt tas korten bort, labels uppdateras med indatan true else if (cardsturned == 3) { updateLabels(true); } turnCards(); cardsturned = 0; } } }
public static void main(String[] args) { /* Instantiate a Scanner to read standard input */ Scanner stdIn = new Scanner(System.in); /* Assume we want to play forever */ boolean doYouWantToPlay = true; /* Loop until we don't want to play */ while (doYouWantToPlay) { /* Explain how to play the game */ System.out.println( "Welcome to Tic Tac Toe! You are about to go against " + "the master of Tic Tac Toe. Are you ready? I hope so!\n BUT FIRST, you" + " must pick what character you want to be and which character I will be"); System.out.println(); /* Enter your marker for the game */ System.out.println("Enter a single character that will represent you on the board (X/O)"); char playerToken = stdIn.next().charAt(0); /* Enter your opponents marker */ System.out.println( "Enter a single character that will represent your opponent on the board(X/O)"); char opponentToken = stdIn.next().charAt(0); /* Create a new game */ TicTacToe game = new TicTacToe(playerToken, opponentToken); /* Create a new AI character */ AI ai = new AI(); /* Print the index board */ System.out.println(); System.out.println( "Now we can start the game. To play, enter a number and your token shall be put " + "in its place.\nThe numbers go from 1-9, left to right. We shall see who will win this round."); TicTacToe.printIndexBoard(); System.out.println(); /* Let's play */ /* Loop until the game is over */ while (game.gameOver().equals("notOver")) { /* Is it the users turn? */ if (game.currentMarker == game.userMarker) { /* User turn */ System.out.println("It's your turn! Enter a spot for your token"); int spot = stdIn.nextInt(); /* While the spot is invalid */ while (!game.playTurn(spot)) { System.out.println( "Try again. " + spot + " is invalid. This spot is already taken" + " or it is out of range"); /* Get another spot */ spot = stdIn.nextInt(); } System.out.println("You picked " + spot + "!"); } else { System.out.println("It's my turn!"); /* AI takes a turn */ int aiSpot = ai.pickSpot(game); /* Play the spot */ game.playTurn(aiSpot); System.out.println("I picked " + aiSpot + "!"); } /* Print out the game board */ System.out.println("The game board now looks like"); game.printBoard(); } /* Print out the results of the game */ System.out.println(game.gameOver()); System.out.println(); /* Setup another game? */ System.out.println( "Do you want to play again? Enter Y if you do." + " Enter anything else if you are tired of me."); /* Read the user response */ char response = stdIn.next().charAt(0); /* Play again if the user responds Y */ doYouWantToPlay = (response == 'Y'); System.out.println(); System.out.println(); } }