Skip to content

Commit 868cbf4

Browse files
author
denrus
committed
Синхронизировал readme.md и код
1 parent 637dc53 commit 868cbf4

File tree

4 files changed

+60
-19
lines changed

4 files changed

+60
-19
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,18 +257,24 @@ TODO
257257

258258
```
259259
match
260+
num_bots {NUM_BOTS}
261+
##MatchConfig
260262
mode {MATCH_MODE}
261263
num_rounds {NUM_ROUNDS}
262-
num_bots {NUM_BOTS}
264+
random_seed {RANDOM_SEED}
265+
move_time_limit {MOVE_TIME_LIMIT}
266+
coin_spawn_period {COIN_SPAWN_PERIOD}
267+
coin_spawn_volume {COIN_SPAWN_VOLUME}
268+
##MapConfig
263269
map_size {MAP_WIDTH} {MAP_HEIGHT}
264270
view_radius {VIEW_RADIUS}
265271
mining_radius {MINING_RADIUS}
266272
attack_radius {ATTACK_RADIUS}
267-
move_time_limit {MOVE_TIME_LIMIT}
273+
block {X} {Y}
274+
##BotsAndCoinsInfo
268275
bot_name {BOT_ID} {BOT_NAME}
269276
bot {BOT_ID} {X} {Y}
270277
bot_coins {BOT_ID} {NUM_COINS}
271-
block {X} {Y}
272278
coin {X} {Y}
273279
round {ROUND}
274280
bot {BOT_ID} {X} {Y}

common/src/main/java/ru/croccode/hypernull/geometry/Point.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,8 @@ public int hashCode() {
113113
public String toString() {
114114
return "(" + x + ", " + y + ")";
115115
}
116+
117+
public String toLog() {
118+
return x + " " + y;
119+
}
116120
}

server/src/main/java/ru/croccode/hypernull/match/MatchConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
public class MatchConfig {
77

8-
private final long randomSeed;
8+
private final MatchMode mode;
99

1010
private final int numRounds;
1111

12-
private final MatchMode mode;
12+
private final long randomSeed;
1313

1414
private final long moveTimeLimit;
1515

server/src/main/java/ru/croccode/hypernull/server/MatchFileLogger.java

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import ru.croccode.hypernull.domain.MatchMap;
44
import ru.croccode.hypernull.geometry.Point;
5+
import ru.croccode.hypernull.geometry.Size;
56
import ru.croccode.hypernull.match.MatchConfig;
67
import ru.croccode.hypernull.match.MatchListener;
78

@@ -39,35 +40,46 @@ public MatchFileLogger(String logsFolder) {
3940
@Override
4041
public void matchStarted(MatchMap map, MatchConfig config, Map<K, String> botNames) {
4142
write("match");
42-
for (Field declaredField : config.getClass().getDeclaredFields()) {
43-
try {
44-
declaredField.setAccessible(true);
45-
write(declaredField.getName() + " " + declaredField.get(config));
46-
} catch (IllegalAccessException e) {
47-
throw new RuntimeException(
48-
"Ошибка получения значения поля через рефлексию: " + e.getMessage(),
49-
e
50-
);
51-
}
52-
}
43+
write("num_bots " + botNames.size());
44+
write("##MatchConfig");
45+
printAllFields(config);
46+
write("##MapConfig");
47+
final Size mapSize = map.getSize();
48+
write("map_size " + mapSize.width() + " " + mapSize.height());
49+
write("view_radius " + map.getViewRadius());
50+
write("mining_radius " + map.getMiningRadius());
51+
write("attack_radius " + map.getAttackRadius());
52+
printAllBlocks(map);
53+
write("##BotsAndCoinsInfo");
5354
for (Map.Entry<K, String> botEntry : botNames.entrySet()) {
5455
write("bot_name " + botEntry.getKey() + " " + botEntry.getValue());
5556
}
5657
}
5758

59+
private void printAllBlocks(MatchMap map) {
60+
for (int row = 0; row < map.getHeight(); row++) {
61+
for (int column = 0; column < map.getWidth(); column++) {
62+
Point somePoint = new Point(column, row);
63+
if (map.isBlocked(somePoint)) {
64+
write("block " + somePoint.toLog());
65+
}
66+
}
67+
}
68+
}
69+
5870
@Override
5971
public void matchRound(int round) {
6072
write("round " + round);
6173
}
6274

6375
@Override
6476
public void coinSpawned(Point position) {
65-
write("coin " + position.toString());
77+
write("coin " + position.toLog());
6678
}
6779

6880
@Override
6981
public void coinCollected(Point position, K botKey) {
70-
write("coin_collected " + position.toString() + " " + botKey);
82+
write("coin_collected " + position.toLog() + " " + botKey);
7183
}
7284

7385
@Override
@@ -77,7 +89,7 @@ public void botSpawned(K botKey, Point position) {
7789

7890
@Override
7991
public void botMoved(K botKey, Point position) {
80-
write("bot " + botKey + " " + position.toString());
92+
write("bot " + botKey + " " + position.toLog());
8193
}
8294

8395
@Override
@@ -103,4 +115,23 @@ private void write(String msg) {
103115
public void close() {
104116
logWriter.close();
105117
}
118+
119+
private void printAllFields(Object someObj) {
120+
final Class<?> objClass = someObj.getClass();
121+
for (Field declaredField : objClass.getDeclaredFields()) {
122+
try {
123+
declaredField.setAccessible(true);
124+
final String filedName = declaredField.getName()
125+
.replaceAll("([A-Z][a-z])", "_$1")
126+
.toLowerCase();
127+
write(filedName + " " + declaredField.get(someObj));
128+
} catch (IllegalAccessException e) {
129+
throw new RuntimeException(
130+
"Ошибка получения значения поля для класса " + objClass.getSimpleName()
131+
+ " через рефлексию: " + e.getMessage(),
132+
e
133+
);
134+
}
135+
}
136+
}
106137
}

0 commit comments

Comments
 (0)