-
Notifications
You must be signed in to change notification settings - Fork 0
/
batch.py
65 lines (50 loc) · 1.76 KB
/
batch.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
"""
Batch program for the Cable Car game. The program can be run with one
command line argument which is the name of the config file.
Place this file in the same directory as cablecar.py
Author: Adam Oest (amo9149@rit.edu)
"""
import Engine
import time
import sys
from Engine.config import Config
def main():
"""Run the engine and start the game"""
sys.setcheckinterval(500)
if len(sys.argv) == 1:
sys.argv.append("cablecar.cfg")
wins = {}
scores = {}
games = abs(int(raw_input("Enter number of games: ")))
# Get config
cfg = Config(sys.argv[1])
cfg.data['UI'] = False
cfg.data['STDOUT_LOGGING'] = False
for game in xrange(1, games + 1):
startTime = time.clock()
winningPlayer, score, eliminated, moves = Engine.run(cfg)
endTime = time.clock()
if len(eliminated) > 0:
print "Players errored: %s" % eliminated
print "Game %s time: %s seconds" % (game, endTime - startTime)
if winningPlayer != []:
for player in winningPlayer:
if player not in wins.keys():
wins[player] = 1
scores[player] = [score[player]]
else:
wins[player] += 1
scores[player].append(score[player])
print "Player %s won the game with %s points!" % (winningPlayer, score)
else:
print "No winner."
for player,wins in wins.iteritems():
print "Player %s won %s times" % (player, wins)
score = 0
for num in scores[player]:
score += num
print "Total Score: %s" % score
if __name__ == "__main__":
main()
#import profile
#profile.run("main()")