Note: Tokens 101-103 (values 2-4) exist in vocab but are NOT used by the grammar. The model only generates NUM tokens >= 104 (5+ repeats) for efficiency.
Special Tokens
Token ID
Name
Function
110
LOOP
Start a loop structure
112
END
End of program
Token 111 (IF) was removed due to simulator incompatibility.
Grammar Rules
Programs follow a strict context-free grammar:
start -> DIR | LOOP NUM DIR | END
after_DIR -> DIR | LOOP NUM DIR | END
after_LOOP -> NUM (must be 104-109)
after_NUM -> DIR (must be 0-3)
after_END -> (stop generation)
Valid Program Examples
[0, 112] # Move UP, END
[2, 2, 2, 112] # Move LEFT 3 times, END
[110, 106, 1, 112] # LOOP(7 times, DOWN), END
[0, 110, 104, 2, 3, 112] # UP, LOOP(5 times, LEFT), RIGHT, END
[110, 108, 0, 110, 105, 3, 112] # LOOP(9, UP), LOOP(6, RIGHT), END
Grammar Constraint: LOOP cutoff at position 8
LOOP token (110) is only allowed at positions 0-7 (indices 0-7 in the generated sequence). From position 8 onwards, only DIR tokens and END are allowed. This prevents overly long programs.
State Vector (828 dimensions)
The 828-dimensional state vector encodes the complete game state:
python
1defget_state_vector(sim):2"""Extract 828-dim state vector from game simulator"""3 state_dict = sim.get_state_dict()4 state =[]5 DYNAMIC_SCALE =10.0# Scale factor for dynamic features67# --- Grid features (11x11 grids) ---89# 1. Wall grid (121 dims): 1=wall, 0=empty10for row in state_dict['wall']:11 state.extend(row)1213# 2. Small Cheese grid (121 dims): 1=cheese present, 0=collected14# Scaled by DYNAMIC_SCALE (10.0)15for row in state_dict['sc']:16 state.extend([v * DYNAMIC_SCALE for v in row])1718# 3. Junction grid (121 dims): 1=junction, 0=not19for row in state_dict['junc']:20 state.extend(row)2122# 4. Dead-end grid (121 dims): 1=dead-end, 0=not23for row in state_dict['deadend']:24 state.extend(row)2526# Total grid: 484 dims (4 * 121)2728# --- Entity positions ---2930# 5. Mouse position (2 dims): [x, y]31 mouse = state_dict['mouse']32 state.extend([float(mouse[0]),float(mouse[1])])3334# 6. Cat positions (12 dims): 6 cats * [x, y], unused=-135 cat_list = state_dict.get('cat',[])36for i inrange(6):37if i <len(cat_list):38 state.extend([float(cat_list[i][0]),float(cat_list[i][1])])39else:40 state.extend([-1.0,-1.0])4142# 7. Moving Big Cheese positions (10 dims): 5 * [x, y], unused=-143 bc_list = state_dict.get('crzbc',[])44for i inrange(5):45if i <len(bc_list):46 state.extend([float(bc_list[i][0]),float(bc_list[i][1])])47else:48 state.extend([-1.0,-1.0])4950# Pad to 549 dims (484 + 65)51whilelen(state)<484+65:52 state.append(0.0)5354# --- Scalar features (6 dims) ---5556# 8. Score (normalized by 1000, scaled)57 state.append(state_dict.get('score',0)/1000.0* DYNAMIC_SCALE)5859# 9. Life (normalized by 3, scaled) - starts at 360 state.append(state_dict.get('life',3)* DYNAMIC_SCALE /3.0)6162# 10. Current run number (normalized by 20, scaled)63 state.append(state_dict.get('run',0)* DYNAMIC_SCALE /20.0)6465# 11. Win flag (DYNAMIC_SCALE if won, 0 otherwise)66 state.append(DYNAMIC_SCALE if state_dict.get('win_sign',False)else0.0)6768# 12. Lose flag (DYNAMIC_SCALE if lost, 0 otherwise)69 state.append(DYNAMIC_SCALE if state_dict.get('lose_sign',False)else0.0)7071# 13. Step progress (current_step / step_limit, scaled)72 step = state_dict.get('step',0)73 step_limit = state_dict.get('step_limit',200)74 state.append(step / step_limit * DYNAMIC_SCALE if step_limit >0else0.0)7576# Pad to 828 dims77whilelen(state)<828:78 state.append(0.0)7980return torch.tensor(state[:828], dtype=torch.float32)
State Vector Layout Summary
Range
Dims
Content
Scale
0-120
121
Wall grid (11x11)
1.0
121-241
121
Small Cheese grid
10.0
242-362
121
Junction grid
1.0
363-483
121
Dead-end grid
1.0
484-485
2
Mouse position [x,y]
1.0
486-497
12
Cat positions (6 cats)
1.0
498-507
10
Big Cheese positions (5)
1.0
508-548
41
Padding (zeros)
-
549
1
Score / 1000 * 10
10.0
550
1
Life / 3 * 10
10.0
551
1
Run / 20 * 10
10.0
552
1
Win flag
10.0
553
1
Lose flag
10.0
554
1
Step progress
10.0
555-827
273
Padding (zeros)
-
Game Rules (Level 3)
Map
11x11 grid maze with walls
Fixed wall layout for level 3
Entities
Mouse: Player-controlled, starts at position [10, 10]
Cat 0 (Dummy): Starts at [2, 2], moves only during command execution (len(command) steps)
Cat 1 (Naughty): Starts at [5, 5], moves every mouse step
Small Cheese (SC): 75 stationary items, +10 points each
Moving Big Cheese (crzbc): 2 items, +500 points each, move each step
Cat Movement (Random Mode)
Cats move randomly at junctions (no turning back), continue straight in corridors, pick random direction when blocked. This is the _get_cats_direct_actions mode in the simulator.
Scoring
Event
Points
Collect Small Cheese
+10
Collect Big Cheese
+500
Hit Wall
-10
Caught by Cat
-500 (+ lose 1 life)
Win Bonus
+(run * 10 + step)
Win/Lose Conditions
WIN: Collect ALL 75 Small Cheese + END token executed
LOSE (life): Life reaches 0 (caught 3 times)
LOSE (step): Step count reaches 200
LOSE (run): 20 runs exhausted without winning
Game Flow
Game starts with mouse at [10,10], 3 lives, 20 max runs
Each run: model generates a program -> program executes step by step