示例#1
0
 def getAction(self, gameState, index, validActions):
     if gameState.isLose():
         return None
     actions = gameState.getLegalActions(index, validActions)
     if index == 0: # human player
         unrolled = util.unroll_board(gameState.board)
         x = numpy.asarray(unrolled)
         x = x.reshape(1, x.shape[0])
         if self.feature_transform:
             x = numpy.log2(x)
         predictions = [(self.predict[move](x), move) for move in range(4)]
         predictions.sort(reverse=True)
         if predictions[0][1] in validActions:
             return predictions[0][1]
         else:
             print('Falling back to second choice since {} was last moved'.format(predictions[0][1]))
             return predictions[1][1]
     else:
         return None if len(actions) == 0 else random.choice(actions)
示例#2
0
 def write_move(self, board, move):
     self.inputs_writer.writerow(util.unroll_board(board))
     self.labels_writer.writerow((move, ))
示例#3
0
def eval_snake(state):
    '''
    Linear combination of all squares' values. 
    Inspired by Hadi Pouransari & Saman Ghili's "AI algorithms for the game 2048".
    '''
    return util.dot_product(SNAKE_WEIGHTS, util.unroll_board(state.board))
示例#4
0
文件: data.py 项目: clu8/2048
 def write_move(self, board, move):
     self.inputs_writer.writerow(util.unroll_board(board))
     self.labels_writer.writerow((move,))