1
+ /*
2
+ COMP20050 Group 12
3
+ Eoin Creavin – Student ID: 21390601
4
+ eoin.creavin@ucdconnect.ie
5
+ GitHub ID: eoin-cr
6
+
7
+ Mynah Bhattacharyya – Student ID: 21201085
8
+ malhar.bhattacharyya@ucdconnect.ie
9
+ GitHub ID: mynah-bird
10
+
11
+ Ben McDowell – Student ID: 21495144
12
+ ben.mcdowell@ucdconnect.ie
13
+ GitHub ID: Benmc1
14
+ */
15
+
1
16
package cascadia ;
2
17
3
18
import cascadia .scoring .ScoreToken ;
4
- import java .util .ArrayList ;
5
19
import java .util .Arrays ;
6
20
import java .util .List ;
7
21
import java .util .Random ;
@@ -14,15 +28,10 @@ public class TokenBot {
14
28
public static final int NUM_TOKEN_STRATS = 2 ;
15
29
// we don't need the token score map atm, but I'm keeping it in case we need it in the
16
30
// future
17
- private final List <ValueSortedMap <Integer , Integer >> deckScoreMap = new ArrayList <>();
18
31
private final int [] bestPlacementIds = new int [Constants .MAX_DECK_SIZE ];
19
32
private final int [] rankedTokens = new int [Constants .MAX_DECK_SIZE ];
20
33
21
34
public TokenBot () {
22
- for (int j = 0 ; j < Constants .NUM_TOKEN_TYPES ; j ++) {
23
- deckScoreMap .add (new ValueSortedMap <>());
24
- }
25
-
26
35
// initialise it to -1, so we know when we aren't able to place a token
27
36
Arrays .fill (bestPlacementIds , -1 );
28
37
}
@@ -45,7 +54,6 @@ public int[] chooseStrategy(Player player, Player nextPlayer) {
45
54
46
55
if (!BotTimer .isTimeLeft ()) {
47
56
System .out .println ("No time left!" );
48
- System .out .println (Arrays .toString (rankedTokens ));
49
57
return rankedTokens ;
50
58
}
51
59
@@ -77,7 +85,6 @@ private void destructiveTokenStrat(List<WildlifeToken> deckTokens, Player nextPl
77
85
private void rankDeckTokens (Player player , boolean isConst , List <WildlifeToken > deckTokens ) {
78
86
int [] scores = new int [Constants .MAX_DECK_SIZE ];
79
87
for (int i = 0 ; i < Constants .MAX_DECK_SIZE ; i ++) {
80
- deckScoreMap .get (i ).clear (); // clear the scores in the map before calculating
81
88
// checks whether it is possible to place a certain token on the map. If it
82
89
// is not, the score for that token is largely decreased
83
90
if (player .getMap ().numPossibleTokenPlacements (deckTokens .get (i )) == 0 ) {
@@ -94,7 +101,7 @@ private void rankDeckTokens(Player player, boolean isConst, List<WildlifeToken>
94
101
}
95
102
96
103
/*
97
- Tries place the token in all possible positions and returns the greatest increase
104
+ Tries to place the token in all possible positions and returns the greatest increase
98
105
in score
99
106
*/
100
107
private int calculatePlacementScoresAndReturnMax (WildlifeToken token , Player player ,
@@ -109,7 +116,6 @@ private int calculatePlacementScoresAndReturnMax(WildlifeToken token, Player pla
109
116
110
117
int prevScore = ScoreToken .calculateScore (player .getMap (), token );
111
118
112
- // oh boy the time complexity of this is. not good.
113
119
for (HabitatTile tile : possibleTiles ) {
114
120
Player tmp = new Player ("temp" );
115
121
tmp .getMap ().setTileBoard (PlayerMap .deepCopy (player .getMap ().getTileBoardPosition ()));
@@ -120,7 +126,6 @@ private int calculatePlacementScoresAndReturnMax(WildlifeToken token, Player pla
120
126
// we get an extra point for getting a nature token from placing on a keystone tile
121
127
scoreDiff ++;
122
128
}
123
- deckScoreMap .get (idx ).put (tile .getTileID (), scoreDiff );
124
129
125
130
// set it to scores that are equal to as well, as for example if the
126
131
// diff is 0 when we place a token, it's still better to place a token
@@ -148,24 +153,17 @@ private int calculatePlacementScoresAndReturnMax(WildlifeToken token, Player pla
148
153
// converts an arraylist of scores (e.g. [1,10,5,6]) to their relative
149
154
// ranking (e.g. [0,3,1,2])
150
155
private void convertToRank (int [] scores , List <WildlifeToken > deckTokens ) {
151
- System .out .println ("-----" );
152
- System .out .println (Arrays .toString (scores ));
153
156
154
157
List <Integer > sorted = Arrays .stream (scores ).sorted ().boxed ().toList ();
155
- System .out .println ("Sorted: " + sorted );
156
158
157
159
for (int i = 0 ; i < sorted .size (); i ++) {
158
160
scores [i ] = sorted .indexOf (scores [i ]);
159
161
}
160
- System .out .println (Arrays .toString (scores ));
161
162
162
163
// for (int i = 0; i < scores.length; i++) {
163
164
// rankedTokens[i] = 4 - scores[i];
164
165
// }
165
166
System .arraycopy (scores , 0 , rankedTokens , 0 , rankedTokens .length );
166
-
167
- System .out .println (Arrays .toString (rankedTokens ));
168
- System .out .println ("-----" );
169
167
}
170
168
171
169
/**
@@ -179,14 +177,14 @@ private void convertToRank(int[] scores, List<WildlifeToken> deckTokens) {
179
177
*/
180
178
public int getBestPlacement (WildlifeToken token , int deckIdx , Player player ) {
181
179
int id = bestPlacementIds [deckIdx ];
182
- System .out .println (Arrays .toString (bestPlacementIds ));
180
+ // System.out.println(Arrays.toString(bestPlacementIds));
183
181
184
182
// if we were doing the destructive method (finding the best token for the opponent
185
183
// and taking it) we want to find where we can place that token on our map
186
184
if (id == -2 ) {
187
185
calculatePlacementScoresAndReturnMax (token , player , true , deckIdx );
188
186
id = bestPlacementIds [deckIdx ];
189
- System .out .println (Arrays .toString (bestPlacementIds ));
187
+ // System.out.println(Arrays.toString(bestPlacementIds));
190
188
}
191
189
return id ;
192
190
}
0 commit comments