/ benchmark / hlt / Game.java
Game.java
 1  package hlt;
 2  
 3  import java.util.ArrayList;
 4  import java.util.Collection;
 5  
 6  public class Game {
 7      public int turnNumber;
 8      public final PlayerId myId;
 9      public final ArrayList<Player> players = new ArrayList<>();
10      public final Player me;
11      public final GameMap gameMap;
12  
13      public Game() {
14          Constants.populateConstants(Input.readLine());
15  
16          final Input input = Input.readInput();
17          final int numPlayers = input.getInt();
18          myId = new PlayerId(input.getInt());
19  
20          Log.open(myId.id);
21  
22          for (int i = 0; i < numPlayers; ++i) {
23              players.add(Player._generate());
24          }
25          me = players.get(myId.id);
26          gameMap = GameMap._generate();
27      }
28  
29      public void ready(final String name) {
30          System.out.println(name);
31      }
32  
33      public void updateFrame() {
34          turnNumber = Input.readInput().getInt();
35          Log.log("=============== TURN " + turnNumber + " ================");
36  
37          for (int i = 0; i < players.size(); ++i) {
38              final Input input = Input.readInput();
39  
40              final PlayerId currentPlayerId = new PlayerId(input.getInt());
41              final int numShips = input.getInt();
42              final int numDropoffs = input.getInt();
43              final int halite = input.getInt();
44  
45              players.get(currentPlayerId.id)._update(numShips, numDropoffs, halite);
46          }
47  
48          gameMap._update();
49          if (turnNumber % 5 == 0){
50              gameMap.updateTotalHalite();
51          }
52  
53          for (final Player player : players) {
54              for (final Ship ship : player.ships.values()) {
55                  gameMap.at(ship).markUnsafe(ship);
56              }
57  
58              gameMap.at(player.shipyard).structure = player.shipyard;
59  
60              for (final Dropoff dropoff : player.dropoffs.values()) {
61                  gameMap.at(dropoff).structure = dropoff;
62              }
63          }
64      }
65  
66      public void endTurn(final Collection<Command> commands) {
67          for (final Command command : commands) {
68              System.out.print(command.command);
69              System.out.print(' ');
70          }
71          System.out.println();
72      }
73  }