simulator process a valid set, instead of a single action
This commit is contained in:
parent
12f45d9dc6
commit
818da800e2
@ -121,8 +121,8 @@ class Go:
|
|||||||
if self._is_eye(current_board, color, vertex):
|
if self._is_eye(current_board, color, vertex):
|
||||||
return False
|
return False
|
||||||
# forbid position on its own eye.
|
# forbid position on its own eye.
|
||||||
if self._is_game_finish(current_board, color) and vertex == utils.PASS
|
#if self._is_game_finish(current_board, color) and vertex == utils.PASS
|
||||||
return False
|
# return False
|
||||||
# forbid pass if the game is not finished.
|
# forbid pass if the game is not finished.
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -183,6 +183,18 @@ class Go:
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def simulate_is_valid_list(self, state, action_set):
|
||||||
|
## find all the valid actions
|
||||||
|
## if no action is valid, then pass
|
||||||
|
valid_action_set = []
|
||||||
|
for action_candidate in action_set:
|
||||||
|
if self.simulate_is_valid(self, state, action_candidate)
|
||||||
|
valid_action_set.append(action_candidate)
|
||||||
|
if not valid_action_set:
|
||||||
|
valid_action_set.append(utils.PASS)
|
||||||
|
# if valid_action_set is a empty set, add pass
|
||||||
|
return valid_action_set
|
||||||
|
|
||||||
def _do_move(self, board, color, vertex):
|
def _do_move(self, board, color, vertex):
|
||||||
if vertex == utils.PASS:
|
if vertex == utils.PASS:
|
||||||
return board
|
return board
|
||||||
|
@ -72,12 +72,7 @@ class UCTNode(MCTSNode):
|
|||||||
|
|
||||||
def valid_mask(self, simulator):
|
def valid_mask(self, simulator):
|
||||||
if self.mask is None:
|
if self.mask is None:
|
||||||
self.mask = []
|
self.mask = simulator.simulate_is_valid_list(self.state, range(self.action_num - 1))
|
||||||
for act in range(self.action_num - 1):
|
|
||||||
if not simulator.simulate_is_valid(self.state, act):
|
|
||||||
self.mask.append(act)
|
|
||||||
self.ucb[act] = -float("Inf")
|
|
||||||
else:
|
|
||||||
self.ucb[self.mask] = -float("Inf")
|
self.ucb[self.mask] = -float("Inf")
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user