Skip to content

Commit

Permalink
fluff
Browse files Browse the repository at this point in the history
  • Loading branch information
aeblyve committed Dec 3, 2021
1 parent 9742beb commit 1a7d124
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions code/bot/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,30 @@ def successors(self, state):
rotate_left_succ = state.rotate_left()
rotate_right_succ = state.rotate_right()
lock_succ = state.lock(self.randomizer)
# TODO hard_succ

pass
hard_succ = state.hard_drop(self.randomizer)
# each action costs 1
successors = [
(go_down_succ, CheeseActions.DOWN, 1),
(go_left_succ, CheeseActions.LEFT, 1),
(go_right_succ, CheeseActions.RIGHT, 1),
(rotate_left_succ, CheeseActions.RLEFT, 1),
(rotate_right_succ, CheeseActions.RRIGHT, 1),
(lock_succ, CheeseActions.LOCK, 1),
(hard_succ, CheeseActions.HARD, 1),
]

return filter(lambda x: x[0].is_legal(), successors)

def is_terminal(self, state):
"""Illegal states and cleared cheese is terminal
If terminal, return the utility, else 0
"""
if not state.is_legal():
return -100
elif state.is_clear():
return 100
else:
return 0


class Randomizer:
Expand Down Expand Up @@ -141,6 +162,10 @@ def move_anchor(self, x_shift, y_shift):
new_piece = shift_piece(self.piece, x_shift, y_shift)
return CheeseState(self.spawn, new_anchor, new_piece, self.grid)

def is_clear(self):
"""If the last row is clear, the whole stage is"""
return self.grid[len(self.grid) - 1][0] != CHEESE_LABEL

def is_legal(self):
"""Illegal if oob or intersecting"""
for x, y, label in self.piece:
Expand Down

0 comments on commit 1a7d124

Please sign in to comment.