1010import bwapi .types .UpgradeType ;
1111import bwapi .values .*;
1212
13- import java .util .ArrayList ;
14- import java .util .List ;
13+ import java .util .*;
1514
1615public class Game {
1716 final GameData gameData ;
17+ final Map <Integer , Unit > units = new HashMap <>();
18+ final Map <Integer , Player > players = new HashMap <>();
19+ final Map <Integer , Force > forces = new HashMap <>();
20+ final Map <Integer , Bullet > bullets = new HashMap <>();
1821
1922 public Game (GameData gameData ) {
2023 this .gameData = gameData ;
24+ init ();
2125 }
2226
27+ private void init () {
28+ for (int id =0 ; id < gameData .getForceCount (); id ++) {
29+ forces .put (id , new Force (gameData .getForce (id ), this ));
30+ }
31+ for (int id =0 ; id < gameData .getPlayerCount (); id ++) {
32+ players .put (id , new Player (gameData .getPlayer (id ), this ));
33+ }
34+ }
2335
24-
25- public List <Force > getForces () {
26- List <Force > forces = new ArrayList <>();
27- for (int i =0 ; i < gameData .getForceCount (); i ++)
28- forces .add (new Force (gameData .getForce (i )));
29- return forces ;
36+ public Collection <Force > getForces () {
37+ return forces .values ();
3038 }
3139
32- public List <Player > getPlayers () {
33- List <Player > players = new ArrayList <>();
34- for (int i =0 ; i < gameData .getPlayerCount (); i ++)
35- players .add (new Player (gameData .getPlayer (i )));
36- return players ;
40+ public Collection <Player > getPlayers () {
41+ return players .values ();
3742 }
3843
39- /**
40- public List<Unit> getAllUnits();
4144
45+ public Collection <Unit > getAllUnits () {
46+ return units .values ();
47+ }
48+
49+ /*
4250 public List<Unit> getMinerals();
4351
4452 public List<Unit> getGeysers();
@@ -54,12 +62,20 @@ public List<Player> getPlayers() {
5462 public List<Bullet> getBullets();
5563
5664 public List<Position> getNukeDots();
65+ */
5766
58- public Force getForce(int forceID);
67+ public Force getForce (int forceID ) {
68+ return forces .get (forceID );
69+ }
5970
60- public Player getPlayer(int playerID);
71+ public Player getPlayer (int playerID ) {
72+ return players .get (playerID );
73+ }
6174
62- public Unit getUnit(int unitID);
75+ public Unit getUnit (int unitID ) {
76+ return units .get (unitID );
77+ }
78+ /*
6379
6480 public Unit indexToUnit(int unitIndex);
6581
@@ -229,16 +245,16 @@ public List<Player> getPlayers() {
229245 */
230246
231247 public Player self () {
232- return new Player ( gameData . getPlayer (gameData .self () ));
248+ return players . get (gameData .self ());
233249 }
234250
235251
236252 public Player enemy () {
237- return new Player ( gameData . getPlayer (gameData .enemy () ));
253+ return players . get (gameData .enemy ());
238254 }
239255
240256 public Player neutral () {
241- return new Player ( gameData . getPlayer (gameData .neutral () ));
257+ return players . get (gameData .neutral ());
242258 }
243259
244260 /*
0 commit comments