Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
def test_mod():
    state = State(stack=[1, 5, 3])
    state.mod()
    assert state.stack == [1, 2]
Ejemplo n.º 4
0
def test_div():
    state = State(stack=[1, 6, 2])
    state.div()
    assert state.stack == [1, 3]
Ejemplo n.º 5
0
def test_sub():
    state = State(stack=[1, 2, 3])
    state.sub()
    assert state.stack == [1, -1]
Ejemplo n.º 6
0
def test_mul():
    state = State(stack=[1, 2, 3])
    state.mul()
    assert state.stack == [1, 6]
Ejemplo n.º 7
0
def test_add():
    state = State(stack=[1, 2, 3])
    state.add()
    assert state.stack == [1, 5]
Ejemplo n.º 8
0
def test_swap_one_item_in_stack():
    state = State(stack=[1])
    with pytest.raises(exc.StackError):
        state.swap()
Ejemplo n.º 9
0
def test_dup():
    state = State(stack=[1, 1])
    state.swap()
    assert state.stack == [1, 1]
Ejemplo n.º 10
0
def test_swap():
    state = State(stack=[1, 2])
    state.swap()
    assert state.stack == [2, 1]
Ejemplo n.º 11
0
def test_push():
    state = State()
    state.push(1)
    assert state.stack == [1]
Ejemplo n.º 12
0
def test_load_key_not_in_heap():
    state = State(stack=[5])
    with pytest.raises(exc.HeapError):
        state.load()
Ejemplo n.º 13
0
def test_load_empty_stack():
    state = State(heap={5: 80})
    with pytest.raises(exc.StackError):
        state.load()
Ejemplo n.º 14
0
def test_load():
    state = State(heap={5: 80}, stack=[5])
    state.load()
    assert state.stack == [80]
Ejemplo n.º 15
0
def test_store_only_one_item_in_stack():
    state = State(stack=[5])
    with pytest.raises(exc.StackError):
        state.store()
Ejemplo n.º 16
0
def test_pop():
    state = State(stack=[1, 2])
    state.pop()
    assert state.stack == [1]
Ejemplo n.º 17
0
def test_store():
    state = State(stack=[5, 80])
    state.store()
    assert state.heap == {5: 80}
Ejemplo n.º 18
0
def test_swap_empty_stack():
    state = State()
    with pytest.raises(exc.StackError):
        state.swap()