-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpowergridtest.java
More file actions
93 lines (76 loc) · 2.88 KB
/
powergridtest.java
File metadata and controls
93 lines (76 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package games.powergrid;
import static core.CoreConstants.VisibilityMode.HIDDEN_TO_ALL;
import static core.CoreConstants.VisibilityMode.VISIBLE_TO_ALL;
import core.components.Component;
import core.components.Deck;
import games.powergrid.components.PowerGridCard;
import games.powergrid.components.PowerGridGraphBoard;
import java.util.List;
import java.util.ArrayList;
import java.util.Random;
public class powergridtest {
public static void main(String[] args) {
int nPlayers = 3;
Random rnd = new Random();
int x = rnd.nextInt(10);
//Random rnd = gameState.getRandomGenerator();
//int nPlayers = gameState.getNPlayers();
Deck<PowerGridCard> finalDeck = setupDecks(nPlayers, rnd);
// Print it out to check
System.out.println("YAAW (top to bottom):");
int idx = 0;
for (Component c : finalDeck.getComponents()) {
System.out.println((idx++) + ": " + c);
}
}
public static Deck<PowerGridCard> setupDecks(int nPlayers, Random rnd) {
Deck<PowerGridCard> drawPile = new Deck<>("Draw", HIDDEN_TO_ALL);
Deck<PowerGridCard> tempPile = new Deck<>("Temp", HIDDEN_TO_ALL);
// Add all cards
PowerGridParameters params = new PowerGridParameters();
for (PowerGridCard card : params.plantsIncludedInGame) {
drawPile.add(card);
}
drawPile.add(PowerGridCard.step3());
// Separate step 3 + low-number plants
PowerGridCard step3Card = null;
List<PowerGridCard> snap = new ArrayList<>(drawPile.getComponents());
for (PowerGridCard c : snap) {
if (c.type == PowerGridCard.Type.STEP3) {
step3Card = c;
drawPile.remove(c);
} else if (c.type == PowerGridCard.Type.PLANT && c.getNumber() <= 15) {
drawPile.remove(c);
tempPile.addToBottom(c);
}
}
// Shuffle piles
tempPile.shuffle(rnd);
drawPile.shuffle(rnd);
// Remove cards based on player count
if (nPlayers == 2) {
tempPile.draw();
for (int k = 0; k < 5; k++) drawPile.draw();
} else if (nPlayers == 3) {
tempPile.draw();
tempPile.draw();
for (int k = 0; k < 6; k++) drawPile.draw();
} else if (nPlayers == 4) {
tempPile.draw();
for (int k = 0; k < 3; k++) drawPile.draw();
}
// Recombine: tempPile on top of drawPile
List<PowerGridCard> buf = new ArrayList<>();
while (tempPile.getSize() > 0) {
buf.add(tempPile.draw());
}
for (int i = buf.size() - 1; i >= 0; i--) {
drawPile.add(buf.get(i));
}
// Add step 3 card to bottom
if (step3Card != null) {
drawPile.addToBottom(step3Card);
}
return drawPile;
}
}