This repository has been archived by the owner on Sep 15, 2022. It is now read-only.
forked from ASPP/pelita
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pelitagame.py
648 lines (546 loc) · 25.9 KB
/
pelitagame.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
import sys
import os.path
import inspect
import random
import string
import keyword
import logging
import subprocess
import time
import json
# silence stupid warnings from logging module
logging.root.manager.emittedNoHandlerWarning = 1
_logger = logging.getLogger("pelita.pelitagame")
try:
import argparse
except ImportError:
from pelita.compat import argparse
import pelita
class ReplayPublisher(object):
def __init__(self, publish_sock, replayfile):
with open(replayfile) as f:
self.old_game = f.read().split("\x04")
self.publisher = pelita.simplesetup.SimplePublisher(publish_sock)
def run(self):
for state in self.old_game:
if state:
message = {"__action__": "observe",
"__data__": json.loads(state)}
self.publisher._send(message)
class ResultPrinter(pelita.viewer.AbstractViewer):
def __init__(self, parseable_output):
self.parseable_output = parseable_output
def observe(self, universe, game_state):
self.print_bad_bot_status(universe, game_state)
if game_state["finished"]:
self.print_possible_winner(universe, game_state)
def print_bad_bot_status(self, universe, game_state):
for bot_id, reason in game_state["bot_error"].iteritems():
if reason == "timeout":
sys.stderr.write("Timeout #%r for team %r (bot index %r).\n" % (
game_state["timeout_teams"][universe.bots[bot_id].team_index],
universe.bots[bot_id].team_index,
bot_id))
else:
sys.stderr.write("Problem for team %r (bot index %r) (%s).\n" % (
universe.bots[bot_id].team_index,
bot_id,
reason))
for team_id, reason in enumerate(game_state["teams_disqualified"]):
if reason == "timeout":
sys.stderr.write("Team %r had too many timeouts. Team disqualified.\n" % team_id)
elif reason == "disconnected":
sys.stderr.write("Team %r disconnected. Team disqualified.\n" % team_id)
elif reason is not None:
sys.stderr.write("Team %r disqualified (%r).\n" % (team_id, reason))
def print_possible_winner(self, universe, game_state):
""" Checks the event list for a potential winner and prints this information.
This is needed for scripts parsing the output.
"""
winning_team = game_state.get("team_wins")
if winning_team is not None:
winner = universe.teams[winning_team]
loser = universe.enemy_team(winning_team)
msg = "Finished. '%s' won over '%s'. (%r:%r)" % (
winner.name, loser.name,
winner.score, loser.score
)
if self.parseable_output:
msg += '\n' + str(winner.index)
sys.stdout.flush()
elif game_state.get("game_draw") is not None:
t0 = universe.teams[0]
t1 = universe.teams[1]
msg = "Finished. '%s' and '%s' had a draw. (%r:%r)" % (
t0.name, t1.name,
t0.score, t1.score
)
if self.parseable_output:
msg += "\n-"
else:
return
print msg
# We must manually flush, else our forceful stopping of Tk
# won't let us pipe it.
sys.stdout.flush()
def get_python_process():
py_proc = sys.executable
if not py_proc:
raise RuntimeError("Cannot retrieve current Python executable.")
return py_proc
def run_external_viewer(subscribe_sock, controller, geometry, delay):
# Something on OS X prevents Tk from running in a forked process.
# Therefore we cannot use multiprocessing here. subprocess works, though.
viewer_args = [ str(subscribe_sock) ]
if controller:
viewer_args += ["--controller-address", str(controller)]
if geometry:
viewer_args += ["--geometry", "{0}x{1}".format(*geometry)]
if delay:
viewer_args += ["--delay", str(delay)]
tkviewer = os.path.join(os.path.dirname(sys.argv[0]), "tkviewer.py")
return subprocess.Popen([get_python_process(), tkviewer] + viewer_args)
def call_standalone_pelitagame(team_spec, addr):
""" Starts another process with the same Python executable,
the same start script (pelitagame) and runs `team_spec`
as a standalone client on URL `addr`.
"""
return subprocess.Popen([get_python_process(),
sys.argv[0],
"--standalone-client",
team_spec,
addr])
def check_module(filepath):
"Throws an ValueError is the specified path is neither a module nor a package."
if not os.path.exists(filepath):
raise ValueError("'%s' doesn't exist" % filepath)
allowed = string.letters + string.digits + '_'
if filepath.endswith('.py'):
valid = os.path.isfile(filepath)
modname = os.path.basename(filepath[:-3])
else:
initpy = os.path.join(filepath, '__init__.py')
valid = os.path.isdir(filepath) and os.path.isfile(initpy)
modname = os.path.basename(filepath.rstrip(os.path.sep))
if (set(modname) - set(allowed) or
modname[0] in string.digits or
modname in keyword.kwlist or
modname.startswith('__')):
raise ValueError("invalid module name: '%s'" % modname)
if not valid:
raise ValueError("'%s': neither a module nor a package" % filepath)
def load_factory(filespec):
filename, _, factory_name = filespec.partition(':')
check_module(filename)
filename = filename.rstrip(os.path.sep)
dirname = os.path.dirname(filename)
modname = os.path.splitext(os.path.basename(filename))[0]
factory_name = factory_name or 'factory'
with pelita.utils.with_sys_path(dirname):
module = __import__(modname, fromlist=[factory_name])
return getattr(module, factory_name)
def import_builtin_player(name):
with pelita.utils.with_sys_path("./"):
players_module = __import__("players")
sane_players = dict((p.__name__, p) for p in players_module.SANE_PLAYERS)
if name == 'random':
player = random.choice(sane_players.values())
print 'Choosing %s for random player' % player
else:
player = sane_players.get(name)
if not player:
try:
# fallback to player in pelita.player
player = getattr(pelita.player, name)
except AttributeError:
others = ', '.join(sane_players.keys())
msg = 'Failed to find %s in players. (Available players are: %s).' % (name, others)
raise ImportError(msg)
if inspect.isclass(player) and issubclass(player, pelita.player.AbstractPlayer):
return player
else:
raise ImportError("%r is not a valid player." % player)
def create_builtin_team(spec):
names = spec.split(',')
if len(names) == 1:
names *= 2
elif len(names) > 2:
raise ValueError('need two comma separated names')
players = [import_builtin_player(name)() for name in names]
teamname = 'The %ss' % players[0].__class__.__name__
return pelita.player.SimpleTeam(teamname, *players)
def check_team_name(name):
# Team name must be ascii
try:
name.encode('ascii')
except UnicodeDecodeError:
raise ValueError('Invalid team name (non ascii): "%s".' % name)
# Team name must be shorter than 25 characters
if len(name) > 25:
raise ValueError('Invalid team name (longer than 25): "%s".' % name)
if len(name) == 0:
raise ValueError('Invalid team name (too short).')
# Check every character and make sure it is either
# a letter or a number. Nothing else is allowed.
for char in name:
if (not char.isalnum()) and (char != ' '):
raise ValueError('Invalid team name (only alphanumeric '
'chars or blanks): "%s"' % name)
if name.isspace():
raise ValueError('Invalid team name (no letters): "%s"' % name)
def load_team(spec):
try:
if os.path.sep in spec or spec.endswith('.py') or os.path.exists(spec):
team = load_factory(spec)()
else:
team = create_builtin_team(spec)
check_team_name(team.team_name)
return team
except (ValueError, AttributeError, IOError, ImportError) as e:
print >> sys.stderr, "failure while loading team '%s'" % spec
print >> sys.stderr, 'ERROR: %s' % e
raise
def prepare_team(team_spec, standalone=False):
# check if we've been given an address which a remote
# player wants to connect to
if standalone:
addrs = "tcp://*"
team = None
else:
if "://" in team_spec:
addrs = team_spec
team = None
else:
addrs = "tcp://*"
team = load_team(team_spec) or sys.exit(1)
return addrs, team
def start_logging(filename):
hdlr = logging.FileHandler(filename, mode='w')
logger = logging.getLogger('pelita')
FORMAT = \
'[%(relativeCreated)06d %(name)s:%(levelname).1s][%(funcName)s] %(message)s'
formatter = logging.Formatter(FORMAT)
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
logger.setLevel(logging.DEBUG)
def geometry_string(s):
"""Get a X-style geometry definition and return a tuple.
600x400 -> (600,400)
"""
try:
x_string, y_string = s.split('x')
geometry = (int(x_string), int(y_string))
except ValueError:
msg = "%s is not a valid geometry specification" % s
raise argparse.ArgumentTypeError(msg)
return geometry
parser = argparse.ArgumentParser(description='Run a single pelita game',
add_help=False,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser._positionals = parser.add_argument_group('Arguments')
parser.add_argument('spec_left', help='team on the left side (default: random)', nargs='?',
default=None)
parser.add_argument('spec_right', help='team on the right side (default: random)', nargs='?',
default=None)
parser._optionals = parser.add_argument_group('Options')
parser.add_argument('--help', '-h', help='show this help message and exit',
action='store_const', const=True)
parser.add_argument('--version', help='show the version number and exit',
action='store_const', const=True)
parser.add_argument('--log', help='print debugging log information to'
' LOGFILE (default \'pelita.log\')',
metavar='LOGFILE', default=argparse.SUPPRESS, nargs='?')
parser.add_argument('--dump', help='print game dumps to file (will be overwritten)'
' DUMPFILE (default \'pelita.dump\')',
metavar='DUMPFILE', default=argparse.SUPPRESS, nargs='?')
parser.add_argument('--replay', help='replay a dumped game'
' DUMPFILE (default \'pelita.dump\')',
metavar='DUMPFILE', default=argparse.SUPPRESS, nargs='?')
parser.add_argument('--rounds', type=int, default=300,
help='maximum number of rounds to play')
parser.add_argument('--fps', type=float, default=40,
help='(approximate) number of frames per second in a graphical viewer')
parser.add_argument('--seed', type=int, metavar='SEED', default=None,
help='fix random seed')
parser.add_argument('--geometry', type=geometry_string, metavar='NxM',
help='initial size of the game window')
parser.add_argument('--dry-run', const=True, action='store_const',
help='load players but do not actually play the game')
parser.add_argument('--max-timeouts', type=int, default=5,
dest='max_timeouts', help='maximum number of timeouts allowed (default: 5)')
parser.add_argument('--parseable-output', action="store_const", const=True,
help='Make game result parseable')
parser.add_argument('--list-teams', action="store_const", const=True,
help='Print the names of the included default teams.')
parser.add_argument('--check-team', action="store_const", const=True,
help='Check that the team is valid (on first sight) and print its name.')
timeout_opt = parser.add_mutually_exclusive_group()
timeout_opt.add_argument('--timeout', type=float, metavar="SEC",
dest='timeout_length', help='time before timeout is triggered (default: 3 seconds)')
timeout_opt.add_argument('--no-timeout', const=None, action='store_const',
dest='timeout_length', help='run game with no timeouts')
parser.set_defaults(timeout_length=3)
publisher_opt = parser.add_mutually_exclusive_group()
publisher_opt.add_argument('--publish', type=str, metavar='URL',
dest='publish_to', help='publish to this zmq socket')
publisher_opt.add_argument('--no-publish', const=False, action='store_const',
dest='publish_to', help='do not publish')
parser.set_defaults(publish_to="tcp://*:*")
controller_opt = parser.add_argument_group("Controller")
controller_opt.add_argument('--controller', type=str, metavar='URL', default="tcp://*:*",
help='open a controller on this zmq socket')
controller_opt.add_argument('--external-controller', const=True, action='store_const',
help='force control by an external controller')
viewer_opt = parser.add_mutually_exclusive_group()
viewer_opt.add_argument('--ascii', action='store_const', const='ascii',
dest='viewer', help='use the ASCII viewer')
viewer_opt.add_argument('--null', action='store_const', const='null',
dest='viewer', help='use the /dev/null viewer')
viewer_opt.add_argument('--progress', action='store_const', const='progress',
dest='viewer', help='use the progress viewer')
viewer_opt.add_argument('--tk', action='store_const', const='tk',
dest='viewer', help='use the tk viewer (default)')
viewer_opt.add_argument('--tk-no-sync', action='store_const', const='tk-no-sync',
dest='viewer', help='use the unsynchronised tk viewer')
parser.set_defaults(viewer='tk')
layout_opt = parser.add_mutually_exclusive_group()
layout_opt.add_argument('--layoutfile', metavar='FILE',
help='load a maze layout from FILE')
layout_opt.add_argument('--layout', metavar='NAME',
help="load a maze layout by name. If NAME is"
" 'list' return a list of available names")
layout_opt.add_argument('--filter', metavar='STRING',
default='normal_without_dead_ends',
help='retrict the pool of random layouts to those whose'
' name contains STRING.'
' Default: \'normal_without_dead_ends\'')
client_opt = parser.add_mutually_exclusive_group()
client_opt.add_argument('--standalone-client', action='store_true',
help='run standalone game')
client_opt.add_argument('--standalone-left', action='store_true',
help='run standalone game for the left team')
client_opt.add_argument('--standalone-right', action='store_true',
help='run standalone game for the right team')
parser.epilog = """\
Team Specification:
- Using predefined players:
A single name (e.g. 'NQRandomPlayer') in which case the team is
composed of players of this type, or a comma separated list of
player types (e.g. 'BFSPlayer,BasicDefensePlayer'). Example usage:
$ %(prog)s BFSPlayer,RandomPlayer NQRandomPlayer,BasicDefensePlayer
Use --list-teams to get a list of predefined players.
- Using custom players (filename):
The name of a python file (e.g. '~/my_player.py') which defines
a function named 'factory' (you can change the name of the factory
function by adding ':my_factory' to the filename). The factory
function must take no arguments and return an instance of
pelita.player.SimpleTeam.
Example implementation:
def factory():
return pelita.player.SimpleTeam("My Team", MyPlayer1(), MyPlayer2())
Example usage:
$ %(prog)s ~/my_player.py NQRandomPlayer,BasicDefensePlayer
Example of custom factory function:
$ %(prog)s ~/my_player.py:my_factory NQRandomPlayer,BasicDefensePlayer
- Using custom players (package):
The name of a python package (i.e. a directory with an __init__.py file),
which exposes a function named 'factory' (see above for more details).
Example usage:
$ %(prog)s my_player NQRandomPlayer,BasicDefensePlayer
- Using custom players (simpleclient):
The address the server should bind on and wait for a client
to connect to.
Example of a server binding the left team to 'tcp://*:9005' and
the right team to 'ipc:///tmp/mysocket':
$ %(prog)s tcp://*:9005 ipc:///tmp/mysocket
Example of a server binding the left team to 'tcp://*:9005' and
using a built-in Player as the right team:
$ %(prog)s tcp://*:9005 NQRandomPlayer,BasicDefensePlayer
Standalone mode:
When --standalone-client is specified, the first positional argument
is taken as a team specification, whereas the second positional argument
is used to specify the address where the Player should connect to.
The user code then runs in the main thread of the process and as such
may be interrupted with the Python debugger pdb. (For best results,
it may be necessary to increase (or turn off) the timeout in the server.
Example usage. A server bound to two different ports:
$ %(prog)s tcp://*:51025 tcp://*:51027
Now we can start two clients connected to their respective sockets:
$ %(prog)s --standalone-client BFSPlayer,RandomPlayer tcp://localhost:51025
$ %(prog)s --standalone-client ~/my_player.py tcp://localhost:51027
A much simpler way, which avoids both the need to specify an available port
and to manually open up a new process is provided by the --standalone-left and
--standalone-right arguments. The following line automatically runs
the left team in standalone mode where it is possible to intercept with
the Python debugger. (Provided this is included in the code.)
$ %(prog)s --standalone-left --no-timeout DebuggablePlayer,MyTestPlayer \
BFSPlayer,RandomPlayer
Layout specification:
If neither --layoutfile nor --layout are specified, the maze is
chosen at random from the pool of available layouts.
You can restrict this pool by using --filter.
"""
def run_game():
config = {
"publish-addr": None,
"controller-addr": None,
}
args = parser.parse_args()
if args.help:
parser.print_help()
sys.exit(0)
if args.version:
print "Pelita %s" % pelita.version
sys.exit(0)
if args.layout == 'list':
layouts = pelita.layout.get_available_layouts()
print '\n'.join(layouts)
sys.exit(0)
if args.seed is not None:
random.seed(args.seed)
if args.viewer.startswith('tk') and not args.publish_to:
raise ValueError("Options --tk (or --tk-no-sync) and --no-publish are mutually exclusive.")
try:
start_logging(args.log or 'pelita.log')
except AttributeError:
pass
if args.list_teams:
print '\n'.join(PLAYERS)
sys.exit(0)
if args.check_team:
if not args.spec_left:
raise ValueError("No team specified.")
# only print the team name.
print load_team(args.spec_left).team_name
sys.exit(0)
def print_team_info(addr, team, spec, info):
if team is not None:
print "Using factory '%s' -> '%s' (%s)" % (spec, team.team_name, info)
elif "://" in addr:
print "Waiting for %s team on %s" % (info, addr)
# if standalone_client was specified,
# we use the following scheme
# the first positional argument specifies the team to load
# the second positional argument specifies the address to connect to
if args.standalone_client:
team = load_team(args.spec_left)
addr = args.spec_right.replace('*', 'localhost')
print_team_info(None, team, args.spec_left, "standalone")
client = pelita.simplesetup.SimpleClient(team, address=addr)
sys.exit(client.run())
try:
# TODO: Re-include the dump.
dump = args.dump or 'pelita.dump'
except AttributeError:
dump = None
try:
replayfile = args.replay or 'pelita.dump'
except AttributeError:
replayfile = None
external_players = []
external_viewers = []
if replayfile:
replay_publisher = ReplayPublisher(args.publish_to, replayfile)
config["publish-addr"] = replay_publisher.publisher.socket_addr
subscribe_sock = replay_publisher.publisher.socket_addr.replace('*', 'localhost')
if args.viewer.startswith("tk"):
args.viewer = "tk-no-sync"
runner = replay_publisher.run
else:
if args.layout or args.layoutfile:
layout_name, layout_string = pelita.layout.load_layout(layout_name=args.layout, layout_file=args.layoutfile)
else:
layout_name, layout_string = pelita.layout.get_random_layout(args.filter)
print "Using layout '%s'" % layout_name
if not args.spec_left:
args.spec_left = "random"
if not args.spec_right:
args.spec_right = "random"
addrs_left, team_left = prepare_team(args.spec_left, args.standalone_left)
addrs_right, team_right = prepare_team(args.spec_right, args.standalone_right)
if args.dry_run:
sys.exit(0)
if args.viewer == 'tk-no-sync':
# only use delay when not synced.
initial_delay = 0.5
else:
initial_delay = 0.0
server = pelita.simplesetup.SimpleServer(layout_string=layout_string,
rounds=args.rounds,
bind_addrs=(addrs_left, addrs_right),
initial_delay=initial_delay,
max_timeouts=args.max_timeouts,
timeout_length=args.timeout_length,
layout_name=layout_name,
seed=args.seed)
player_clients = []
for (addr, team) in zip(server.bind_addresses, [team_left, team_right]):
if team:
addr = addr.replace('*', 'localhost')
client = pelita.simplesetup.SimpleClient(team, address=addr)
player_clients.append(client)
for client in player_clients:
proc = client.autoplay_process()
external_players.append(proc)
print_team_info(addrs_left, team_left, args.spec_left, "left")
print_team_info(addrs_right, team_right, args.spec_right, "right")
if args.standalone_left:
sub = call_standalone_pelitagame(args.spec_left, server.bind_addresses[0])
if args.standalone_right:
sub = call_standalone_pelitagame(args.spec_right, server.bind_addresses[1])
# register the viewers
if args.publish_to:
publisher = pelita.simplesetup.SimplePublisher(args.publish_to)
config["publish-addr"] = publisher.socket_addr
print "Publishing to %s" % publisher.socket_addr
server.game_master.register_viewer(publisher)
if dump:
server.game_master.register_viewer(pelita.viewer.DumpingViewer(open(dump, "w")))
if args.viewer == 'ascii':
server.game_master.register_viewer(pelita.viewer.AsciiViewer())
if args.viewer == 'progress':
server.game_master.register_viewer(pelita.viewer.ProgressViewer())
if args.viewer == 'null':
pass
# Adding the result printer to the viewers.
server.game_master.register_viewer(ResultPrinter(args.parseable_output))
if args.viewer == 'tk' or args.external_controller:
server.register_teams()
controller = pelita.simplesetup.SimpleController(server.game_master, args.controller)
print "Controller listening on %s" % controller.socket_addr
config["controller-addr"] = controller.socket_addr
def runner():
controller.run()
server.exit_teams()
else:
def runner():
server.run()
if args.viewer.startswith('tk'):
# Something on OS X prevents Tk from running in a forked process.
# Therefore we cannot use multiprocessing here. subprocess works, though.
delay = int(1000. / args.fps)
if args.viewer == 'tk':
sync_address_tk = config["controller-addr"].replace('*', 'localhost')
else:
sync_address_tk = None
subscribe_sock = config["publish-addr"].replace('*', 'localhost')
tkprocess = run_external_viewer(subscribe_sock, sync_address_tk, args.geometry, delay)
external_viewers.append(tkprocess)
if not sync_address_tk:
time.sleep(0.5)
try:
runner()
except KeyboardInterrupt:
for external_viewer in external_viewers:
external_viewer.kill()
finally:
# kill all client processes. NOW!
# (is this too early?)
for external_player in external_players:
_logger.debug("Attempting to terminate %r.", external_player)
external_player.terminate()
for external_player in external_players:
external_player.join()
_logger.debug("%r terminated.", external_player)
if __name__ == '__main__':
run_game()