-
Notifications
You must be signed in to change notification settings - Fork 0
/
kingdom.py
41 lines (36 loc) · 1.06 KB
/
kingdom.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
"""python kingdom.py FILE.
This script is for handling specialized kingdom input files. The format for the input file is the
following:
'Number of cases'
'String grid height'
'String grid width'
'String grid'
...
...
...
"""
import sys
import argparse
import core
PARSER = argparse.ArgumentParser()
PARSER.add_argument('filename')
ARGS = PARSER.parse_args()
with open(ARGS.filename) as f:
CASE_COUNT = f.readline().strip('\n')
for case in xrange(int(CASE_COUNT)):
sys.stdout.write('Case ')
sys.stdout.write(str(case + 1))
sys.stdout.write(':\n')
grid = []
grid_height_limit = int(f.readline().strip('\n'))
grid_width = int(f.readline().strip('\n'))
for _ in xrange(grid_height_limit):
grid += [f.readline().strip('\n')]
solver = core.KingdomSolver(grid)
contested_ = solver.contested()[0]
for key, value in solver.map_army_count():
print key, value
if contested_ != 0:
sys.stdout.write('contested ')
print contested_
sys.stdout.flush()