-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhuman_player.py
37 lines (30 loc) · 1.28 KB
/
human_player.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
"""This file gives the opportunity to play Qwixx as a human player; not a UI;
place where valid turns are 'translated' into a standardized format"""
from player import Player
class HumanPlayer(Player):
"""creates an environment for a human Player to play the game in conformity with the rules"""
def cross_passive(self, lst_eyes, valid_turns, completed_lines):
"""chooses one valid cross or skips"""
super().cross_passive(lst_eyes, valid_turns, completed_lines)
assert (self.ui is not None)
wish = self.ui.get_turn()
if wish != "skip":
return [wish]
return []
def cross_active(self, lst_eyes, valid_turns, completed_lines, turn_index):
"""chooses two valid crosses in succession; 2nd cross can be 'skip'"""
super().cross_active(lst_eyes, valid_turns, completed_lines)
assert (self.ui is not None)
# get 1st turn
while turn_index == 0:
wish = self.ui.get_turn()
# active player is not allowed to skip first cross
if wish == "skip":
self.inform_about_invalid_turn()
else:
return [wish]
# get 2nd turn
wish = self.ui.get_turn()
if wish != "skip":
return [wish]
return []