Пример #1
0
    def test_line_status(self):

        state = empty_state()
        state = move(move(move(state, 2), 3), 2)

        self.assertEqual(state.line_status(0, YELLOW), AVAILABLE)
        self.assertEqual(state.line_status(0, RED), AVAILABLE)
        self.assertEqual(state.line_status(31, YELLOW), SINGLE)
        self.assertEqual(state.line_status(32, YELLOW), DOUBLE)
        self.assertEqual(state.line_status(21, YELLOW), UNAVAILABLE)
        self.assertEqual(state.line_status(21, RED), UNAVAILABLE)
        self.assertEqual(state.line_status(23, RED), SINGLE)
        self.assertEqual(state.line_status(56, RED), SINGLE)
        self.assertEqual(state.line_status(56, YELLOW), UNAVAILABLE)
        self.assertEqual(state.line_status(55, YELLOW), SINGLE)
        self.assertEqual(state.line_status(68, RED), UNAVAILABLE)
Пример #2
0
from state import State
from debug import print_board
from state_operations import move, empty_state

if __name__ == "__main__":
    s = empty_state()
    while True:
        print_board(s)
        col = int(input("Column "))
        s = move(s, col)
        print()
Пример #3
0
from tree import Node
from state_operations import move, empty_state
from debug import print_tree

if __name__ == "__main__":
    state = move(
        move(
            move(
                move(
                    move(move(move(move(move(empty_state(), 1), 2), 0), 1), 0),
                    0), 3), 6), 3)

    node = Node(state)
    node.create_subtree(2)

    print_tree(node)
Пример #4
0
    def create_children(self):
        """ Create list of all children of this node. """

        moves = self.state.possible_moves()

        self.children = [Node(move(self.state, c)) for _, c in moves]
Пример #5
0
    def test_line_future_state(self):

        # board used in case study 4 email thread
        state = move(
            move(
                move(
                    move(
                        move(
                            move(
                                move(
                                    move(
                                        move(
                                            move(
                                                move(
                                                    move(
                                                        move(empty_state(), 5),
                                                        3), 5), 3), 6), 6), 0),
                                6), 0), 5), 0), 0), 4)

        self.assertEqual(state.line_future_state(17), [(5, 1), (5, 2)])
        self.assertEqual(state.line_future_state(14), [(4, 2), (4, 4)])
        self.assertEqual(state.line_future_state(15), [(4, 4)])
        self.assertEqual(state.line_future_state(27), [])
        self.assertEqual(state.line_future_state(57), [(1, 3), (2, 4)])
        self.assertEqual(state.line_future_state(56), [])