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
#!/usr/bin/python3
 
# SI 335 Algorithms, Spring 2016
# Project 3 Helper code
#
# This program scores the given map and moves, without actually
# displaying everything.
 
import argparse
import sys
import curses
import time
import collections
 
from show import World, read_moves
 
def main():
    # parse command-line arguments
    parser = argparse.ArgumentParser(description="Compute score for given moves in given map")
    parser.add_argument("mapfile", type=argparse.FileType('r'),
            help="filename of the map")
    parser.add_argument("movesfile", type=argparse.FileType('r'), 
            help="filename of the moves")
    args = parser.parse_args()
 
    # read in the map
    world = World(args.mapfile)
    
    # read in moves
    moves = read_moves(args.movesfile, world.nasset)
 
    # calculate the score
    for move in moves:
        if not world.active(): break
        msgs, status = world.move(move)
        for msg in msgs:
            print(msg, file=sys.stderr)
 
    remasset = len(world.assets) - len(world.dead)
    remtarg = len(world.targets)
 
    if remasset:
        print("Finished with {} assets remaining".format(remasset), file=sys.stderr)
    else:
        print("All assets were lost", file=sys.stderr)
    
    if remtarg:
        print("Finished with {} targets remaining".format(remtarg), file=sys.stderr)
    else:
        print("All targets were successfully destroyed", file=sys.stderr)
 
    print(world.score)
 
if __name__ == '__main__':
    main()