-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.py
133 lines (91 loc) · 3.83 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
119
120
121
122
123
124
125
126
127
128
129
130
131
from queue import PriorityQueue
from copy import deepcopy
EXIT_HEXES = {
'red' : [(3, -3), (3, -2), (3, -1), (3, 0)],
'green' : [(-3, 3), (-2, 3), (-1, 3), (0, 3)],
'blue' : [(0, -3), (-1, -2), (-2, -1), (-3, 0)]
}
INI_HEXES = {
'red' : [(-3, 3), (-3, 2), (-3, 1), (-3, 0)],
'green' : [(3, -3), (2, -3), (1, -3), (0, -3)],
'blue' : [(0, 3), (1, 2), (2, 1), (3, 0)]
}
MOVE = 'MOVE'
JUMP = 'JUMP'
EXIT = 'EXIT'
PASS = 'PASS'
SIZE = 3
class ExamplePlayer:
def __init__(self, colour):
"""
This method is called once at the beginning of the game to initialise
your player. You should use this opportunity to set up your own internal
representation of the game state, and any other information about the
game state you would like to maintain for the duration of the game.
The parameter colour will be a string representing the player your
program will play as (Red, Green or Blue). The value will be one of the
strings "red", "green", or "blue" correspondingly.
"""
self.colour = colour
self.hexes = {'red' : [(-3, 3), (-3, 2), (-3, 1), (-3, 0)],
'green' : [(3, -3), (2, -3), (1, -3), (0, -3)],
'blue' : [(0, 3), (1, 2), (2, 1), (3, 0)]}
self.exitHexes = EXIT_HEXES[colour]
# TODO: Set up state representation.
def action(self):
"""
This method is called at the beginning of each of your turns to request
a choice of action from your program.
Based on the current state of the game, your player should select and
return an allowed action to play on this turn. If there are no allowed
actions, your player must return a pass instead. The action (or pass)
must be represented based on the above instructions for representing
actions.
"""
# TODO: Decide what action to take.
def update(self, colour, action):
"""
This method is called at the end of every turn (including your player’s
turns) to inform your player about the most recent action. You should
use this opportunity to maintain your internal representation of the
game state and any other information about the game you are storing.
The parameter colour will be a string representing the player whose turn
it is (Red, Green or Blue). The value will be one of the strings "red",
"green", or "blue" correspondingly.
The parameter action is a representation of the most recent action (or
pass) conforming to the above in- structions for representing actions.
You may assume that action will always correspond to an allowed action
(or pass) for the player colour (your method does not need to validate
the action/pass against the game rules).
"""
# TODO: Update state representation in response to action.
(a, m) = action
if a in [MOVE, JUMP]:
opponent = self.hexes[colour]
print(self.hexes)
(s, e) = m
print(opponent)
print(s)
opponent.remove(s)
opponent.append(m)
if a == JUMP:
p = jump_piece(s, e)
delete(p, colour)
opponent.append(p)
self.hexes[colour] = sorted(opponent)
#...
elif a == EXIT:
self.hexes[colour].remove(m)
#...
def delete(self, piece, colour):
colour = None
keys = ['red', 'green', 'blue']
keys.remove(colour)
for k in keys:
if piece in self.hexes[k]:
self.hexes[k].remove(piece)
break
def jump_piece(start, end):
(s1, e1) = end
(s2, e2) = start
return ((s1+s2)/2 , (e1+e2)/2)