Exemplo n.º 1
0
 def move_right(self, matrix):
     if matrix in self. right_table:
         self.hits += 1
         return self.right_table[matrix]
     else:
         self.right_table[matrix] = game.move_right(matrix)
         return self.right_table[matrix]
Exemplo n.º 2
0
def move_right(matrix):
    if matrix in RIGHT_TABLE:
        global HITS
        HITS += 1
        return RIGHT_TABLE[matrix]
    else:
        RIGHT_TABLE[matrix] = game.move_right(matrix)
        return RIGHT_TABLE[matrix]
Exemplo n.º 3
0
def action(x,i):
    if i == 0:
        return game.move_up(x)
    elif i == 1:
        return game.move_down(x)
    elif i == 2:
        return game.move_left(x)
    elif i == 3:
        return game.move_right(x)
Exemplo n.º 4
0
 def action(loc, board):
     if loc == 0:
         board = game.move_up(board)
     elif loc == 1:
         board = game.move_down(board)
     elif loc == 2:
         board = game.move_left(board)
     else:
         board = game.move_right(board)
     return board
Exemplo n.º 5
0
def on_key_press(symbol, modifiers):
    global last_move, down_press
    if symbol == key.LEFT:
        game.active_piece, game.grid = game.move_left(game.active_piece, game.grid)
        last_move = 1
    if symbol == key.RIGHT:
        game.active_piece, game.grid = game.move_right(game.active_piece, game.grid)
        last_move = 2
    if symbol == key.UP:
        game.active_piece, game.grid = game.rotate_piece(game.active_piece, game.grid)
        last_move = 3
    if symbol == key.DOWN:
        down_press = True
Exemplo n.º 6
0
def find_best_move(matrix):
    best_move = None
    best_score = -1
    matrixes = [game.move_up(matrix),
                game.move_down(matrix),
                game.move_left(matrix),
                game.move_right(matrix)]
    for i in range(4):
        if matrixes[i] != matrix:
            score = score_matrix(matrixes[i])
            if score >= best_score:
                best_score = score
                best_move = i
    return best_move, best_score
Exemplo n.º 7
0
def action(x, board):
    comp = 0
    loc = 0
    for i in range(4):
        if x[i] > comp:
            loc = i
            comp = x[i]
    if loc == 0:
        board = game.move_up(board)
    elif loc == 1:
        board = game.move_down(board)
    elif loc == 2:
        board = game.move_left(board)
    else:
        board = game.move_right(board)
    return board