-
Notifications
You must be signed in to change notification settings - Fork 0
/
env.py
38 lines (27 loc) · 827 Bytes
/
env.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
from gym import Env
from gym.spaces import Discrete
from board import Board
RED = 1
BLACK = 0
class Backgammon(Env):
def __init__(self):
self.state = None
self.current_agent = None
self.action_space = Discrete(601)
def step(self,agent, action):
if self.state.isValidMove(self.state.outputMapping[action]):
self.state.addCheckerToPoint(agent, self.state.outputMapping[action])
reward = 0
done = False
if self.state.isGameOver() == 1:
reward = 1
done = True
elif self.state.isGameOver() == -1:
reward = -1
done = True
info = {}
return self.state, reward, done, info
def render(self):
self.state.printBoard()
def reset(self):
self.state = Board()