This commit is contained in:
korzepadawid 2022-05-09 18:22:01 +02:00
parent 1a4f245087
commit 33577c1824
3 changed files with 10 additions and 7 deletions

View File

@ -58,7 +58,7 @@ def castle_neighbors(map, castle_bottom_right_row, castle_bottom_right_col):
return neighbors
def find_neighbours(col: int, row: int) -> List[Tuple[int, int]]:
def find_neighbours(grid: List[List[str]], col: int, row: int) -> List[Tuple[int, int]]:
dr = [-1, 1, 0, 0]
dc = [0, 0, -1, 1]
@ -70,7 +70,7 @@ def find_neighbours(col: int, row: int) -> List[Tuple[int, int]]:
if rr < 0 or cc < 0: continue
if rr >= ROWS or cc >= COLUMNS: continue
if grid[rr][cc] not in ['g', 's', '.']: continue
neighbours.append((rr, cc))
return neighbours

View File

@ -34,7 +34,7 @@ class DecisionTree:
self.model = DecisionTreeClassifier(criterion='entropy')
self.model.fit(self.train_set.values, self.goals)
def predict_move(self, map: List[List[str]], current_knight: Knight, castle: Castle, monsters: List[Monster],
def predict_move(self, grid: List[List[str]], current_knight: Knight, castle: Castle, monsters: List[Monster],
opponents: List[Knight]) -> \
List[Tuple[int, int]]:
distance_to_castle = manhattan_distance(current_knight.position, castle.position)
@ -59,14 +59,14 @@ class DecisionTree:
agent_hp=current_knight.current_hp)
print(prediction)
if prediction == 'tower': # castle...
return castle_neighbors(map, castle_bottom_right_row=castle.position[0],
return castle_neighbors(grid, castle_bottom_right_row=castle.position[0],
castle_bottom_right_col=castle.position[1])
elif prediction.startswith('opp'):
idx = parse_idx_of_opp_or_monster(prediction)
return find_neighbours(opponents[idx].position[1], opponents[idx].position[0])
return find_neighbours(grid, opponents[idx].position[1], opponents[idx].position[0])
else:
idx = parse_idx_of_opp_or_monster(prediction)
return find_neighbours(monsters[idx].position[1], monsters[idx].position[0])
return find_neighbours(grid, monsters[idx].position[1], monsters[idx].position[0])
def get_prediction(self, tower_dist: int, mob1_dist: int, mob2_dist: int, opp1_dist: int, opp2_dist: int,
opp3_dist: int, opp4_dist: int, agent_hp: int, tower_hp: int, mob1_hp: int, mob2_hp: int,

View File

@ -113,12 +113,15 @@ class Level:
knight_pos_x = current_knight.position[0]
knight_pos_y = current_knight.position[1]
goal_list = self.decision_tree.predict_move(map=self.map, current_knight=current_knight,
goal_list = self.decision_tree.predict_move(grid=self.map, current_knight=current_knight,
monsters=self.list_monsters,
opponents=self.list_knights_red
if current_knight.team_alias == 'k_r' else self.list_knights_blue,
castle=self.list_castles[0])
if len(goal_list) == 0:
return
state = State((knight_pos_y, knight_pos_x), current_knight.direction.name)
action_list = a_star(state, self.map, goal_list)
print(action_list)