def __init__(self, col, row, p): self.col = col self.row = row self.p = p self.board = Board(col, row, p) self.board.initialize_game() self.color = 2
def __init__(self, col, row, k, g): self.k = k self.col = col self.row = row self.board = Board(col, row, k, g) self.g = True if g == 1 else False self.win = 10**k
def train_one_episode(self): # This is training function for one episode, start a new board and # update Q value until win or loss # QUESTION IS HOW TO DECIDE OPPONENT MOVE? BY SELF-TRAIN? AND HOW TO SELF-TRAIN? new_board = Board() new_board.initialize_game() turn = ''
def __init__(self, col, row, p): self.col = col self.row = row self.p = p self.board = Board(col, row, p) self.board.initialize_game() self.color = '' self.opponent = {1: 2, 2: 1} self.color = 2
def simulate_lr(self, color): # simulate one time # record all X features to feature_matrix # update the y value accordingly print("entering simulations") newboard = Board(self.col, self.row, self.p) newboard.initialize_game() feature_list_b = [] feature_list_w = [] win = 0 ### TODO: Fixing Current move in a new board curr_turn = self.opponent[color] for turn in range(50): if newboard.is_win(color) == color: win = 1 break elif newboard.is_win(self.opponent[color]) == self.opponent[color]: break move = self.minimax_move(newboard.get_all_possible_moves(curr_turn)) newboard.make_move(move, curr_turn) b, w = self.get_X(self.board) feature_list_b.append(b) feature_list_w.append(w) self.feature_matrix = np.append(self.feature_matrix, np.array([b, w]), axis=0) print(self.feature_matrix) curr_turn = self.opponent[curr_turn] else: win = 0.5 # matrix = np.array([feature_list_b, feature_list_w]) # feature_matrix = np.hstack((matrix, np.zeros((matrix.shape[0], 1)))) # TODO: Fixing y value update if win == 1 and color == 1: for fb in feature_list_b: index = np.where(fb in self.feature_matrix[:, 0:self.feature_size]) if index == []: self.feature_matrix = np.append(self.feature_matrix, np.array([b, w]), axis=0) self.feature_matrix[index, self.feature_size] += 1 elif win == 0 and color == 1: for fw in feature_list_w: index = np.where(fw in self.feature_matrix[:, 0:self.feature_size]) if index == []: self.feature_matrix = np.append(self.feature_matrix, np.array([b, w]), axis=0) self.feature_matrix[index, self.feature_size] += 1 return win
def __init__(self, col, row, p): self.col = col self.row = row self.p = p self.board = Board(col, row, p) self.board.initialize_game() self.color = 2 self.mcts = MCTS(TreeNode(self.board, self.color, None, None)) self.total_time_remaining = 479 self.time_divisor = row * col * 0.5 self.timed_move_count = 2
def __init__(self, col, row, p): self.col = col self.row = row self.p = p self.board = Board(col, row, p) self.board.initialize_game() self.color = '' self.opponent = {1: 2, 2: 1} self.color = 2 self.movecount = 0 self.simulate_times = 100
def __init__(self, col, row, p): self.col = col self.row = row self.p = p self.board = Board(col, row, p) self.board.initialize_game() self.color = '' self.opponent = {1: 2, 2: 1} self.color = 2 self.search_lim = 5 self.current_node = TreeNode(None, self.color)
def __init__(self, col, row, p): self.col = col self.row = row self.p = p self.board = Board(col, row, p) self.board.initialize_game() self.color = '' self.opponent = {1: 2, 2: 1} self.color = 2 self.bestMove = None self.blackVal = 0 #------- self.whiteVal = 0 #-------
def __init__(self, col, row, p): self.col = col self.row = row self.p = p self.startnode = Node() self.startnode.board = Board(col, row, p) self.startnode.board.initialize_game() self.color = '' self.opponent = {1: 2, 2: 1} self.color = 2 self.maxiter = 100 self.curriter = 0
def __init__(self, col, row, p): self.col = col self.row = row self.p = p self.board = Board(col, row, p) self.board.initialize_game() self.number_of_move = 0 self.EARLY_GAME = 10 self.MID_GAME = 20 self.END_GAME = 30 self.run_time_depth = 5 self.opponent = {1: 2, 2: 1} self.color = 2
def __init__(self, col, row, p): self.col = col self.row = row self.p = p self.board = Board(col, row, p) self.board.initialize_game() self.color = '' self.opponent = {1: 2, 2: 1} self.color = 2 self.halftime = time.time() + 240 self.endtime = time.time() + 360 self.finaltime = time.time() + 460 self.root = Node(0, 0)
def __init__(self, col, row, p): self.col = col self.row = row self.p = p self.board = [Board(col, row, p) for i in range(num_processes)] for board in self.board: board.initialize_game() self.color = '' self.opponent = {1: 2, 2: 1} self.color = 2 self.search_lim = 5 self.current_node = TreeNode(None, self.color) self.sim_total = 0 self.sim_counter = 0
def __init__(self, col, row, p): self.col = col self.row = row self.p = p self.board = Board(col, row, p) self.board.initialize_game() self.color = '' self.opponent = {1: 2, 2: 1} self.color = 2 self.search_depth = 5 self.debug = True self.time_used = 0 self.transposition_table = dict()
def __init__(self, col, row, p): self.col = col self.row = row self.p = p self.board = Board(col, row, p) self.board.initialize_game() self.color = '' self.opponent = {1: 2, 2: 1} self.color = 2 self.movecount = 1 self.file = f"{self.col}-{self.row}-{self.color}-{randint(0, 500)}-test.txt" self.start = time.time() self.theta1, self.theta2 = self.get_theta() self.cutoff = self.get_cutoff()
def __init__(self, col, row, p): self.col = col self.row = row self.p = p self.boards = [] for i in range(num_thread): self.boards.append(Board(col, row, p)) self.boards[i].initialize_game() self.color = '' self.opponent = {1: 2, 2: 1} self.color = 2 self.mcts_trees = [ TreeNode(None, self.color) for i in range(num_thread) ] self.sim_total = 0 self.sim_counter = 0
def __init__(self, col, row, p): """ Intializes manualAI @param row: no of rows in the board @param col: no of columns in the board @param k: no of rows to be filled with checker pieces at the start @return : @raise : """ self.col = col self.row = row self.p = p self.board = Board(col, row, p) self.board.initialize_game() self.color = 2 self.opponent = {1: 2, 2: 1} # to switch turns after each turn
def __init__(self, col, row, p): self.col = col self.row = row self.p = p self.board = Board(col, row, p) self.board.initialize_game() self.color = '' self.opponent = {1: 2, 2: 1} self.color = 2 self.depth = 0 self.turn = 0 self.control = asyncio.get_event_loop() self.iterative_depth_limit = self.INITIAL_DEPTH_LIMIT self.time_left = TimeFlags.UNDER self.time_used = 0 self.upper_depth_limit = float('inf')
def __init__(self, col, row, p): self.col = col self.row = row self.p = p self.board = Board(col, row, p) self.board.initialize_game() self.color = '' self.opponent = {1: 2, 2: 1} self.color = 2 ##ADDED self.calc_time = 1999 self.visited_tree = [] self.C = 1.6 self.colors = {1: "B", 2: "W"} self.letters = {"B": 1, "W": 2}
def train_one_episode(self): new_board = Board() new_board.initialize_game() turn = '' while True: if new_board.is_win(self.color): break elif new_board.is_win(self.opponent[self.color]): break action = self.explore(new_board, self.color) state = new_board new_state = new_board.make_move(action, turn) self.Q_table[state, action] = self.Q_table[state, action] + self.lr * \ (self.reward(state, action) + self.gamma * np.max(self.Q_tableQ[new_state, :])\ - self.Q_table[state, action]) state = new_state
def __init__(self, col, row, p): self.col = col self.row = row self.p = p self.board = Board(col, row, p) self.board.initialize_game() self.color = '' self.opponent = {1: 2, 2: 1} self.color = 2 #---------------------------------# self.area = self.row * self.col self.count = 0 if self.area <= 39: self.depth = 8 elif self.area <= 49: self.depth = 5 elif self.area <= 79: self.depth = 4 else: self.depth = 4
def __init__(self, col, row, p): self.col = col self.row = row self.p = p self.board = Board(col, row, p) self.board.initialize_game() self.color = '' self.opponent = {1: 2, 2: 1} self.color = 2 self.depth = 0 self.turn = 0 self.control = asyncio.get_event_loop() self.iterative_depth_limit = self.INITIAL_DEPTH_LIMIT self.time_left = TimeFlags.UNDER self.time_used = 0 self.upper_depth_limit = float('inf') self.time_limit = 480 # 8 minutes self.late_game_flag = False self.heuristic_flag = 1 #use ieee1, if 2, use ieee2 self.flag_just_changed = 0
def __init__(self,col,row,p): self.col = col self.row = row self.p = p self.board = Board(col,row,p) self.board.initialize_game() self.color = '' self.opponent = {1:2,2:1} self.color = 2 # new params ''' new data clearification: feature_matrix = [[X1, X2, ..., X_feature_size, Y], ... [X1m, X2m, ..., X_feature_size_m, Y]] ''' self.movecount = 0 self.feature_size = 5 self.thetas = np.random.rand(self.feature_size) self.feature_matrix = np.empty((0, self.feature_size))
def __init__(self, col, row, p): self.col = col self.row = row self.p = p self.board = Board(col, row, p) self.board.initialize_game() self.color = '' self.opponent = {1: 2, 2: 1} self.color = 2 # ---------- What we added ----------- self.calc_time = datetime.timedelta(seconds=3) self.max_moves = 35 self.wins = {} self.plays = {} self.max_depth = 0 self.C = 1.4 self.colors = {1: "B", 2: "W"} self.letters = {"B": 1, "W": 2} self.states = []
def simulate(self, player): win = 0 counter = 0 fake_board = Board(self.col, self.row, self.p) self.copy_board(fake_board) # print("DIT ME DIEN") # fake_board.show_board() # totaltime = 0 while win == 0: moves = fake_board.get_all_possible_moves(player) if len(moves) == 1: index = 0 elif len(moves) == 0: win = self.opponent[player] break else: index = randint(0, len(moves) - 1) if len(moves[index]) == 1: inner_index = 0 else: inner_index = randint(0, len(moves[index]) - 1) move = moves[index][inner_index] fake_board.make_move(move, player) counter += 1 # bt = time.time() if fake_board.tie_counter >= fake_board.tie_max: win = -1 # totaltime += time.time() - bt # print("self.board.is_win():", time.time() - bt) player = self.opponent[player] # #print("total time is_win:", totaltime) # #bt = time.time() # for i in range(counter): # self.board.undo() # #rint("total time undo:", time.time() - bt) # fake_board.show_board() return win
def __init__(self, col, row, p): self.col = col self.row = row self.p = p self.board = Board(col, row, p) self.board.initialize_game() self.color = '' self.opponent = {1: 2, 2: 1} self.color = 2 self.ct = 0 #self.dif_val = False self.size = self.col * self.row if self.size < 40: #6x6 #print(8) self.search_depth = 8 elif self.size < 50: #7x7 #print(7) self.search_depth = 5 elif self.size < 80: #8x8 #print(6) self.search_depth = 4 else: self.search_depth = 4
def __init__(self, player1, player2, boardRows, boardCols): self.player1 = player1 self.player2 = player2 self.board = Board(boardRows, boardCols) self.turnNumber = 0 self.setUpInitialBoardState()
def __init__(self,col,row,k,g): self.g = g self.col = col self.row = row self.k = k self.board = Board(col,row,k,g)