-
Notifications
You must be signed in to change notification settings - Fork 6
/
SpringChallenge2021.java
166 lines (149 loc) · 6.03 KB
/
SpringChallenge2021.java
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
/**
* Auto-generated code below aims at helping you parse
* the standard input according to the problem statement.
**/
class Player {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int numberOfCells = in.nextInt(); // 37
List<Cells> cellList = new ArrayList<>();
for (int i = 0; i < numberOfCells; i++) {
int index = in.nextInt(); // 0 is the center cell, the next cells spiral outwards
int richness = in.nextInt(); // 0 if the cell is unusable, 1-3 for usable cells
int neigh0 = in.nextInt(); // the index of the neighbouring cell for each direction
int neigh1 = in.nextInt();
int neigh2 = in.nextInt();
int neigh3 = in.nextInt();
int neigh4 = in.nextInt();
int neigh5 = in.nextInt();
Cells cell = new Cells(index, richness, neigh0, neigh1, neigh2, neigh3, neigh4, neigh5);
System.err.println(cell);
cellList.add(cell);
}
// game loop
while (true) {
int day = in.nextInt(); // the game lasts 24 days: 0-23
int nutrients = in.nextInt(); // the base score you gain from the next COMPLETE action
int sun = in.nextInt(); // your sun points
int score = in.nextInt(); // your current score
int oppSun = in.nextInt(); // opponent's sun points
int oppScore = in.nextInt(); // opponent's score
boolean oppIsWaiting = in.nextInt() != 0; // whether your opponent is asleep until the next day
int numberOfTrees = in.nextInt(); // the current amount of trees
List<Tree> treeList = new ArrayList<>();
for (int i = 0; i < numberOfTrees; i++) {
int cellIndex = in.nextInt(); // location of this tree
int size = in.nextInt(); // size of this tree: 0-3
boolean isMine = in.nextInt() != 0; // 1 if this is your tree
boolean isDormant = in.nextInt() != 0; // 1 if this tree is dormant
Tree tree = new Tree(cellIndex, size, isMine, isDormant);
System.err.println(tree);
treeList.add(tree);
}
int numberOfPossibleActions = in.nextInt(); // all legal actions
if (in.hasNextLine()) {
in.nextLine();
}
List<String> actionPossibles = new ArrayList<>();
for (int i = 0; i < numberOfPossibleActions; i++) {
String possibleAction = in.nextLine(); // try printing something from here to start with
if (!"WAIT".equals(possibleAction)) {
actionPossibles.add(possibleAction);
System.err.println(possibleAction);
}
}
List<Tree> trees = treeList.stream().filter(tree -> tree.isMine).collect(Collectors.toList());
int max = 0;
String message = "WAIT";
List<Tree> trees3 = trees.stream().filter(tree -> tree.size == 3).collect(Collectors.toList());
if (trees3.isEmpty()) {
for (Tree tree : trees) {
int temp = tree.size;
if (temp > max) {
max = temp;
message = "GROW " + tree.cellIndex;
}
}
} else {
for (Tree tree : trees3) {
int temp = cellList.stream().filter(cell -> cell.index == tree.cellIndex).findFirst().get().getRichness();
if (temp > max) {
max = temp;
message = "COMPLETE " + tree.cellIndex;
}
}
}
if (!actionPossibles.isEmpty() && !actionPossibles.contains(message)){
message = actionPossibles.get(0);
}
// Write an action using System.out.println()
// To debug: System.err.println("Debug messages...");
// GROW cellIdx | SEED sourceIdx targetIdx | COMPLETE cellIdx | WAIT <message>
System.out.println(message);
}
}
}
class Tree {
int cellIndex; // location of this tree
int size; // size of this tree: 0-3
boolean isMine; // 1 if this is your tree
boolean isDormant;
public Tree(int cellIndex, int size, boolean isMine, boolean isDormant) {
this.cellIndex = cellIndex;
this.size = size;
this.isMine = isMine;
this.isDormant = isDormant;
}
@Override
public String toString() {
return "Tree{" +
"cellIndex=" + cellIndex +
", size=" + size +
", isMine=" + isMine +
", isDormant=" + isDormant +
'}';
}
}
class Cells {
int index; // 0 is the center cell, the next cells spiral outwards
int richness; // 0 if the cell is unusable, 1-3 for usable cells
int neigh0; // the index of the neighbouring cell for each direction
int neigh1;
int neigh2;
int neigh3;
int neigh4;
int neigh5;
public Cells(int index, int richness, int neigh0, int neigh1, int neigh2, int neigh3, int neigh4, int neigh5) {
this.index = index;
this.richness = richness;
this.neigh0 = neigh0;
this.neigh1 = neigh1;
this.neigh2 = neigh2;
this.neigh3 = neigh3;
this.neigh4 = neigh4;
this.neigh5 = neigh5;
}
@Override
public String toString() {
return "Cell{" +
"index=" + index +
", richness=" + richness +
", neigh0=" + neigh0 +
", neigh1=" + neigh1 +
", neigh2=" + neigh2 +
", neigh3=" + neigh3 +
", neigh4=" + neigh4 +
", neigh5=" + neigh5 +
'}';
}
public int getIndex() {
return index;
}
public int getRichness() {
return richness;
}
}