-
Notifications
You must be signed in to change notification settings - Fork 0
/
ai.py
31 lines (28 loc) · 759 Bytes
/
ai.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
#!/usr/bin/env python
import logging
import heapq
import random
import time
import berlin
def move_at_random(game):
'''
stupid random AI
'''
res = berlin.Response()
for n in game.m.nodes.values():
if n.owner == game.myself and n.units > 0:
moves = {}
neighbours = []
for i in n.edges:
neighbours.append(i)
moves[i] = 0
for i in range(n.units):
dest_index = random.randint(0,len(neighbours))
if dest_index == len(neighbours):
# stand your ground
continue
moves[neighbours[dest_index]] += 1
for dest, units in moves.items():
logging.debug("moving %d units from %d to %d" % (units, n.id, dest))
res.add_move(n.id, dest, units)
return res