-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
108 lines (100 loc) · 3.76 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import random
from src.game import Game
import time
flag = False
def initializer(game: Game):
strategic_nodes = game.get_strategic_nodes()['strategic_nodes']
score = game.get_strategic_nodes()['score']
strategic_nodes = list(zip(strategic_nodes, score))
strategic_nodes.sort(key=lambda x: x[1], reverse=True)
strategic_nodes, score = list(zip(*strategic_nodes))
print(game.get_turn_number())
owner = game.get_owners()
for i in strategic_nodes:
if owner[str(i)] == -1:
print(game.put_one_troop(i), "-- putting one troop on", i)
game.next_state()
return
adj = game.get_adj()
for i in strategic_nodes:
for j in adj[str(i)]:
if owner[str(j)] == -1:
print(game.put_one_troop(j), "-- putting one troop on neighbor of strategic node", j)
game.next_state()
return
my_id = game.get_player_id()['player_id']
nodes = []
nodes.extend([i for i in strategic_nodes if owner[str(i)] == my_id])
for i in strategic_nodes:
for j in adj[str(i)]:
if owner[str(j)] == my_id:
nodes.append(j)
nodes = list(set(nodes))
node = random.choice(nodes)
game.put_one_troop(node)
game.next_state()
print("3- putting one troop on", node)
def turn(game):
global flag
game.printer("test\n")
owner = game.get_owners()
for i in owner.keys():
if owner[str(i)] == -1 and game.get_number_of_troops_to_put()['number_of_troops'] > 1:
print(game.put_troop(i, 1))
list_of_my_nodes = []
for i in owner.keys():
if owner[str(i)] == game.get_player_id()['player_id']:
list_of_my_nodes.append(i)
print(game.put_troop(random.choice(list_of_my_nodes), game.get_number_of_troops_to_put()['number_of_troops']))
print(game.get_number_of_troops_to_put())
print(game.next_state())
# find the node with the most troops that I own
max_troops = 0
max_node = -1
owner = game.get_owners()
for i in owner.keys():
if owner[str(i)] == game.get_player_id()['player_id']:
if game.get_number_of_troops()[i] > max_troops:
max_troops = game.get_number_of_troops()[i]
max_node = i
# find a neighbor of that node that I don't own
adj = game.get_adj()
for i in adj[max_node]:
if owner[str(i)] != game.get_player_id()['player_id'] and owner[str(i)] != -1:
print(game.attack(max_node, i, 1, 0.9999999))
break
print(game.next_state())
print(game.get_state())
# get the node with the most troops that I own
max_troops = 0
max_node = -1
owner = game.get_owners()
for i in owner.keys():
if owner[str(i)] == game.get_player_id()['player_id']:
if game.get_number_of_troops()[i] > max_troops:
max_troops = game.get_number_of_troops()[i]
max_node = i
print(game.get_reachable(max_node))
x = game.get_reachable(max_node)['reachable']
try:
x.remove(int(max_node))
except:
print(x, max_node)
if len(x) > 0:
destination = random.choice(x)
print(game.move_troop(max_node, destination, 1))
print(game.next_state())
if flag == False:
max_troops = 0
max_node = -1
owner = game.get_owners()
for i in owner.keys():
if owner[str(i)] == game.get_player_id()['player_id']:
if game.get_number_of_troops()[i] > max_troops:
max_troops = game.get_number_of_troops()[i]
max_node = i
print(game.get_number_of_troops()[str(max_node)])
print(game.fort(max_node, 3))
print(game.get_number_of_fort_troops())
flag = True
game.next_state()