Menu

[f55325]: / run.py  Maximize  Restore  History

Download this file

83 lines (70 with data), 2.7 kB

 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
# Python Fights online AI creation game
# Copyright (C) 2009 Maxim Sloyko
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#!/usr/bin/python
from optparse import OptionParser
import cProfile
from core import *
from serialize import serializer
parser = OptionParser()
parser.add_option('-o', '--output',
dest = 'output',
default = 'results.prof',
metavar = 'FILENAME',
help = 'Where to write profiler\'s logs')
parser.add_option('-r', '--round-count',
dest = 'rounds',
type = 'int',
default = 20,
metavar = 'NUMBER',
help = 'Number of rounds to play')
parser.add_option('-n', '--game-count',
dest = 'games',
type = 'int',
default = 1,
metavar = 'NUMBER',
help = 'Number of games to play')
opt, args = parser.parse_args()
def main():
py1 = Python('First')
mslot1 = MemorySlot(py1)
mslot1.set_cell(3, 3, MemoryCell(kind = MC_OWN_HEAD))
mslot1.set_cell(3, 2, MemoryCell(kind = MC_ENEMY_TAIL))
mslot = MemorySlot(py1)
mslot.set_cell(3, 3, MemoryCell(kind = MC_OWN_HEAD))
mslot.set_cell(3, 2, MemoryCell(kind = MC_ENEMY_TAIL, trait = MCT_OR))
mslot.set_cell(3, 1, MemoryCell(kind = MC_ENEMY_TAIL, trait = MCT_OR))
mslot.set_cell(3, 0, MemoryCell(kind = MC_ENEMY_TAIL, trait = MCT_OR))
mslot.set_cell(4, 1, MemoryCell(kind = MC_ENEMY_TAIL, trait = MCT_OR))
mslot.set_cell(4, 0, MemoryCell(kind = MC_ENEMY_TAIL, trait = MCT_OR))
mslot.set_cell(5, 0, MemoryCell(kind = MC_ENEMY_TAIL, trait = MCT_OR))
py1.memslot_list = [mslot1, mslot]
py2 = Python('Second')
py3 = Python('Third')
for i in range(opt.games):
g = Game([py1, py2, py3], round_num = opt.rounds)
g.play()
#moves = b.play()
print "Score:"
for py, score in g.get_score().iteritems():
print '%s: %s' % (py.name, score)
print serializer.save_game(g)
#print "Moves:"
#nmame_map = {MOVE_NORTH: 'N', MOVE_WEST: 'W', MOVE_EAST: 'E', MOVE_SOUTH: 'S'}
#print ''.join([nmame_map.get(m, '-') for m in moves])
if opt.output:
cProfile.run('main()', opt.output)
else:
main()