Skip to content

Commit

Permalink
Updates to Agent 7
Browse files Browse the repository at this point in the history
  • Loading branch information
athar-va committed Nov 9, 2022
1 parent 103660f commit db2fa94
Show file tree
Hide file tree
Showing 6 changed files with 884 additions and 350 deletions.
113 changes: 36 additions & 77 deletions Agent_7.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,26 @@ def begin(arena):
print("In game Agent_7 at game_count: ", game_count, " step_count: ", step_count)
print(agent7.curr_pos, prey.curr_pos, predator.curr_pos)


# Check if it knows where the predator is
if max(agent7.predator_belief_state.values()) == 1.0:
found_prey, node_surveyed = utils.survey_prey(agent7, prey)
found_prey, prey_node_surveyed = utils.survey_prey(agent7, prey)
else:
found_predator, node_surveyed = utils.survey_predator(agent7, predator)
found_predator, predator_node_surveyed = utils.survey_predator(agent7, predator)

if prey_node_surveyed != None:
node_surveyed = prey_node_surveyed
if prey_node_surveyed == predator.curr_pos:
found_predator = True

else:
node_surveyed = predator_node_surveyed
if predator_node_surveyed == prey.curr_pos:
found_prey = True


# updating both belief states

agent7.prey_belief_state = utils.update_prey_belief_state(agent7.prey_belief_state, \
agent7.curr_pos, \
agent7.prev_pos, \
Expand All @@ -119,7 +132,8 @@ def begin(arena):
'after_survey')
if max(agent7.prey_belief_state.values()) == 1:
prey_certainty_counter += 1



agent7.predator_belief_state = utils.update_predator_belief_state(agent7.predator_belief_state, \
agent7.curr_pos, \
agent7.prev_pos, \
Expand All @@ -129,28 +143,17 @@ def begin(arena):
'after_survey')
if max(agent7.predator_belief_state.values()) == 1:
predator_certainty_counter += 1


"""
# print(found_prey)
if found_prey:
# found the prey and now have to use a variable assignment tree to track the prey
pass
else:
# Choose a node at random and assume it is where the prey is
agent7.prey_belief_state[node_surveyed] = 0
for i in range(50):
degree = utils.get_degree(arena, i)
if i != node_surveyed:
agent7.prey_belief_state[i] += 1/48 # Has to be phrased in the form of previous probability and next probability in terms of the degree of neighbours of this node
"""

believed_prey_curr_pos = utils.return_max_prey_belief(agent7.prey_belief_state, arena)
believed_predator_curr_pos = utils.return_max_predator_belief(agent7.predator_belief_state, arena)

# print( " After survey, Predator at : ", predator.curr_pos," believed at :", believed_predator_curr_pos)
# pprint(agent7.predator_belief_state)
# print(sum(agent7.predator_belief_state.values()))

# print(f'believed_prey_curr_pos: {believed_prey_curr_pos}')
# print(f'believed_predator_curr_pos: {believed_predator_curr_pos}')

#using the max belief node for prey
agent7.move(arena, believed_prey_curr_pos, believed_predator_curr_pos)

Expand Down Expand Up @@ -179,6 +182,10 @@ def begin(arena):
node_surveyed, \
'after_agent_moves')

# print(" After survey, Predator at : ", predator.curr_pos, " believed at :", believed_predator_curr_pos)
# pprint(agent7.predator_belief_state)
# print(sum(agent7.predator_belief_state.values()))

prey.move(arena)

agent7.prey_belief_state = utils.update_prey_belief_state(agent7.prey_belief_state, \
Expand All @@ -203,6 +210,17 @@ def begin(arena):
found_predator, \
node_surveyed, \
'after_predator_moves')

# print(" After survey, Predator at : ", predator.curr_pos, " believed at :", believed_predator_curr_pos)
# pprint(agent7.predator_belief_state)
# print(sum(agent7.predator_belief_state.values()))

found_prey = False
found_predator = False

predator_node_surveyed = None
prey_node_surveyed = None

# Checking termination states
if agent7.curr_pos == predator.curr_pos:
loss_count += 1
Expand Down Expand Up @@ -230,62 +248,3 @@ def begin(arena):
forced_termination * 100 / number_of_games, prey_certainty * 100 / number_of_games, predator_certainty * 100 / number_of_games]
# data.append(data_row)
return data_row


"""
# Class Test code
#arena=env.generate_environement()
arena = {0: [1, 49, 48],
1: [2, 0, 46],
2: [3, 1, 5],
3: [4, 2, 7],
4: [5, 3, 6],
5: [6, 4, 2],
6: [7, 5, 4],
7: [8, 6, 3],
8: [9, 7, 10],
9: [10, 8, 11],
10: [11, 9, 8],
11: [12, 10, 9],
12: [13, 11, 14],
13: [14, 12, 15],
14: [15, 13, 12],
15: [16, 14, 13],
16: [17, 15, 19],
17: [18, 16, 20],
18: [19, 17, 21],
19: [20, 18, 16],
20: [21, 19, 17],
21: [22, 20, 18],
22: [23, 21, 26],
23: [24, 22, 25],
24: [25, 23, 28],
25: [26, 24, 23],
26: [27, 25, 22],
27: [28, 26, 30],
28: [29, 27, 24],
29: [30, 28, 31],
30: [31, 29, 27],
31: [32, 30, 29],
32: [33, 31, 35],
33: [34, 32],
34: [35, 33, 39],
35: [36, 34, 32],
36: [37, 35, 38],
37: [38, 36, 41],
38: [39, 37, 36],
39: [40, 38, 34],
40: [41, 39, 44],
41: [42, 40, 37],
42: [43, 41],
43: [44, 42, 47],
44: [45, 43, 40],
45: [46, 44, 49],
46: [47, 45, 1],
47: [48, 46, 43],
48: [49, 47, 0],
49: [0, 48, 45]}
# print(a1.curr_pos)
a1.move(arena, 5, 6)
# pprint(arena)
"""
4 changes: 2 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# FILE_PATH = 'D:/Desktop/Fall_22_Academics/520_Intro to AI/Project_2/Data/'
FILE_PATH = '/Users/dhanur/Everything/Subjects/520_Intro_to_Artificial_Intelligence/Projects/Project_2/circle_of_life/The-Circle-of-Life/data/'
FILE_PATH = 'D:/Desktop/Fall_22_Academics/520_Intro to AI/Project_2/Data/'
# FILE_PATH = '/Users/dhanur/Everything/Subjects/520_Intro_to_Artificial_Intelligence/Projects/Project_2/circle_of_life/The-Circle-of-Life/data/'
FILE_NAME = 'Agent_3_data.csv'

NUMBER_OF_GAMES = 30
Expand Down
6 changes: 3 additions & 3 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from Agent_7_with_defective_drone import Agent_7_wdd
from Agent_7_wdd_handled import Agent_7_wdd_handled
# from Agent_9 import Agent_9
from test_agent import Agent_test
# from test_agent import Agent_7
import utils
import config

Expand All @@ -34,9 +34,9 @@ def run():
arena = env.generate_environement()
# results.append(Agent_1.begin(arena))
# results.append(Agent_2.begin(arena))
results.append(Agent_3.begin(arena))
# results.append(Agent_3.begin(arena))
# results.append(Agent_4.begin(arena))
#results.append(Agent_5.begin(arena))
results.append(Agent_5.begin(arena))
# results.append(Agent_6.begin(arena))
# results.append(Agent_7.begin(arena))
# results.append(Agent_8.begin(arena))
Expand Down
Loading

0 comments on commit db2fa94

Please sign in to comment.