-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
113 lines (73 loc) · 3.49 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import time
import sys
import os
# import constant definitions
from macros import *
# import game class
from hamham import Game
# import agents
from agent import Agent
from astar_agent import AStarAgent
from dstar_lite_agent import DStarLiteAgent
# Initialize game
hamham = Game()
# to prevent infinite loop while playing, just in case
MAX_EPISODE_LENGTH = 500
#First command line argument is player_string
player_string = ""
if (len(sys.argv) >= 2):
player_string = sys.argv[1]
else:
# no argument is provided, assign player_string hardcodedly
player_string = "HUMAN"
#player_string = "ASTAR"
#player_string = "DSTAR"
player_string = player_string.upper()
#Second command line argument is played level
PLAYED_LEVEL = 1
if (len(sys.argv) >= 3):
PLAYED_LEVEL = int(sys.argv[2])
else:
PLAYED_LEVEL = 1
# display player and played level
print("Player {} will be playing level {}".format(player_string, PLAYED_LEVEL))
if (player_string == "HUMAN"):
(collected_apple_count, elapsed_time_step) = hamham.start_level_human(PLAYED_LEVEL)
printed_str = "--- Player Statistics ---\n"
printed_str += "collected apple count:{}\n".format(collected_apple_count)
printed_str += "elapsed time step:{}\n".format(elapsed_time_step)
print(printed_str)
elif (player_string == "ASTAR"):
agent = AStarAgent()
(collected_apple_count, elapsed_time_step, elapsed_solve_time, result) = hamham.start_level_computer(PLAYED_LEVEL, agent,
render=True, play_sound=True,
max_episode_length=MAX_EPISODE_LENGTH,
test=True)
printed_str = "--- A* Agent Statistics ---\n"
printed_str += "elapsed time step:{}\n".format(elapsed_time_step)
printed_str += "number of generated nodes:{}\n".format(agent.generated_node_count)
printed_str += "number of expanded nodes:{}\n".format(agent.expanded_node_count)
printed_str += "maximum number of nodes kept in memory:{}\n".format(agent.maximum_node_in_memory_count)
printed_str += "elapsed solve time:{}\n".format(elapsed_solve_time)
if (result == RESULT_PLAYER_WON):
printed_str += "WON\n"
else:
printed_str += "FAIL\n"
print(printed_str)
elif (player_string == "DSTAR"):
agent = DStarLiteAgent()
(collected_apple_count, elapsed_time_step, elapsed_solve_time, result) = hamham.start_level_computer(PLAYED_LEVEL, agent,
render=True, play_sound=True,
max_episode_length=MAX_EPISODE_LENGTH,
test=True)
printed_str = "--- D* Lite Agent Statistics ---\n"
printed_str += "elapsed time step:{}\n".format(elapsed_time_step)
#printed_str += "number of generated nodes:{}\n".format(agent.generated_node_count)
#printed_str += "number of expanded nodes:{}\n".format(agent.expanded_node_count)
#printed_str += "maximum number of nodes kept in memory:{}\n".format(agent.maximum_node_in_memory_count)
printed_str += "elapsed solve time:{}\n".format(elapsed_solve_time)
if (result == RESULT_PLAYER_WON):
printed_str += "WON\n"
else:
printed_str += "FAIL\n"
print(printed_str)