diff --git a/DLS/DLS.py b/DLS/DLS.py index cd1d5fe..f677a31 100644 --- a/DLS/DLS.py +++ b/DLS/DLS.py @@ -1,3 +1,4 @@ +import copy from typing import List, Tuple import pygame import heapq @@ -59,7 +60,7 @@ def getMovement(Id, Animals): move = (Id, x - o_x, y - o_y) Movements.append(move) else: - if right_move(o_x, o_y, x, y, Id, MAP, MAP1): + if left_move(o_x, o_y, x, y, Id, MAP, MAP1): move = (Id, x - o_x, y - o_y) Movements.append(move) return Movements @@ -85,13 +86,14 @@ def getSuccessors(Animals, turn: int): # update the map for action in Actions: Id, dx, dy = action[0], action[1], action[2] - t_Animals = Animals + t_Animals = copy.deepcopy(Animals) x = Animals[Id]['old_x'] + dx y = Animals[Id]['old_y'] + dy t_Animals[Id]['x'] = x t_Animals[Id]['y'] = y - print(t_Animals) - Successors.append(t_Animals) + target = (Id, x, y) + #print(t_Animals) + Successors.append((t_Animals, target)) # updateMAP() return Successors @@ -224,24 +226,24 @@ def depthLimitedSearch2(curAnimals, turn): # depth = 2 else: turn2 = 1 for Move in tempNextMove: - Successors2 = getSuccessors(Move[0], turn2) - nextMove2 = [(Successor2, Heuristic(Successor2, turn2)) for Successor2 in Successors2] - max2 = inf + Successors2 = getSuccessors(Move[0][0], turn2) + nextMove2 = [(Successor2, Heuristic(Successor2[0], turn2)) for Successor2 in Successors2] + max2 = -inf for action2 in nextMove2: - if action2[1] < max2: + if action2[1] > max2: max2 = action2[1] nextMove.append((Move, max2)) - min1 = -inf + min1 = inf index = 0 for i in range(len(nextMove)): - if nextMove[i][1] > min1: + if nextMove[i][1] < min1: min1 = nextMove[i][1] index = i - return nextMove[index][0] + return nextMove[index][0][0][1] axis = [(0, 0), (2, 6), (1, 1), (1, 5), (2, 2), (2, 4), (2, 3), (2, 0), (6, 0), (7, 5), (7, 1), (6, 4), (6, 2), (6, 3), (6, 6)] Axis = s.Chessmen_axis(axis) Animals = Axis.axis -print(len(axis)) +print(depthLimitedSearch2(Animals, 0))