-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwood_3_league.dart
153 lines (124 loc) · 3.44 KB
/
wood_3_league.dart
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
import 'dart:io';
import 'dart:math';
//constants
const int typeNoStructure = -1;
const int typeBarracks = 2;
const int ownerFriendly = 0;
const int ownerEnemy = 1;
//game variables
int numSites; //number of buildings on the map
int gold; //amount of gold
int touchedSite; //id of the side Queen is touching or -1
List<SiteLocation> siteLocations;
List<Site> sites;
List<Unit> units = [];
void initializationInput() {
numSites = int.parse(stdin.readLineSync());
siteLocations =
new List.generate(numSites, (i) => new SiteLocation(i));
sites = new List.generate(numSites, (i) => new Site(i));
for (int i = 0; i < numSites; i++) {
List<String> inputs = stdin.readLineSync().split(' ');
int siteId = int.parse(inputs[0]); //always from 0 to numSites - 1 ?
siteLocations[siteId].x = int.parse(inputs[1]);
siteLocations[siteId].y = int.parse(inputs[2]);
siteLocations[siteId].radius = int.parse(inputs[3]);
}
}
void inputForOneGameTurn() {
List<String> inputs = stdin.readLineSync().split(' ');
gold = int.parse(inputs[0]);
touchedSite = int.parse(inputs[1]); // -1 if none
readSites();
readUnits();
}
void readSites() {
for (int i = 0; i < numSites; i++) {
List<String> inputs = stdin.readLineSync().split(' ');
int siteId = int.parse(inputs[0]);
sites[siteId].ignore1 = int.parse(inputs[1]); // used in future leagues
sites[siteId].ignore2 = int.parse(inputs[2]); // used in future leagues
sites[siteId].structureType =
int.parse(inputs[3]); // -1 = No structure, 2 = Barracks
sites[siteId].owner =
int.parse(inputs[4]); // -1 = No structure, 0 = Friendly, 1 = Enemy
sites[siteId].param1 = int.parse(inputs[5]);
sites[siteId].param2 = int.parse(inputs[6]);
}
}
void showSites() {
sites.forEach((site) {
SiteLocation siteLocation = siteLocations[site.siteId];
stderr.writeln("$site $siteLocation");
});
}
void readUnits() {
units.clear();
int numUnits = int.parse(stdin.readLineSync());
for (int i = 0; i < numUnits; i++) {
List<String> inputs = stdin.readLineSync().split(' ');
int x = int.parse(inputs[0]);
int y = int.parse(inputs[1]);
int owner = int.parse(inputs[2]);
int unitType = int.parse(inputs[3]); // -1 = QUEEN, 0 = KNIGHT, 1 = ARCHER
int health = int.parse(inputs[4]);
units.add(new Unit(x, y, owner, unitType, health));
}
}
void showUnits() {
stderr.writeln("units");
units.forEach((unit) {
stderr.writeln(unit);
});
}
void gameLoop() {
while (true) {
inputForOneGameTurn();
showSites();
showUnits();
print('WAIT');
print('TRAIN');
}
}
void main() {
initializationInput();
gameLoop();
}
//other classes
class Site {
int siteId;
int ignore1;
int ignore2;
int structureType;
int owner;
int param1;
int param2;
Site(this.siteId);
@override
String toString() {
return 'Site{siteId: $siteId, ignore1: $ignore1, ignore2: $ignore2, structureType: $structureType, owner: $owner, param1: $param1, param2: $param2}';
}
}
class SiteLocation {
int siteId;
int x;
int y;
int radius;
SiteLocation(this.siteId);
@override
String toString() {
return 'SiteLocation{x: $x, y: $y, radius: $radius}';
}
}
class Unit {
int x;
int y;
int owner;
int unitType;
int health;
Unit(this.x, this.y, this.owner, this.unitType, this.health);
@override
String toString() {
return 'Unit{x: $x, y: $y, owner: $owner, unitType: $unitType, health: $health}';
}
}