1313The jsonl format: one metadata line, per-turn v1 state frames ({game,turn,board,you}),
1414and a final result line ({winnerName,isDraw}).
1515"""
16+
1617import argparse
1718import json
1819import sys
@@ -48,19 +49,28 @@ def load(path):
4849 frames = []
4950 for t in turns :
5051 b = by_turn [t ]
51- frames .append ({
52- "turn" : t ,
53- "food" : [[c ["x" ], c ["y" ]] for c in b .get ("food" , [])],
54- "hazards" : [[c ["x" ], c ["y" ]] for c in b .get ("hazards" , [])],
55- "snakes" : [{
56- "name" : s ["name" ],
57- "health" : s .get ("health" , 0 ),
58- "body" : [[c ["x" ], c ["y" ]] for c in s ["body" ]],
59- } for s in b ["snakes" ]],
60- })
52+ frames .append (
53+ {
54+ "turn" : t ,
55+ "food" : [[c ["x" ], c ["y" ]] for c in b .get ("food" , [])],
56+ "hazards" : [[c ["x" ], c ["y" ]] for c in b .get ("hazards" , [])],
57+ "snakes" : [
58+ {
59+ "name" : s ["name" ],
60+ "health" : s .get ("health" , 0 ),
61+ "body" : [[c ["x" ], c ["y" ]] for c in s ["body" ]],
62+ }
63+ for s in b ["snakes" ]
64+ ],
65+ }
66+ )
6167 return {
62- "w" : b0 ["width" ], "h" : b0 ["height" ], "frames" : frames , "colors" : colors ,
63- "winner" : result .get ("winnerName" ), "draw" : result .get ("isDraw" , False ),
68+ "w" : b0 ["width" ],
69+ "h" : b0 ["height" ],
70+ "frames" : frames ,
71+ "colors" : colors ,
72+ "winner" : result .get ("winnerName" ),
73+ "draw" : result .get ("isDraw" , False ),
6474 }
6575
6676
@@ -69,7 +79,7 @@ def to_ascii(g):
6979 grid = [["." for _ in range (g ["w" ])] for _ in range (g ["h" ])]
7080 for fx , fy in f ["food" ]:
7181 grid [fy ][fx ] = "*"
72- for i , s in enumerate ( f ["snakes" ]) :
82+ for s in f ["snakes" ]:
7383 ch = s ["name" ][0 ].upper ()
7484 for j , (x , y ) in enumerate (s ["body" ]):
7585 grid [y ][x ] = ch if j else ch .lower () # head lowercase-ish marker
0 commit comments