def make_random_move(): while True: my_brain["last"][0] = random.randint(0, pp.width) my_brain["last"][1] = random.randint(0, pp.height) if isFree(my_brain["last"][0], my_brain["last"][1]): break pp.do_mymove(my_brain["last"][0], my_brain["last"][1])
def brain_turn(): if pp.terminateAI: return ai.setWho(ai.XP) x, y = ai.yourTurn() ai.move(x, y) pp.do_mymove(x, y)
def brain_turn(): global estimator, oppo_move try: # f.write('my_turn\n') if pp.terminateAI: return if estimator is None: estimator = bd.Board(board, (20, 20), whose_turn=1) # f.write('estimator_init\n') # 第一步假定对方很强 # candidates = [None] else: # candidates = estimator.get_candidates(brunch=8) # f.write('estimator_update\n') estimator.toMove(oppo_move, 2) # f.write(str(candidates)+"\n") # move_t = oppo_move # f.write(str(move_t) + "\n") # f.write('try to get candidate\n') moves, values = get_candidate(1) # f.write('try to choose move\n') move, value = action_network_me.forward(moves, values) # f.write(str(move)+'\n') x, y = move pp.do_mymove(x, y) # f.write('finish:do_mymove\n') estimator.toMove((x, y), 1) # f.write('estimator_update2\n') except: pass
def increase_node(info): if isValidPos(info["add_head"][0], info["add_head"][1], 0): pp.do_mymove(info["add_head"][0], info["add_head"][1]) elif isValidPos(info["add_tail"][0], info["add_tail"][1], 0): pp.do_mymove(info["add_tail"][0], info["add_tail"][1]) else: make_random_move()
def brain_turn(): try: if pp.terminateAI: return i = 0 while True: global board global adjacent if check_board(board): x = int(pp.width/2) y = int(pp.height/2) else: play_turn = [1,2] UCT = MCTS_UCT(board, play_turn, time=5, max_actions=7) move = UCT.get_action() x,y = move # logDebug((x,y)) # heuristic = confront_heuristic(board, x, y, 1) # logDebug(my_heuristic(board, x, y, 1)) # logDebug(opponents_heuristic(board, x, y, 1)) # logDebug(heuristic) i += 1 if pp.terminateAI: return if isFree(x,y): break if i > 1: pp.pipeOut("DEBUG {} coordinates didn't hit an empty field".format(i)) pp.do_mymove(x, y) except: logTraceBack() raise Exception("f**k")
def brain_turn(): logDebug("==================================================") logDebug("Starting1") if pp.terminateAI: return sss = 0 while True: # x = random.randint(0, pp.width - 1) # y = random.randint(0, pp.height - 1) logDebug("==================================================") logDebug("Starting") position = GA(gomoku) x = position[0] y = position[1] logDebug("==================================================") logDebug("XY get!") sss += 1 if pp.terminateAI: return if gomoku.is_free(x, y): break if sss > 1: pp.pipeOut( "DEBUG {} coordinates didn't hit an empty field".format(sss)) pp.do_mymove(x, y)
def brain_turn(): if pp.terminateAI: return _board = deepcopy(board) mct_agent = mct.MCTS(_board, 1) x, y = mct_agent.get_best_action() pp.do_mymove(x, y)
def brain_turn(): if pp.terminateAI: return pos, v, top5_points, nodes_num = agent.minimax() x, y = pos pp.do_mymove(x, y) pp.pipeOut("{},{}\tValue:{}\tNodes:{}\tTop5 Points:{}".format(x, y, v, nodes_num, top5_points))
def brain_turn(): """ MCTS Useful materials: class: Board MCTS """ if pp.terminateAI: return MCTS_AI = MCTS(board, players_in_turn=[1, 2], # brain is 1 confidence=2, time_limit=5, max_simulation=200) i = 0 while True: move = MCTS_AI.get_action() x, y = move if MCTS_AI.MCTSboard.winner: print("Winner: {}".format(MCTS_AI.MCTSboard.winner)) break if pp.terminateAI: return if isFree(x, y): break if i > 1: # zs: maybe useful to debug pp.pipeOut("DEBUG {} coordinates didn't hit an empty field".format(i)) pp.do_mymove(x, y)
def MCT_brain(): if pp.terminateAI: return state = (board, 1) mct = myMCT(state) x, y = mct.bestStep() pp.do_mymove(x, y)
def brain_turn(): """choose your move and call do_mymove(x,y), 0 <= x < width, 0 <= y < height""" if pp.terminateAI: return i = 0 while True: Problem = db.DBProblem(board, check=True) category1, (x1, y1) = Problem.getStep() pp.pipeOut("DEBUG My category: {}".format(category1)) oppboard = db.inverseBoard(board) oppProblem = db.DBProblem(oppboard, check=False) category2, (x2, y2) = oppProblem.getStep(category1) pp.pipeOut("DEBUG Opp category: {}".format(category2)) if (category2 < category1): (x, y) = (x2, y2) else: (x, y) = (x1, y1) if (category1 == 3) and (category2 == 3): (x, y) = db.findMostPromising(board, Problem.root.threats) if pp.terminateAI: return if isFree(x, y): break if i > 1: pp.pipeOut("DEBUG {} coordinates didn't hit an empty field".format(i)) pp.do_mymove(x, y)
def brain_turn(): if pp.terminateAI: return # copy_board = copy.deepcopy(board) x, y = AI.choose_move(board) # x=random.randint(0, pp.width-1) # y=random.randint(0, pp.width-1) pp.do_mymove(x, y)
def brain_turn(): global t t.color = 1 if pp.terminateAI: return array = [row[:pp.width] for row in board[:pp.height]] action = t.get_move(array) pp.do_mymove(action[0], action[1])
def abpruning_brain(): if pp.terminateAI: return state = get_board_state(board) action = strategy(state) x = action[0] y = action[1] pp.do_mymove(x, y)
def brain_turn(): if pp.terminateAI: return GOMOKU_AI.time_limit = pp.info_timeout_turn GOMOKU_AI.min_max(7, BOARD, calculus=13, reduction=2) if not isFree(GOMOKU_AI.play_cell.x, GOMOKU_AI.play_cell.y): GOMOKU_AI.play_cell = GOMOKU_AI.rescue_cell x = GOMOKU_AI.play_cell.x y = GOMOKU_AI.play_cell.y pp.do_mymove(x, y)
def brain_turn(): if pp.terminateAI: return #move_left, my_move, opponent_move = updata_board_info(board) mcts = MTCS(board, move_left, my_move, opponent_move) (x, y) = mcts.main() pp.do_mymove(x, y) #logDebug(str((x,y))) with open('D:/学习资料/大三下/人工智能/final pj/code/log.txt', "a") as f: f.write('my move' + str(my_move) + "\n") f.write('opponent move' + str(opponent_move) + '\n') f.flush() """
def brain_turn(): try: if pp.terminateAI: return if board.whose_turn == None: action = ((10, 10), 1) else: action = uct.uct_search() where = action[0] pp.do_mymove(where[0], where[1]) #uct.forward(action) except: logTraceBack() raise Exception("f**k")
def brain_turn(): if pp.terminateAI: return i = 0 while True: x, y = AlphaBetaSearch(board) i += 1 if pp.terminateAI: return if isFree(x, y): break if i > 1: pp.pipeOut("DEBUG {} coordinates didn't hit an empty field".format(i)) pp.do_mymove(x, y)
def brain_turn(): if pp.terminateAI: return i = 0 while True: x = random.randint(0, pp.width - 1) y = random.randint(0, pp.height - 1) i += 1 if pp.terminateAI: return if gomoku.is_free(x, y): break if i > 1: pp.pipeOut("DEBUG {} coordinates didn't hit an empty field".format(i)) pp.do_mymove(x, y)
def brain_turn(): # change if pp.terminateAI: return current_board = [[] for _ in range(pp.width)] for i in range(pp.width): for j in range(pp.height): current_board[i].append(board[i][j]) pro = TSS.Problem(pp.width, TSS.AI(), current_board) res = pro.my_move() x, y = res pp.do_mymove(x, y)
def brain_turn(): if pp.terminateAI: return i = 0 while True: prob = util.MCTS(board) x, y = prob.get_action() i += 1 if pp.terminateAI: return if isFree(x, y): break if i > 1: pp.pipeOut("DEBUG {} coordinates didn't hit an empty field".format(i)) pp.do_mymove(x, y)
def brain_turn(): if pp.terminateAI: return i = 0 while True: x1, y1, score = find(2, 1) i += 1 if pp.terminateAI: return if isFree(x1, y1): break if i > 1: pp.pipeOut("DEBUG {} coordinates didn't hit an empty field".format(i)) else: pp.do_mymove(x1, y1)
def brain_turn(): """ Choose your move and call do_mymove(x,y), 0 <= x < width, 0 <= y < height. Write your strategies here. """ if pp.terminateAI: # the game is over return if not his_moves: # the board is empty, place a move at center pp.do_mymove(int(pp.width//2), int(pp.height//2)) # use MCTS to find a move AI = brain_MCTS(time=pp.info_timeout_turn, max_actions=50000) action = AI.get_action() pp.do_mymove(*action)
def brain_turn(): logDebug('brain_turn()') if pp.terminateAI: return i = 0 while True: x = random.randint(0, pp.width) y = random.randint(0, pp.height) i += 1 if pp.terminateAI: return if isFree(x, y): break if i > 1: pp.pipeOut("DEBUG {} coordinates didn't hit an empty field".format(i)) pp.do_mymove(x, y)
def brain_turn(): # time_start = time.time() if pp.terminateAI: return # global stepcount # if stepcount is None: # stepcount = 0 # for i in range(len(board)): # for j in range(len(board)): # if board[i][j] == 1: # stepcount += 1 # time_limit = 5 + time_start if stepcount > 3 else -1 # (x, y) = player.get_action(board, time_limit) board_copy = deepcopy(board) x, y = algorithm.get_action_fast_version(board_copy) pp.do_mymove(x, y)
def brain_turn(): # if pp.terminateAI: # return # i = 0 # while True: # x = random.randint(0, pp.width) # y = random.randint(0, pp.height) # i += 1 # if pp.terminateAI: # return # if isFree(x,y): # break # if i > 1: # pp.pipeOut("DEBUG {} coordinates didn't hit an empty field".format(i)) board.setController(agent.state["US"]) x, y = board.reasoing() pp.do_mymove(x, y)
def brain_turn(): # modified if pp.terminateAI: return i = 0 while True: x, y = actionNetwork() i += 1 if pp.terminateAI: return if isFree(x, y): # setAround(x, y) break if i > 1: pp.pipeOut("DEBUG {} coordinates didn't hit an empty field".format(i)) pp.do_mymove(x, y)
def brain_turn(): logDebug('brain turn') if pp.terminateAI: return i = 0 while True: x = random.randint(0, pp.width - 1) y = random.randint(0, pp.height - 1) i += 1 if pp.terminateAI: return if gomoku.is_free(x, y): logDebug('brain turn,{},{}'.format(x, y)) logDebug(str(gomoku.get_board())) break if i > 1: pp.pipeOut("DEBUG {} coordinates didn't hit an empty field".format(i)) pp.do_mymove(x, y)
def brain_turn(): """ Choose your move and call do_mymove(x,y), 0 <= x < width, 0 <= y < height. Write your strategies here. Randomly take a move. """ if pp.terminateAI: return i = 0 while True: x = random.randint(0, pp.width) y = random.randint(0, pp.height) i += 1 if pp.terminateAI: return if isFree(x, y): break if i > 1: pp.pipeOut("DEBUG {} coordinates didn't hit an empty field".format(i)) pp.do_mymove(x, y)
def brain_turn(): if pp.terminateAI: return GA_AI = Wuzi_GA(board, players_in_turn=[1, 2], n_in_line=5, time_limit=40.0, DNA_length=2, mutate_rate_limit=0.01, start_number=800, number_limit=500, sruvival_rate=0.1) i = 0 move = GA_AI.get_action() x, y = move if i > 1: # zs: maybe useful to debug pp.pipeOut("DEBUG {} coordinates didn't hit an empty field".format(i)) pp.do_mymove(x, y)