-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExampleBot.java
201 lines (173 loc) · 5.11 KB
/
ExampleBot.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import cern.ais.gridwars.UniverseView;
import cern.ais.gridwars.Coordinates;
import cern.ais.gridwars.bot.PlayerBot;
import cern.ais.gridwars.command.MovementCommand;
import java.util.List;
import java.util.Random;
public class ExampleBot implements PlayerBot
{
private Coordinates oi;
private double d;
private double dist(UniverseView universeview){
int enemy_x=0, enemy_y=0, friend_x=0, friend_y=0;
int size= universeview.getUniverseSize();
for(int i=0;i<size;i++){
for(int j=0;j<size;j++){
if(!(universeview.isEmpty(i, j)) && !(universeview.belongsToMe(i, j))){
enemy_x = i;
enemy_y=j;
}else if((universeview.isEmpty(i, j)) && (universeview.belongsToMe(i, j))){
friend_x=i;
friend_y=j;
}
}
}
double dist_x=friend_x-enemy_x;
dist_x=Math.pow(dist_x, 2);
double dist_y=friend_y-enemy_y;
dist_y=Math.pow(dist_y, 2);
double d=Math.sqrt(dist_x+dist_y);
return d;
}
/*private Coordinates myStartCoordinates(UniverseView universeview){
int size= universeview.getUniverseSize();
Coordinates oi=universeview.getCoordinates(0, 0);;
for(int i=0;i<size;i++){
for(int j=0;j<size;j++){
if((universeview.isEmpty(i, j)) && (universeview.belongsToMe(i, j))){
oi = universeview.getCoordinates(i, j);
}
}
}
return oi;
}*/
public static final long BATSIZE = 5;
public void getNextCommands(UniverseView universeView, List<MovementCommand> list){
//
// Coordinates start=myStartCoordinates(universeView);
int turn=universeView.getCurrentTurn();
if(turn==1){
for (Coordinates c : universeView.getMyCells()) {
long pop=universeView.getPopulation(c);
pop-=5;
long up=pop/4;
long down=pop/4;
long right=pop/4;
long left=pop-up-down-right;
list.add(new MovementCommand(c, MovementCommand.Direction.UP, up));
list.add(new MovementCommand(c, MovementCommand.Direction.DOWN, down));
list.add(new MovementCommand(c, MovementCommand.Direction.LEFT, left));
list.add(new MovementCommand(c, MovementCommand.Direction.RIGHT, right));
oi=c;
d=dist(universeView);
}
}
else if(turn>1 && turn<70){
for (Coordinates c : universeView.getMyCells()) {
int x=0,y=0, start_x=0,start_y=0;
long pop=universeView.getPopulation(c);
x=c.getX();
y=c.getY();
start_x=oi.getX();
start_y=oi.getY();
if(pop>5){
//right
if(x>start_x){
list.add(new MovementCommand(c, MovementCommand.Direction.RIGHT, pop-5));
}
//left
else if(x<start_x){
list.add(new MovementCommand(c, MovementCommand.Direction.LEFT, pop-5));
}
//up
else if(y>=start_y){
list.add(new MovementCommand(c, MovementCommand.Direction.UP, pop-5));
}
//down
else if(y<start_y){
list.add(new MovementCommand(c, MovementCommand.Direction.DOWN, pop-5));
}
}
}
}else{
long troops=0;
//long batallion;
long tier;
int order;
Random rng = new Random();
for (Coordinates c : universeView.getMyCells()) {
troops-=BATSIZE;
tier = troops/BATSIZE;
order = rng.nextInt(4);
while(tier>0){
switch(order){
case 1:
list.add(new MovementCommand(c,MovementCommand.Direction.RIGHT, BATSIZE));
tier--;
if(tier>0){
list.add(new MovementCommand(c,MovementCommand.Direction.UP, BATSIZE));
tier--;
}
if(tier>0){
list.add(new MovementCommand(c,MovementCommand.Direction.LEFT, BATSIZE));
tier--;
}
if(tier>0){
list.add(new MovementCommand(c,MovementCommand.Direction.DOWN, BATSIZE));
tier--;
}
break;
case 2:
list.add(new MovementCommand(c,MovementCommand.Direction.DOWN, BATSIZE));
tier--;
if(tier>0){
list.add(new MovementCommand(c,MovementCommand.Direction.RIGHT, BATSIZE));
tier--;
}
if(tier>0){
list.add(new MovementCommand(c,MovementCommand.Direction.UP, BATSIZE));
tier--;
}
if(tier>0){
list.add(new MovementCommand(c,MovementCommand.Direction.LEFT, BATSIZE));
tier--;
}
break;
case 3:
list.add(new MovementCommand(c,MovementCommand.Direction.LEFT, BATSIZE));
tier--;
if(tier>0){
list.add(new MovementCommand(c,MovementCommand.Direction.DOWN, BATSIZE));
tier--;
}
if(tier>0){
list.add(new MovementCommand(c,MovementCommand.Direction.RIGHT, BATSIZE));
tier--;
}
if(tier>0){
list.add(new MovementCommand(c,MovementCommand.Direction.UP, BATSIZE));
tier--;
}
break;
default:
list.add(new MovementCommand(c,MovementCommand.Direction.UP, BATSIZE));
tier--;
if(tier>0){
list.add(new MovementCommand(c,MovementCommand.Direction.LEFT, BATSIZE));
tier--;
}
if(tier>0){
list.add(new MovementCommand(c,MovementCommand.Direction.DOWN, BATSIZE));
tier--;
}
if(tier>0){
list.add(new MovementCommand(c,MovementCommand.Direction.RIGHT, BATSIZE));
tier--;
}
break;
}
}
}
}
}
}