22
33import ru .croccode .hypernull .domain .MatchMap ;
44import ru .croccode .hypernull .geometry .Point ;
5+ import ru .croccode .hypernull .geometry .Size ;
56import ru .croccode .hypernull .match .MatchConfig ;
67import 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