-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenvtest.py
37 lines (32 loc) · 888 Bytes
/
envtest.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
import pygame
from chess import Chess
from time import sleep
import numpy as np
import random
import sys
sys.setrecursionlimit(100)
env = Chess(window_size=800)
env.render()
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# if event.type == pygame.KEYDOWN:
# if event.key != pygame.K_SPACE:
# continue
# else:
turn = env.turn
print("White" if turn else "Black")
src, dst, mask = env.get_all_actions(turn)
action = random.sample(list(np.where(mask == 1)[0]), 1)[0]
print(f"Action = {action}", src[action], dst[action])
rewards, done, infos = env.step(action)
print(f"Rewards = {rewards}")
print(f"Infos = {infos}")
print("-" * 64)
env.render()
if done:
env.reset()
print("RESET")
env.close()