def move(): if game_over(state_board): print("GAME IS OVER") response = app.response_class( response="game over", status=200 ) return response source = int(request.args.get('from', default='')) destination = int(request.args.get('to', default='')) # human move human_move(source, destination) # computer_move state = State(state_board, Turn.BLACK, []) move = move_function(state) computer_move(move) response = app.response_class( response=BOARD.fen(), status=200 ) return response
def __init__(self): """Initialize game.""" # Initialize pygame window pygame.init() pygame.display.set_caption("Snake Game") self.scene = pygame.display.set_mode(self.DIMENSIONS) # Initialize backend components self.background_color = 0, 0, 0 self.board = Board((self.DIMENSIONS[1] // 10, self.DIMENSIONS[0] // 10)) self.state = State() self.handler = RenderHandler([], self.scene) # Initialize game objects self.food = Food(self.board) self.player = Player(self.DIMENSIONS[0] // 20, self.DIMENSIONS[1] // 20, self.board, self.food, self.state)
def test_mod(): state = State(stack=[1, 5, 3]) state.mod() assert state.stack == [1, 2]
def test_div(): state = State(stack=[1, 6, 2]) state.div() assert state.stack == [1, 3]
def test_sub(): state = State(stack=[1, 2, 3]) state.sub() assert state.stack == [1, -1]
def test_mul(): state = State(stack=[1, 2, 3]) state.mul() assert state.stack == [1, 6]
def test_add(): state = State(stack=[1, 2, 3]) state.add() assert state.stack == [1, 5]
def test_swap_one_item_in_stack(): state = State(stack=[1]) with pytest.raises(exc.StackError): state.swap()
def test_dup(): state = State(stack=[1, 1]) state.swap() assert state.stack == [1, 1]
def test_swap(): state = State(stack=[1, 2]) state.swap() assert state.stack == [2, 1]
def test_push(): state = State() state.push(1) assert state.stack == [1]
def test_load_key_not_in_heap(): state = State(stack=[5]) with pytest.raises(exc.HeapError): state.load()
def test_load_empty_stack(): state = State(heap={5: 80}) with pytest.raises(exc.StackError): state.load()
def test_load(): state = State(heap={5: 80}, stack=[5]) state.load() assert state.stack == [80]
def test_store_only_one_item_in_stack(): state = State(stack=[5]) with pytest.raises(exc.StackError): state.store()
def test_pop(): state = State(stack=[1, 2]) state.pop() assert state.stack == [1]
def test_store(): state = State(stack=[5, 80]) state.store() assert state.heap == {5: 80}
def test_swap_empty_stack(): state = State() with pytest.raises(exc.StackError): state.swap()