tief([ c[1] for c in children if c[0] == PrimitiveValues.TIE ]) + 1) elif PrimitiveValues.DRAW in values: v = (PrimitiveValues.DRAW, -1) elif PrimitiveValues.WIN in values: v = (PrimitiveValues.LOSE, max([ c[1] for c in children if c[0] == PrimitiveValues.WIN ]) + 1) else: v = (PrimitiveValues.INVALID, -1) else: self.primitiveCounter[v[0].value] += 1 self.memo[p] = v self.counter[v[0].value] += 1 return v times = [] for _ in range(10): game = TTT(3, 3, 3) experiment = MemoSolver(game) start = time.perf_counter() experiment.solve(game.start, min) end = time.perf_counter() times.append(end - start) print("Average Time: ", sum(times) / len(times))
def pressTTT(self): TTTFrame = TTT() TTTFrame.Show()
return 2 @staticmethod def utc(node): # --------------------- # Q(v_i) / 2 * ln(N(v_{i-1})) # UCT(v_i, v) = -------- + / -------------------- # N(v_i) v N(v_i) # v = node.q / (node.n + 1e-12) + sqrt(2 * log(node.parent.n + 1) / (node.n + 1e-12)) return v if __name__ == '__main__': t = TTT() m = MCTS(t.board) while t.result == 0: t.dispboard() time_start = time.time() ii = m.mcts(new_board=t.board, mode='time', criteria=2000) print('iteration value: ', ii) print('elapsed time: ', time.time() - time_start) m.result_view() time_start = time.time() m.mcts(new_board=t.board, mode='iter', criteria=ii) print('elapsed time: ', time.time() - time_start) m.result_view()
with open(save_route + '.txt', 'w') as f: f.write('=== Settings ===\n') f.write(f'- Matchs, Rounds: {mmm}, {rrr}\n') f.write(f'- Look Through: {str(look_through)}\n') f.write(f'- MCTS Setting: {mcts_criteria[0]}, {mcts_criteria[1]}\n\n') # 1. Random vs Random =============================================== p1_data, p2_data, tie_data = [], [], [] p1_wins, p2_wins, tie = 0, 0, 0 iterations = np.arange(rrr, mmm * rrr + 1, rrr) time_start = time.time() for i in range(mmm): for j in range(rrr): t = TTT() if look_through: t.dispboard() print() while t.result == 0: if t.player == 1: v = auto_random(t.board) t.ai_input(v) else: v = auto_random(t.board) t.ai_input(v) if look_through: t.dispboard() print() t.checkresult() t.switch_player()