-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.py
118 lines (102 loc) · 3.79 KB
/
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
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
109
110
111
112
113
114
115
116
117
118
# player.py
# Class definition for each player
from collections import OrderedDict
from copy import deepcopy
import random
class Player:
'''
An instance for each player
'''
def __init__(self, name):
self.name = name
self.starter = 0
self.next_round_starter = 0
self.score = 0
#self.filled_lines = 0
# Wall stored as an ordered dict
wall = [OrderedDict({'blue': 0, 'yellow': 0, 'red': 0, 'black': 0, 'white': 0}),
OrderedDict({'white': 0, 'blue': 0, 'yellow': 0, 'red': 0, 'black': 0}),
OrderedDict({'black': 0, 'white': 0, 'blue': 0, 'yellow': 0, 'red': 0}),
OrderedDict({'red': 0, 'black': 0, 'white': 0, 'blue': 0, 'yellow': 0}),
OrderedDict({'yellow': 0, 'red': 0, 'black': 0, 'white': 0, 'blue': 0})]
# Pattern Line as list of dicts containing color and count
pattern_lines = [{'color': 'none', 'count': 0},
{'color': 'none', 'count': 0},
{'color': 'none', 'count': 0},
{'color': 'none', 'count': 0},
{'color': 'none', 'count': 0}]
# Floor as list of None elements (no more than 7 elements allowed)
# Floor penalty as a list of associated penalties
floor = []
floor_penalty = [-1, -1, -2, -2, -2, -3, -3]
self.wall = wall
self.pattern_lines = pattern_lines
self.floor = floor
self.floor_penalty = floor_penalty
class AIPlayer(Player):
def pick_factory_or_center(self, choices):
picked = random.choice(choices)
picked = deepcopy(picked)
print(f"\n{self.name}'s choice is: {picked}", end='; ')
return picked
def pick_color(self, color_choices):
chosen_color = random.choice(color_choices)
print(f"the {chosen_color} tiles(s).\n")
return chosen_color
def pick_pattern_line(self, allowed_lines):
chosen_line = random.choice(allowed_lines)
return chosen_line
class HumanPlayer(Player):
def pick_factory_or_center(self, choices):
print("Your choices are:")
for i, x in enumerate(choices):
print(f"Choice number {i}: {x}")
choice = int(input("Enter choice number: "))
picked = choices[choice]
picked = deepcopy(picked)
print(f"You picked: {picked}")
return picked
def pick_color(self, color_choices):
print("And from these colored tiles:", color_choices)
chosen_color = input("Pick a color: ")
return chosen_color
def pick_pattern_line(self, allowed_lines):
print("Your pattern lines are:")
for i, x in enumerate(self.pattern_lines):
print(f"Pattern line {i+1}: {x}")
print(f"Allowed lines are ", end='')
print([x+1 for x in allowed_lines])
chosen_line = int(input("Pick from allowed line: ")) - 1
return chosen_line
def create_AI_players(num = 0):
'''
Initial AI player construction
'''
AI_players = []
if num >= 1:
AI_players.append(AIPlayer("Andrew"))
if num >= 2:
AI_players.append(AIPlayer("Bob"))
if num >= 3:
AI_players.append(AIPlayer("David"))
if num == 4:
AI_players.append(AIPlayer("John"))
return AI_players
def create_human_players(num = 0):
'''
Initial Human player construction
'''
human_players = []
for i in range(num):
print(f"Player {i+1}'s name: ", end='')
name = input()
human_players.append(HumanPlayer(name))
return human_players
def starting_player(players):
'''
Randomly choose the starting player,
and return the index of starting player
'''
x = random.randint(0, len(players)-1)
players[x].starter = 1
return x