Merge branch 'an_branch' of https://bdgit.educoder.net/pahiq8bnc/Jungle into an_branch

deemo2
an_branch
Mix 3 years ago
commit f1db685d34

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

Loading…
Cancel
Save