コード例 #1
0
def generate_unique_states_from_sets(complexity, almanac=set_almanac, size=3):
    """From a state of complexity n, generate all states of complexity n+1."""
    for state in almanac[complexity]:
        board = Board(size)
        board.previous_states = []
        board.state = json.loads(state)
        open_y = 1
        open_x = 1

        for row in board.state:
            if 9 in row:
                open_y += board.state.index(row)
                open_x += row.index(9)

        board.open_cell_coords = (open_x, open_y)

        board._determine_legal_moves(board.open_cell_coords)

        pboard = PracticeBoard(board.state)

        for move in board.legal_moves:
            if complexity > 0:
                if str(pboard.practice_slide(move)) in almanac[complexity - 1]:
                    continue
            almanac[complexity + 1].add(str(pboard.practice_slide(move)))

    return almanac
コード例 #2
0
def test_determine_legal_moves_finds_all_moves(coords, result):
    """Test that the legal moves are correctly determined around any coords."""
    from electric_slide.scripts.board import Board
    b = Board()
    b._determine_legal_moves(coords)
    assert sorted(b.legal_moves) == sorted(result)