-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
59 lines (45 loc) · 1.09 KB
/
main.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
NUM_OF_BOTS = 2
NUM_OF_TURNS=1000
matrix = None
import sys
from bot import Bot
def init_matrix(matrix,width,hight):
matrix = [[None]*width]*hight
return matrix
def get_player_bots():
'''gets the player bots do_turn function. returns array with the functions and the player instanse
[(mybot1,032940528),(mybot2,032940528)]
'''
if len(sys.argv) != (NUM_OF_BOTS+1):
raise Exception("requerie at least " + NUM_OF_BOTS + " bots")
botsNames = sys.argv[1:]
bots = (Bot(botName) for botName in botsNames)
bots = [(bot , bot.do_turn) for bot in bots]
return bots
def main():
init_matrix(matrix)
bots= get_player_bots()
winner=None
#turn loop
for turn in range(NUM_OF_TURNS):
#win check
if len(bots)==1:
winner= bots[0][0]
break
elif len(bots)<1:
winner="nobody"
break
#bot loop
for (owner ,do_turn) in bots:
#points check
if owner.points >=1000:
winner=owner
try:
do_turn()
except:
debug( str(owner) + " loses - illigal execution" )
bots.remove((owner ,do_turn))
#winner check
if winner != None:
break
print(str(winner)+" wins!")