-
Notifications
You must be signed in to change notification settings - Fork 1
/
guess.py
38 lines (32 loc) · 1.26 KB
/
guess.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
""" Stupid AI. Just place track randomly """
import random
from template import Template
from state import SELECT, ALL
def create():
""" Return an AI """
return Guess()
class Guess(Template):
""" A class to hold the stupidest AI algorithm """
def start(self, num, player_count, board, hand):
""" Construct a random AI """
super().start(num, player_count, board, hand)
return ALL
def place_hub(self, board, state): # pylint: disable=W0613
""" Return where we want out hub """
while self.hub is None:
row = random.randint(1, board.rows - 1)
col = random.randint(1, board.cols - 1)
self.hub = (row, col)
for ocean in board.oceans:
if row == ocean[0] and col == ocean[1]:
self.hub = None
if self.hub is not None:
return self.hub
def move(self, board, tracks_left, state):
""" Figure out our move """
if state.desired_states & SELECT:
possible_moves = list(state.fast_get_moves(self.hub, tracks_left))
else:
possible_moves = list(state.legal_moves(self.num, 1, tracks_left))
move = random.randint(0, len(possible_moves) - 1)
return possible_moves[move]