Implemented actions
This commit is contained in:
@@ -16,7 +16,7 @@ def possible_dragonkill_actions(
|
||||
"""Enumerate all possible dragon kills"""
|
||||
possible_dragons = [board.SpecialCard.Zhong,
|
||||
board.SpecialCard.Fa, board.SpecialCard.Bai]
|
||||
if not any(x == board.BunkerStatus.Empty for x in search_board.bunker):
|
||||
if not any(x is None for x in search_board.bunker):
|
||||
new_possible_dragons = []
|
||||
for dragon in possible_dragons:
|
||||
if any(x == dragon for x in search_board.bunker):
|
||||
@@ -35,7 +35,7 @@ def possible_dragonkill_actions(
|
||||
destination_bunker_id = bunker_dragons[0]
|
||||
else:
|
||||
destination_bunker_id = [
|
||||
i for i, x in enumerate(search_board.bunker) if x == board.BunkerStatus.Empty][0]
|
||||
i for i, x in enumerate(search_board.bunker) if x is None][0]
|
||||
|
||||
source_stacks = [(board.Position.Bunker, i) for i in bunker_dragons]
|
||||
source_stacks.extend([(board.Position.Field, i)
|
||||
@@ -45,10 +45,10 @@ def possible_dragonkill_actions(
|
||||
destination_bunker_id=destination_bunker_id)
|
||||
|
||||
|
||||
def possible_bunkerize_actions(search_board: board.Board) -> Iterator[board_actions.MoveAction]:
|
||||
def possible_bunkerize_actions(search_board: board.Board) -> Iterator[board_actions.StoreAction]:
|
||||
"""Enumerates all possible card moves from the field to the bunker"""
|
||||
open_bunker_list = [i for i, x in enumerate(
|
||||
search_board.bunker) if x == board.BunkerStatus.Empty]
|
||||
search_board.bunker) if x is None]
|
||||
|
||||
if not open_bunker_list:
|
||||
return
|
||||
@@ -57,14 +57,13 @@ def possible_bunkerize_actions(search_board: board.Board) -> Iterator[board_acti
|
||||
for index, stack in enumerate(search_board.field):
|
||||
if not stack:
|
||||
continue
|
||||
yield board_actions.MoveAction(card=stack[-1],
|
||||
source_position=board.Position.Field,
|
||||
source_id=index,
|
||||
destination_position=board.Position.Bunker,
|
||||
destination_id=open_bunker)
|
||||
yield board_actions.StoreAction(card=stack[-1],
|
||||
source_id=index,
|
||||
destination_id=open_bunker)
|
||||
|
||||
|
||||
def possible_debunkerize_actions(search_board: board.Board) -> Iterator[board_actions.MoveAction]:
|
||||
def possible_debunkerize_actions(
|
||||
search_board: board.Board) -> Iterator[board_actions.RestoreAction]:
|
||||
"""Enumerates all possible card moves from the bunker to the field"""
|
||||
bunker_number_cards = [(i, x) for i, x in enumerate(
|
||||
search_board.bunker) if isinstance(x, board.NumberCard)]
|
||||
@@ -78,16 +77,26 @@ def possible_debunkerize_actions(search_board: board.Board) -> Iterator[board_ac
|
||||
continue
|
||||
if other_stack[-1].number != card.number + 1:
|
||||
continue
|
||||
yield board_actions.MoveAction(card=card,
|
||||
source_position=board.Position.Bunker,
|
||||
source_id=index,
|
||||
destination_position=board.Position.Field,
|
||||
destination_id=other_index)
|
||||
yield board_actions.RestoreAction(card=card,
|
||||
source_id=index,
|
||||
destination_id=other_index)
|
||||
|
||||
|
||||
def possible_goal_move_actions(search_board: board.Board) -> Iterator[board_actions.MoveAction]:
|
||||
def possible_goal_move_actions(search_board: board.Board) -> Iterator[board_actions.GoalAction]:
|
||||
"""Enumerates all possible moves from anywhere to the goal"""
|
||||
#TODO
|
||||
field_cards = [(board.Position.Field, index, stack[-1]) for index, stack in enumerate(
|
||||
search_board.field) if stack if isinstance(stack[-1], board.NumberCard)]
|
||||
bunker_cards = [(board.Position.Bunker, index, stack)
|
||||
for index, stack in enumerate(search_board.bunker)
|
||||
if isinstance(stack, board.NumberCard)]
|
||||
top_cards = field_cards + bunker_cards
|
||||
|
||||
for suit, number in search_board.goal.items():
|
||||
for source, index, stack in top_cards:
|
||||
if not (stack.suit == suit and stack.number == number + 1):
|
||||
continue
|
||||
yield board_actions.GoalAction(card=stack, source_id=index, source_position=source)
|
||||
break
|
||||
|
||||
|
||||
def possible_field_move_actions(search_board: board.Board) -> Iterator[board_actions.MoveAction]:
|
||||
@@ -107,9 +116,7 @@ def possible_field_move_actions(search_board: board.Board) -> Iterator[board_act
|
||||
if other_stack[-1].number != stack[-1].number + 1:
|
||||
continue
|
||||
yield board_actions.MoveAction(card=stack[-1],
|
||||
source_position=board.Position.Field,
|
||||
source_id=index,
|
||||
destination_position=board.Position.Field,
|
||||
destination_id=other_index)
|
||||
|
||||
|
||||
@@ -117,6 +124,7 @@ def possible_actions(search_board: board.Board) -> Iterator[board_actions.Action
|
||||
"""Enumerate all possible actions on the current search_board"""
|
||||
yield from possible_huakill_action(search_board)
|
||||
yield from possible_dragonkill_actions(search_board)
|
||||
yield from possible_goal_move_actions(search_board)
|
||||
yield from possible_debunkerize_actions(search_board)
|
||||
yield from possible_field_move_actions(search_board)
|
||||
yield from possible_bunkerize_actions(search_board)
|
||||
|
||||
Reference in New Issue
Block a user