; rest_split — eat adjacent enemies, split into free squares once fat, else rest. ; Memory: byte 0 = preferred split direction (rotates each split). lea r8, [rdi + VIEW_CELLS] ; 1. attack an adjacent enemy (neighbour indices: up 7, right 13, down 17, left 11) cmp byte [r8 + 7], CELL_ENEMY je .atk_up cmp byte [r8 + 13], CELL_ENEMY je .atk_right cmp byte [r8 + 17], CELL_ENEMY je .atk_down cmp byte [r8 + 11], CELL_ENEMY je .atk_left ; 2. split when we have a comfortable margin above SPLIT_MIN cmp rsi, SPLIT_MIN + 8 jb .rest movzx ecx, byte [rdx] ; preferred direction 0..3 mov r9d, 4 ; try all four directions .try: and ecx, 3 mov r10d, ecx lea r11, [neighbour_idx] movzx r10d, byte [r11 + r10] ; neighbour index for direction ecx cmp byte [r8 + r10], CELL_EMPTY je .split inc ecx dec r9d jnz .try .rest: mov al, ACT_REST ret .split: lea eax, [ecx + 1] and al, 3 mov [rdx], al ; next time start one further round mov al, ACT_SPLIT or al, cl ret .atk_up: mov al, ACT_ATTACK + DIR_UP ret .atk_right: mov al, ACT_ATTACK + DIR_RIGHT ret .atk_down: mov al, ACT_ATTACK + DIR_DOWN ret .atk_left: mov al, ACT_ATTACK + DIR_LEFT ret neighbour_idx: db 7, 13, 17, 11 ; VIEW_CELLS index of the square in each direction