Esempio n. 1
0
def loop_game(i, start, queue, cache, cf_lock, level, logger):
    start = bin2mat(human2bin(start))
    game = Game(start, queue, i, level)
    board = Array('f', range(16))
    board[:] = start.reshape((16,)).tolist()[:]
    moves = 0
    while True:
        p = Process(target=game.run, args=(moves, board, cache, cf_lock, logger))
        p.start()
        p.join()
        del p
        moves += 1
Esempio n. 2
0
 def apply(self, b_new, n=None, four=None):
     if four is None:
         four = random.randint(0, 100) > 90
     cell = 2 + (2 * int(four))
     c = self.empty(b_new)
     if n is None:
         if c > 1:
             n = random.randint(0, c - 1)
         else:
             n = 1
     t = 0
     tb = bin2mat(b_new)
     for y in range(4):
         for x in range(4):
             if t == n and tb[y][x] == 0:
                 tb[y][x] = cell
                 t += 1
             elif tb[y][x] == 0:
                 t += 1
     return mat2bin(tb)
Esempio n. 3
0
 def empty(self, board):
     return len(list(filter(lambda x: x == 0,
                            bin2mat(board).reshape((16,)).tolist())))
Esempio n. 4
0
 def __init__(self, board):
     self.board = bin2mat(board)
Esempio n. 5
0
 def move(self, board, cache, cache_queue, logger):
     me = MoveEvaluator(mat2bin(board))
     ce = ChaosEvaluator(cache, self.level, cache_queue, logger)
     ce_res = ce.eval(mat2bin(board))[0]
     return bin2mat(ce.apply(me.sim(np.argmax(ce_res))[0]))