Fixed check_correct
This commit is contained in:
@@ -133,7 +133,7 @@ class Board:
|
|||||||
self.bunker, itertools.chain.from_iterable(
|
self.bunker, itertools.chain.from_iterable(
|
||||||
stack for stack in self.field if stack), ):
|
stack for stack in self.field if stack), ):
|
||||||
if isinstance(card, tuple):
|
if isinstance(card, tuple):
|
||||||
special_cards[card[0]] += 4 # pylint: disable=E1136
|
special_cards[card[0]] += 4
|
||||||
elif isinstance(card, SpecialCard):
|
elif isinstance(card, SpecialCard):
|
||||||
special_cards[card] += 1
|
special_cards[card] += 1
|
||||||
elif isinstance(card, NumberCard):
|
elif isinstance(card, NumberCard):
|
||||||
@@ -141,8 +141,8 @@ class Board:
|
|||||||
return False
|
return False
|
||||||
number_cards[card.suit].add(card.number)
|
number_cards[card.suit].add(card.number)
|
||||||
|
|
||||||
for _, numbers in number_cards.items():
|
for suit, numbers in number_cards.items():
|
||||||
if set(range(1, 10)) != numbers:
|
if set(range(self.goal[suit] + 1, 10)) != numbers:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
for cardtype, count in special_cards.items():
|
for cardtype, count in special_cards.items():
|
||||||
|
|||||||
@@ -15,8 +15,6 @@ class Action:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def apply(self, action_board: board.Board) -> None:
|
def apply(self, action_board: board.Board) -> None:
|
||||||
assert self._before_state == 0
|
|
||||||
assert self._after_state == 0
|
|
||||||
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)
|
||||||
|
|||||||
@@ -71,9 +71,6 @@ def solve(board: Board) -> Iterator[List[board_actions.Action]]:
|
|||||||
for prev_action in stack.action_stack[-2:-21:-1]:
|
for prev_action in stack.action_stack[-2:-21:-1]:
|
||||||
if isinstance(prev_action, MoveAction):
|
if isinstance(prev_action, MoveAction):
|
||||||
if prev_action.cards == action.cards:
|
if prev_action.cards == action.cards:
|
||||||
print("Dropping")
|
|
||||||
print(action)
|
|
||||||
print(prev_action)
|
|
||||||
drop = True
|
drop = True
|
||||||
if drop:
|
if drop:
|
||||||
continue
|
continue
|
||||||
|
|||||||
15
test/helper.py
Normal file
15
test/helper.py
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
from .context import shenzhen_solitaire
|
||||||
|
from shenzhen_solitaire import solver
|
||||||
|
|
||||||
|
from .boards import my_board
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
A = solver.solve(my_board)
|
||||||
|
for _, B in zip(range(1), A):
|
||||||
|
print(*B, sep='\n')
|
||||||
|
print(len(B))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -1,15 +1,20 @@
|
|||||||
|
import unittest
|
||||||
|
import copy
|
||||||
|
|
||||||
from .context import shenzhen_solitaire
|
from .context import shenzhen_solitaire
|
||||||
from shenzhen_solitaire import solver
|
from shenzhen_solitaire import solver
|
||||||
|
|
||||||
from .boards import my_board
|
from .boards import my_board
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
class SolverTest(unittest.TestCase):
|
||||||
|
def test_solver(self) -> None:
|
||||||
|
board_copy = copy.deepcopy(my_board)
|
||||||
|
board_id = my_board.state_identifier
|
||||||
A = solver.solve(my_board)
|
A = solver.solve(my_board)
|
||||||
for _, B in zip(range(1), A):
|
for _, B in zip(range(1), A):
|
||||||
print(*B, sep='\n')
|
self.assertEqual(board_id, board_copy.state_identifier)
|
||||||
print(len(B))
|
for x in B:
|
||||||
|
x.apply(board_copy)
|
||||||
|
self.assertTrue(board_copy.check_correct())
|
||||||
if __name__ == "__main__":
|
self.assertTrue(board_copy.solved())
|
||||||
main()
|
|
||||||
|
|||||||
Reference in New Issue
Block a user