def testGetOrderedScore_6(): board_w, board_h = 10, 5 vampires = {(4, 3): 4} humans = {(9, 0): 2, (2, 2): 4, (9, 2): 1, (9, 4): 10} cboard = board.Board(board_w, board_h, [], []) cboard.is_vampire = True cboard.humansPos = humans cboard.vampiresPos = vampires moves = cboard.getAvailableMoves(2) print(getPositionsByOrder(moves, cboard, -1))
def testGetOrderedScore_5(): board_w, board_h = 10, 5 vampires = {(3, 3): 4} humans = {(9, 0): 2, (2, 2): 4, (9, 2): 1, (9, 4): 10} cboard = board.Board(board_w, board_h, [], []) cboard.is_vampire = True cboard.humansPos = humans cboard.vampiresPos = vampires cboard.werewolvesPos = {(4, 1): 8} print(getPositionsByOrder([[[2, 2, 4]]], cboard, 4))
def testGetOrderedScore_3(): board_w, board_h = 5, 5 vampires = {(2, 2): 4} humans = {(1, 1): 4, (3, 1): 4, (0, 4): 1, (4, 4): 1} cboard = board.Board(board_w, board_h, [], []) cboard.is_vampire = True cboard.humansPos = humans cboard.vampiresPos = vampires cboard.werewolvesPos = {(1, 2): 7, (1, 3): 7} moves = cboard.getAvailableMoves(3) print(getPositionsByOrder(moves, cboard, 4))
def run(sv): #initialize the board current_board = board.Board(sv.board_h, sv.board_w, sv.mapInfo, sv.startingPosition) status, updates = sv.update() current_board.updateBoard(updates) heuristicHistory = {} clock = Clock(TIME_LIMIT) while True: #print('Board :', current_board.getBoard()) start_time = time.time() clock.startClock() minimax.nb_nodes_explore = 0 minimax.nb_cuts = 0 #perform tree search throw minimax and reprise optim pos exploredPositions = {} #current_pos = current_board.getCurrentPositions() #as new positions are sorted by pos number we do the same for the current_pos current_pos = list( dict( sorted(current_board.getOurDict().items(), key=lambda kv: kv[1], reverse=True)).keys()) new_pos = minimax(current_board, exploredPositions, heuristicHistory, clock)[0] #if we have more new pos than existing, this is a split to manage if len(new_pos) > len(current_pos): for i in range(len(new_pos) - len(current_pos)): current_pos.append(current_pos[0]) print("current_pos", current_pos) print("new pos", new_pos) #move player sv.movePlayers_split_Leo(new_pos) end_time = time.time() print("Time Elapsed : " + str(end_time - start_time)) print("Number of nodes explored :", minimax.nb_nodes_explore) print("Number of cuts performed :", minimax.nb_cuts) status, updates = sv.update() #print("update", updates) current_board.updateBoard(updates) #print('new board', current_board.getBoard()) #input('are you ready ?') if status == "END" or status == "BYE": break print('game ended')