-
Notifications
You must be signed in to change notification settings - Fork 1
/
agent.py
34 lines (26 loc) · 845 Bytes
/
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
""" Random AI.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import sys
import os
import numpy as np
import time
from ...constants import *
from ...board import Board
from ...game import Checkers
from ..agent import Agent
class RandomAgent(Agent):
def __init__(self, player, rule):
base_name = 'Random'
super(RandomAgent, self).__init__(base_name, player, rule)
def act(self, obs, moves, info):
random_index1 = int(np.random.random_sample() * len(moves))
from_pos, legal_moves = moves[random_index1]
assert(len(legal_moves) > 0)
random_index2 = int(np.random.random_sample() * len(legal_moves))
to_pos = legal_moves[random_index2]
return (from_pos, to_pos)
def consume(self, rew):
pass