-
Notifications
You must be signed in to change notification settings - Fork 3
/
play.py
77 lines (65 loc) · 2.95 KB
/
play.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
import os
import sys
from argparse import ArgumentParser
from agent import RandomAgent
from agent import HumanAgent
from driver import GameDriver
from utils import InvalidMapError
MAP_TYPES = ['ascii', 'emoji']
def main(args):
parser = ArgumentParser(description='')
parser.add_argument('--height', type=int, required=True,
help='Heigth of the map')
parser.add_argument('--width', type=int, required=True,
help='Width of the map')
parser.add_argument('--num-powerups', type=int, required=True,
help='Number of powerups to put in the game map')
parser.add_argument('--num-monsters', type=int, required=True,
help='Number of monsters to put in the game map')
parser.add_argument('--num-dynamic-monsters', type=int, required=True,
help='Number of dynamic monsters to put in the game')
parser.add_argument('--initial-strength', default=100, type=int,
help='Initial strength of each agent')
parser.add_argument('--save-dir', type=str,
help='Save directory for saving the map')
parser.add_argument('--map-file', type=str,
help='Path to the map JSON file')
parser.add_argument('--play-against-human', action='store_true',
help='Whether to have a Human player as one of the '
'agents in the game')
parser.add_argument('--show-map', action='store_true',
help='Whether to display the map in the terminal')
parser.add_argument('--map-type', choices=MAP_TYPES, default='ascii',
help='Select map type. Choices are {' +
', '.join(MAP_TYPES) + '}')
parser.add_argument('--verbose', action='store_true',
help='Whether to be verbose when playing game')
args = parser.parse_args(args)
# TODO: Change how agents are populated
agent = RandomAgent(args.height, args.width, args.initial_strength)
agents = [agent]
if args.play_against_human:
human = HumanAgent(args.height, args.width, args.initial_strength)
agents.append(human)
try:
game_driver = GameDriver(
height=args.height, width=args.width,
num_powerups=args.num_powerups,
num_monsters=args.num_monsters,
num_dynamic_monsters=args.num_dynamic_monsters,
agents=agents,
initial_strength=args.initial_strength,
show_map=args.show_map, map_type=args.map_type,
save_dir=args.save_dir, map_file=args.map_file)
except InvalidMapError as e:
print('The game map could not be created!')
print(e)
print('Restart the game')
print('Starting game')
try:
game_driver.play(verbose=args.verbose)
except StopIteration as e:
print(e)
return
if __name__ == '__main__':
main(sys.argv[1:])