Skip to content

Commit

Permalink
game fluff
Browse files Browse the repository at this point in the history
  • Loading branch information
aeblyve committed Dec 3, 2021
1 parent fd57ee8 commit ae91156
Showing 1 changed file with 55 additions and 7 deletions.
62 changes: 55 additions & 7 deletions code/bot/game.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3

import random, copy
from enum import Enum

T_PIECE = ((0, -1, "b"), (-1, 0, "b"), (0, 0, "b"), (1, 0, "b"))
L_PIECE = ((0, 0, "b"), (1, 0, "b"), (0, -1, "b"), (0, -2, "b"))
Expand Down Expand Up @@ -63,17 +64,61 @@ def shift_piece(piece, x_shift, y_shift):
new_piece.append(new_brick)
return tuple(new_piece)

class CheeseActions(Enum):
DOWN = 1
LEFT = 2
RIGHT = 3
RLEFT = 4
RRIGHT = 5
LOCK = 6
HARD = 7

class CheeseGame:
"""Clear all the cheese to win."""

pass
def __init__(self):
self.randomizer = SimpleRandomizer(PIECES)

def successors(self, state):

go_down_succ = state.move_anchor(0, 1)
go_left_succ = state.move_anchor(-1, 0)
go_right_succ = state.move_anchor(1, 0)
rotate_left_succ = state.rotate_left()
rotate_right_succ = state.rotate_right()
lock_succ = state.lock(self.randomizer)
# TODO
hard_succ


pass



class Randomizer:
pass


def row_is_full(row):
for block in row:
if block == BLANK_LABEL:
return False
return True


def clear_rows(grid):
"""Clear full rows."""
y_dimension = len(grid)
x_dimension = len(grid[0])
blank_row = tuple([" "] * x_dimension)
filtered = list(filter(row_is_full, grid))
# prepend rows until match y_dimension

for _ in y_dimension - len(filtered):
filtered.insert(0, blank_row)
return tuple(filtered)


class SimpleRandomizer(Randomizer):
def __init__(self, bag, weights=None):
self.bag = bag
Expand Down Expand Up @@ -106,15 +151,16 @@ def is_legal(self):
return False
return True

def can_lock(self):
for x, y, label in self.piece:
if y == len(self.grid) - 1 or self.grid[y + 1][x] != BLANK_LABEL:
return True
return False

def lock_piece(self, randomizer):
"""Fix the current piece to the board if possible, and get a new one"""
# TODO suboptimal

can_lock = False
for x, y, label in self.piece:
if y == len(self.grid) - 1 or self.grid[y + 1][x] != BLANK_LABEL:
can_lock = True
break
can_lock = self.can_lock()
if can_lock and self.is_legal():
new_grid = []
for row in self.grid:
Expand All @@ -124,8 +170,10 @@ def lock_piece(self, randomizer):
for i in range(len(new_grid)):
new_grid[i] = tuple(new_grid[i])
new_grid = tuple(new_grid)
new_grid = clear_rows(new_grid)
new_piece = randomizer.choice()
mapped_piece = shift_piece(new_piece, self.spawn[0], self.spawn[1])

return CheeseState(self.spawn, self.spawn, mapped_piece, new_grid)
else:
return CheeseState(self.spawn, self.anchor, self.piece, self.grid)
Expand Down

0 comments on commit ae91156

Please sign in to comment.