-
Notifications
You must be signed in to change notification settings - Fork 0
/
human_agent.py
35 lines (28 loc) · 980 Bytes
/
human_agent.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
import pygame
from agent import Agent
class MyAgent(Agent):
def get_action(self, state, last_action, time_left):
played = False
action = None
while not played:
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONUP:
pos = pygame.mouse.get_pos()
valid_clic = False
if state.get_cur_player() == 0:
pawn = int(pos[0] / 100) - 1
if 0 <= pawn <= 4 and state.get_pawn_position(0, pawn)[1] <= pos[1] <= state.get_pawn_position(0, pawn)[1] + 100:
valid_clic = True
else:
pawn = int(pos[1] / 100) - 1
if 0 <= pawn <= 4 and state.get_pawn_position(1, pawn)[0] <= pos[0] <= state.get_pawn_position(1, pawn)[0] + 100:
valid_clic = True
if valid_clic and state.is_action_valid(pawn):
played = True
action = pawn
if event.type == pygame.QUIT:
pygame.quit()
exit(0)
return action
def get_name(self):
return "human_agent"