private static void printSchedule() throws IOException { FileWriter fileWriter = new FileWriter("/Users/petersavitsky/fantasySchedule.csv"); fileWriter.append("Owner"); for (int i = 0; i < NUMBER_OF_WEEKS; i++) { fileWriter.append(COMMA_DELIMITER); fileWriter.append("Week " + (i + 1)); } fileWriter.append("\n"); for (Entry<Team, Map<Integer, Matchup>> entry : schedule.getMatchupsByTeam().entrySet()) { fileWriter.append(entry.getKey().getTeamName()).append(COMMA_DELIMITER); for (int i = 1; i <= entry.getValue().size(); i++) { Matchup matchup = entry.getValue().get(i); if (matchup != null) { Team opponent = matchup.getOpponent(entry.getKey()); if (opponent != null) { fileWriter.append(opponent.getTeamName()); } else { fileWriter.append("no_opponent"); } } else { fileWriter.append("no_matchup"); } fileWriter.append(COMMA_DELIMITER); } fileWriter.append("\n"); } fileWriter.flush(); fileWriter.close(); }
public Match(Matchup matchup, Board board, IOutput output, ITimer timer) { this.matchup = matchup; this.board = board; this.output = output; this.timer = timer; dark = matchup.getFirst(); light = matchup.getSecond(); curPlayer = dark; }
/** * Allows the input player to play a single ply of Othello. (Make a single move on the board). If * the player has no available moves, this will switch to the other player w/o requesting a move. * If the game is over, this will switch to the GAMEOVER state. */ private void playPly() { if (stateManager.isStateChange()) { MoveList validMoves = GameLogic.getValidMoves(board, curPlayer.getState()); if (validMoves.size() > 0) { // Make your move. aiThread = new AIThread(curPlayer, board.clone(), validMoves.toPoints()); timer.reset(); aiThread.start(); return; } else { nextPlayer(); validMoves = GameLogic.getValidMoves(board, curPlayer.getState()); if (validMoves.size() > 0) { // Other player goes again. output.playerGetsToMoveAgain(curPlayer); aiThread = new AIThread(curPlayer, board.clone(), validMoves.toPoints()); timer.reset(); aiThread.start(); return; } else { // GameOver gameOver(); return; } } } if (aiThread.isReady()) { Move move = aiThread.getMove(); if (move != null) { FlipList flipList = GameLogic.getPointsFlipped(board, move); GameLogic.makeDestructiveMove(board, flipList); output.playerMadeMove(curPlayer, move, flipList, board); nextPlayer(); stateManager.setCurState(GameState.PLAYING); } else { // Forfeit turn due to invalid move. gameOver(matchup.otherPlayer(curPlayer)); return; } } else if (timer.expired()) { output.playerRanOutOfTime(curPlayer); gameOver(matchup.otherPlayer(curPlayer)); return; } }
private void nextPlayer() { // NOTE: Do NOT set GameState.PLAYING here. curPlayer = matchup.otherPlayer(curPlayer); }
private void gameOver(Player winner) { matchup.playedMatch(winner); stateManager.setCurState(GameState.GAME_OVER); }