-
Notifications
You must be signed in to change notification settings - Fork 2
/
MyBot.py
44 lines (40 loc) · 1.25 KB
/
MyBot.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
import logging
log = logging.getLogger('aipybucuresti')
log.setLevel(100) # disabled by default
def main():
import itertools
from PlanetWars import PlanetWars
from strategy import DoTurn
map_data = ''
turn_counter = itertools.count(1)
while True:
current_line = raw_input()
if len(current_line) >= 2 and current_line.startswith("go"):
turn = turn_counter.next()
pw = PlanetWars(map_data)
log.debug("===== turn %3d =====", turn)
DoTurn(log, pw)
pw.FinishTurn()
map_data = ''
else:
map_data += current_line + '\n'
if __name__ == '__main__':
import sys
if sys.argv[-1] == '--debug':
import os
log.setLevel(logging.DEBUG)
log_path = os.path.join(os.path.dirname(__file__), 'ai.log')
if os.path.isfile(log_path): os.unlink(log_path)
log.addHandler(logging.FileHandler(log_path))
try:
import psyco
psyco.full()
except ImportError:
pass
try:
try:
main()
except:
log.exception("=======================================")
except KeyboardInterrupt:
print 'ctrl-c, leaving ...'