Beispiel #1
0
 def move_down(self, matrix):
     if matrix in self.down_table:
         self.hits += 1
         return self.down_table[matrix]
     else:
         self.down_table[matrix] = game.move_down(matrix)
         return self.down_table[matrix]
Beispiel #2
0
def update_frame(x):
    global state, score, high_score, last_move, bot_mode, down_press

    if bot_mode:
        # a = policy(Variable(torch.from_numpy(state).type(torch.FloatTensor)))
        # _, ac = a.max(0)
        # action = ac.item()

        a = policy(Variable(torch.from_numpy(state).type(torch.FloatTensor)))
        # a = F.softmax(a, dim=-1)
        c = Categorical(a)
        action = c.sample()

        # action = train.select_action(state).item()

        state, reward, done = game.step(action)

        last_move = action
    else:
        state, reward, done = game.step(0)
        if down_press:
            game.active_piece, game.grid, _ = game.move_down(game.active_piece, game.grid)
            last_move = 4

    score += reward

    if done:
        game.reset()
        high_score = max(high_score, score)
        score = 0
Beispiel #3
0
def move_down(matrix):
    if matrix in DOWN_TABLE:
        global HITS
        HITS += 1
        return DOWN_TABLE[matrix]
    else:
        DOWN_TABLE[matrix] = game.move_down(matrix)
        return DOWN_TABLE[matrix]
Beispiel #4
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)
Beispiel #5
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
Beispiel #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
Beispiel #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