-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.py
81 lines (62 loc) · 2.67 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
import pygame
class Player:
def __init__(self, enviroment):
self.game = enviroment.game
self.enviroment = enviroment
self.playing = True
class Player_3moves(Player):
def __init__(self, enviroment):
super().__init__(enviroment)
def move(self):
self.playing = True
finished = False
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.playing = False
if event.type == pygame.MOUSEBUTTONDOWN:
# finished buttons
if self.enviroment.activate_finished_buttons:
for b in self.enviroment.buttons:
if self.enviroment.cursor.colliderect(b.rectangle):
b.command()
break
# play
if self.game.count_chips() < 3:
for i in range(3):
for j in range(3):
box = self.enviroment.boxes[j][i] # TRANSPOSE !! ------------------
if self.enviroment.cursor.colliderect(box.rectangle) and self.game.board[i][j] == 0:
action = 3*i+j
finished = self.game.make_move(action)
else:
for i in range(3):
for j in range(3):
box = self.enviroment.boxes[j][i] # TRANSPOSE !! ------------------
if self.enviroment.cursor.colliderect(box.rectangle) and self.game.board[i][j] == self.game.player:
action = 3*i+j
finished = self.game.make_move(action, erase=True)
return finished
class Player_FullBaoard(Player):
def __init__(self, enviroment):
super().__init__(enviroment)
def move(self):
self.playing = True
finished = False
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.playing = False
if event.type == pygame.MOUSEBUTTONDOWN:
# finished buttons
if self.enviroment.activate_finished_buttons:
for b in self.enviroment.buttons:
if self.enviroment.cursor.colliderect(b.rectangle):
b.command()
break
# play human
for i in range(3):
for j in range(3):
box = self.enviroment.boxes[j][i] # TRANSPOSE !! ------------------
if self.enviroment.cursor.colliderect(box.rectangle) and self.game.board[i][j] == 0:
action = 3*i+j
finished = self.game.make_move(action)
return finished