Adding docstring
This commit is contained in:
@@ -5,6 +5,7 @@ from . import board
|
|||||||
|
|
||||||
|
|
||||||
class Action:
|
class Action:
|
||||||
|
"""Base class for a card move action on a solitaire board"""
|
||||||
_before_state: int = 0
|
_before_state: int = 0
|
||||||
_after_state: int = 0
|
_after_state: int = 0
|
||||||
|
|
||||||
@@ -15,6 +16,7 @@ class Action:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def apply(self, action_board: board.Board) -> None:
|
def apply(self, action_board: board.Board) -> None:
|
||||||
|
"""Apply action to board"""
|
||||||
if __debug__:
|
if __debug__:
|
||||||
self._before_state = action_board.state_identifier
|
self._before_state = action_board.state_identifier
|
||||||
self._apply(action_board)
|
self._apply(action_board)
|
||||||
@@ -22,6 +24,7 @@ class Action:
|
|||||||
self._after_state = action_board.state_identifier
|
self._after_state = action_board.state_identifier
|
||||||
|
|
||||||
def undo(self, action_board: board.Board) -> None:
|
def undo(self, action_board: board.Board) -> None:
|
||||||
|
"""Undo action to board"""
|
||||||
assert action_board.state_identifier == self._after_state
|
assert action_board.state_identifier == self._after_state
|
||||||
self._undo(action_board)
|
self._undo(action_board)
|
||||||
assert action_board.state_identifier == self._before_state
|
assert action_board.state_identifier == self._before_state
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ from .board_actions import (
|
|||||||
|
|
||||||
|
|
||||||
class ActionStack:
|
class ActionStack:
|
||||||
|
"""Stack of chosen actions on the board"""
|
||||||
iterator_stack: List[Iterator[board_actions.Action]]
|
iterator_stack: List[Iterator[board_actions.Action]]
|
||||||
action_stack: List[Optional[board_actions.Action]]
|
action_stack: List[Optional[board_actions.Action]]
|
||||||
index_stack: List[int]
|
index_stack: List[int]
|
||||||
@@ -23,12 +24,14 @@ class ActionStack:
|
|||||||
self.state_stack = []
|
self.state_stack = []
|
||||||
|
|
||||||
def push(self, board: Board) -> None:
|
def push(self, board: Board) -> None:
|
||||||
|
"""Append another board state to stack"""
|
||||||
self.iterator_stack.append(possible_actions(board))
|
self.iterator_stack.append(possible_actions(board))
|
||||||
self.action_stack.append(None)
|
self.action_stack.append(None)
|
||||||
self.index_stack.append(0)
|
self.index_stack.append(0)
|
||||||
self.state_stack.append(board.state_identifier)
|
self.state_stack.append(board.state_identifier)
|
||||||
|
|
||||||
def get(self) -> Optional[board_actions.Action]:
|
def get(self) -> Optional[board_actions.Action]:
|
||||||
|
"""Get next iteration of top action iterator"""
|
||||||
try:
|
try:
|
||||||
self.action_stack[-1] = next(self.iterator_stack[-1])
|
self.action_stack[-1] = next(self.iterator_stack[-1])
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
@@ -37,6 +40,7 @@ class ActionStack:
|
|||||||
return self.action_stack[-1]
|
return self.action_stack[-1]
|
||||||
|
|
||||||
def pop(self) -> None:
|
def pop(self) -> None:
|
||||||
|
"""Pop one action from stack"""
|
||||||
self.action_stack.pop()
|
self.action_stack.pop()
|
||||||
self.iterator_stack.pop()
|
self.iterator_stack.pop()
|
||||||
self.index_stack.pop()
|
self.index_stack.pop()
|
||||||
|
|||||||
Reference in New Issue
Block a user