Exemplo n.º 1
0
def create_random_board():
    board = NQueensBoard(SIZE)

    for c in range(SIZE):
        r = randint(0, SIZE - 1)
        board.add_queen_at(XYLocation(c, r))

    return board
Exemplo n.º 2
0
def create_random_board():
    board = NQueensBoard(SIZE)

    for c in range(SIZE):
        r = randint(0, SIZE - 1)
        board.add_queen_at(XYLocation(c, r))

    return board
Exemplo n.º 3
0
    def test_actions(self):
        nqb = NQueensBoard(3)
        nqb.add_queen_at(XYLocation(0, 0))

        nqiaf = NQIActionsFunctions()
        actions = nqiaf.actions(nqb)
        expected_actions = [QueenAction(QueenAction.PLACE_QUEEN, XYLocation(1, 2)),
                            QueenAction(QueenAction.PLACE_QUEEN, XYLocation(2, 1))]
        self.assertSameElements(expected_actions, actions)
Exemplo n.º 4
0
    def test_move_queen(self):
        nqb = NQueensBoard(5)
        nqb.add_queen_at(XYLocation(3, 4))

        nqrf = NQResultFunction()
        new_board = nqrf.result(nqb, QueenAction(QueenAction.MOVE_QUEEN, XYLocation(3, 1)))

        self.assertFalse(new_board.queen_exists_at_square(4, 3))
        self.assertTrue(new_board.queen_exists_at_square(1, 3))
Exemplo n.º 5
0
    def test_move_queen(self):
        nqb = NQueensBoard(5)
        nqb.add_queen_at(XYLocation(3, 4))

        nqrf = NQResultFunction()
        new_board = nqrf.result(
            nqb, QueenAction(QueenAction.MOVE_QUEEN, XYLocation(3, 1)))

        self.assertFalse(new_board.queen_exists_at_square(4, 3))
        self.assertTrue(new_board.queen_exists_at_square(1, 3))
Exemplo n.º 6
0
    def test_actions(self):
        nqb = NQueensBoard(3)
        nqb.add_queen_at(XYLocation(0, 0))

        nqiaf = NQIActionsFunctions()
        actions = nqiaf.actions(nqb)
        expected_actions = [
            QueenAction(QueenAction.PLACE_QUEEN, XYLocation(1, 2)),
            QueenAction(QueenAction.PLACE_QUEEN, XYLocation(2, 1))
        ]
        self.assertSameElements(expected_actions, actions)
Exemplo n.º 7
0
    def test_get_state(self):
        string = "23041"
        conv = NQueensConverter(5)

        expected_board = NQueensBoard(5)
        expected_board.add_queen_at(XYLocation(0, 2))
        expected_board.add_queen_at(XYLocation(1, 3))
        expected_board.add_queen_at(XYLocation(2, 0))
        expected_board.add_queen_at(XYLocation(3, 4))
        expected_board.add_queen_at(XYLocation(4, 1))

        self.assertEqual(expected_board, conv.get_state(string))
Exemplo n.º 8
0
    def test_get_state(self):
        string = "23041"
        conv = NQueensConverter(5)

        expected_board = NQueensBoard(5)
        expected_board.add_queen_at(XYLocation(0, 2))
        expected_board.add_queen_at(XYLocation(1, 3))
        expected_board.add_queen_at(XYLocation(2, 0))
        expected_board.add_queen_at(XYLocation(3, 4))
        expected_board.add_queen_at(XYLocation(4, 1))

        self.assertEqual(expected_board, conv.get_state(string))
Exemplo n.º 9
0
    def test_remove_queen_from(self):
        nqb = NQueensBoard(5)
        nqb.add_queen_at(XYLocation(3, 4))
        nqb.remove_queen_from(XYLocation(3, 4))

        self.assertEqual(0, len(nqb.get_queen_positions()))
Exemplo n.º 10
0
 def test_add_queen_at(self):
     nqb = NQueensBoard(5)
     nqb.add_queen_at(XYLocation(3, 4))
     self.assertTrue(nqb.queen_exists_at_square(4, 3))
Exemplo n.º 11
0
    def test_remove_queen_from(self):
        nqb = NQueensBoard(5)
        nqb.add_queen_at(XYLocation(3, 4))
        nqb.remove_queen_from(XYLocation(3, 4))

        self.assertEqual(0, len(nqb.get_queen_positions()))
Exemplo n.º 12
0
 def test_add_queen_at(self):
     nqb = NQueensBoard(5)
     nqb.add_queen_at(XYLocation(3, 4))
     self.assertTrue(nqb.queen_exists_at_square(4, 3))