Esempio n. 1
0
    def load_level(self, n):
        rob.set_field_size(11, 11)

        a = random.randint(1, 7)
        b = random.randint(1, 3)
        c = 1 if random.randint(0, 1) else -1

        rob.goto(10, 5)

        for i in range(a):
            rob.put_wall(left=True, right=True)
            rob.move_up()

        if c == 1:
            rob.put_wall(left=True, top=True)
        else:
            rob.put_wall(right=True, top=True)

        for i in range(b):
            if c == 1:
                rob.move_right()
            else:
                rob.move_left()
            rob.put_wall(top=True, bottom=True)

        if c == -1:
            rob.put_wall(left=True)
        else:
            rob.put_wall(right=True)

        rob.set_parking_cell(*rob.get_pos())

        rob.goto(10, 5)
Esempio n. 2
0
    def load_level(self, n):

        m = random.randint(20, 40)

        rob.set_field_size(3, m)

        cells = list(range(1, m))
        random.shuffle(cells)
        cells = sorted(cells[:random.randint(7, m - 5)])

        for i in cells:
            rob.set_cell_type(1, i, rob.CELL_FILLED)

        rob.goto(1, 0)

        c = 0
        while not rob.wall_is_on_the_right():
            if rob.cell_is_filled():
                c += 1
                if c == 3:
                    break
            else:
                c = 0
            rob.move_right()

        rob.set_parking_cell(*rob.get_pos())

        rob.goto(1, 0)
Esempio n. 3
0
    def load_level(self, n):
        rob.set_field_size(13, 20)

        l = random.randint(10, 15)

        corridors = [random.randint(0, 1) for i in range(l)]

        rob.goto(10, 1)
        for i in range(l):
            rob.move_right()
            rob.put_wall(bottom=True)

            if not corridors[i]:
                rob.put_wall(top=True)
                continue

            k = random.randint(1, 8)
            for j in range(k):
                rob.move_up()
                pos = rob.get_pos()
                rob.set_cell_type(pos[0], pos[1], rob.CELL_TO_BE_FILLED)
                rob.put_wall(left=True, right=True)

            rob.put_wall(top=True)

            for j in range(k):
                rob.move_down()

        self.cells_to_fill = find_cells_to_be_filled()

        rob.put_wall(right=True)
        rob.set_parking_cell(10, 1)

        rob.goto(10, 1)
Esempio n. 4
0
    def load_level(self, n):
        n = random.randint(20, 30)

        rob.set_field_size(5, n)

        cases = {
            0: {'top': True},
            1: {'bottom': True},
            2: {'top': True, 'bottom': True},
            3: {}
        }

        rob.goto(2, 0)
        for j in range(n):
            case = random.randint(0, 3)
            rob.put_wall(**cases[case])

            if not rob.wall_is_above():
                rob.set_cell_type(1, j, rob.CELL_TO_BE_FILLED)

            if not rob.wall_is_beneath():
                rob.set_cell_type(3, j, rob.CELL_TO_BE_FILLED)

            if rob.wall_is_above() and rob.wall_is_beneath():
                rob.set_cell_type(2, j, rob.CELL_TO_BE_FILLED)

            if j != n-1:
                rob.move_right()
Esempio n. 5
0
    def load_level(self, n):

        m = random.randint(20, 40)

        rob.set_field_size(3, m)

        rob.goto(1, 1)

        d = 0
        _d = 0

        while not rob.wall_is_on_the_right():
            if _d == 0:
                pos = rob.get_pos()
                rob.set_cell_type(pos[0], pos[1], rob.CELL_TO_BE_FILLED)
                d += 1
                _d = d
            rob.move_right()
            _d -= 1

        self.cells_to_fill = find_cells_to_be_filled()

        rob.set_parking_cell(1, m - 1)

        rob.goto(1, 0)
Esempio n. 6
0
    def testWallCrash(self):
        rob.goto(0, 0)

        for move, test in [('move_right', 'move_up'), ('move_down', 'move_right'), ('move_left', 'move_down'),
                           ('move_up', 'move_left')]:
            for i in range(10):
                with self.assertRaises(RobotCrashed):
                    getattr(rob, test)()

                if i != 9:
                    getattr(rob, move)()

        rob.goto(0, 0)
        with self.assertRaises(RobotCrashed):
            rob.move_right(10)

        rob.goto(0, 0)
        with self.assertRaises(RobotCrashed):
            rob.move_down(10)

        rob.goto(9, 9)
        with self.assertRaises(RobotCrashed):
            rob.move_left(10)

        rob.goto(9, 9)
        with self.assertRaises(RobotCrashed):
            rob.move_up(10)
Esempio n. 7
0
    def testRight(self):
        rob.goto(0, 0)
        for i in range(8):
            rob.move_right()
            self.assertEqual(rob.get_pos(), (0, i + 1))

        rob.goto(0, 0)
        rob.move_right(9)

        self.assertEqual(rob.get_pos(), (0, 9))
Esempio n. 8
0
    def load_level(self, n):
        rob.set_field_size(15, 15)

        l = random.randint(5, 13)
        i = random.randint(2, 8)

        rob.goto(i, 0)
        for k in range(l):
            rob.put_wall(bottom=True)
            rob.move_right()

        rob.set_parking_cell(i + 1, 0)

        rob.goto(0, 0)
Esempio n. 9
0
    def load_level(self, n):
        rob.set_field_size(10, 10)

        i = random.randint(2, 8)
        l = random.randint(1, 8)

        rob.goto(i, 1)
        for k in range(l):
            rob.put_wall(bottom=True)
            rob.move_right()

        rob.set_parking_cell(*rob.get_pos())

        rob.goto(i, 1)
Esempio n. 10
0
    def load_level(self, n):
        rob.set_field_size(10, 10)

        for i in range(10):
            rob.set_cell_type(i, i, rob.CELL_TO_BE_FILLED)

        rob.set_parking_cell(3, 3)
        rob.set_parking_cell(9, 9)

        rob.goto(2, 4)
        for i in range(4):
            rob.put_wall(top=True, bottom=True)
            rob.move_right()

        rob.goto(0, 0)
Esempio n. 11
0
    def load_level(self, n):
        rob.set_field_size(10, 20)

        l = random.randint(5, 12)
        i = random.randint(2, 6)
        j = random.randint(0, 5)

        rob.goto(i, j)
        for m in range(l):
            k = random.randint(0, 1)
            rob.put_wall(bottom=(k == 0), top=(k == 1))
            rob.move_right()

        rob.set_parking_cell(*rob.get_pos())

        rob.goto(i, j)
Esempio n. 12
0
    def load_level(self, n):
        l = random.randint(20, 30)
        rob.set_field_size(13, l + 1)

        corridors = [random.randint(0, 1) for i in range(l)]

        self.filled_cells_number = 0

        rob.goto(10, 0)
        rob.put_wall(top=True, bottom=True)
        rob.set_cell_type(10, 0, rob.CELL_TO_BE_FILLED)
        for j in range(l - 1):
            rob.move_right()
            rob.put_wall(bottom=True)

            if not corridors[j + 1]:
                rob.put_wall(top=True)
                rob.set_cell_type(10, j + 1, rob.CELL_TO_BE_FILLED)
                continue

            k = random.randint(1, 8)
            for q in range(k):
                rob.move_up()
                pos = rob.get_pos()
                if random.randint(0, 1) == 0:
                    rob.fill_cell()
                    self.filled_cells_number += 1
                else:
                    rob.set_cell_type(pos[0], pos[1], rob.CELL_TO_BE_FILLED)
                rob.put_wall(left=True, right=True)

            rob.put_wall(top=True)

            for q in range(k):
                rob.move_down()

        self.cells_to_fill = find_cells_to_be_filled() + find_filled_cells()

        rob.set_parking_cell(10, l)

        rob.goto(10, 0)
Esempio n. 13
0
    def load_level(self, n):
        rob.set_field_size(11, 11)

        i = random.randint(4, 8)
        j = random.randint(1, 9)
        q = random.randint(1, 9)

        rob.goto(i, 1)
        rob.put_wall(left=True)

        for k in range(1, 10):
            rob.put_wall(bottom=True)
            if k != j:
                rob.put_wall(top=True)
            rob.move_right()

        rob.put_wall(left=True)

        rob.set_parking_cell(0, 0)

        rob.goto(i, q)
Esempio n. 14
0
    def load_level(self, n):
        n = random.randint(20, 30)

        rob.set_field_size(3, n)

        rob.goto(1, 0)
        for j in range(n):
            rob.put_wall(bottom=True)
            if random.randint(0, 1) == 0:
                rob.put_wall(top=True)
            else:
                rob.set_cell_type(1, j, rob.CELL_TO_BE_FILLED)

            if j != n - 1:
                rob.move_right()

        self.cells_to_fill = find_cells_to_be_filled()

        rob.set_parking_cell(1, n - 1)

        rob.goto(1, 0)
Esempio n. 15
0
    def load_level(self, n):
        rob.set_field_size(11, 11)

        i = random.randint(4, 8)

        rob.goto(i, 1)
        if n != 1:
            rob.put_wall(left=True)

        for k in range(1, 10):
            rob.put_wall(bottom=True, top=True)
            rob.move_right()

        if n != 0:
            rob.put_wall(left=True)

        if n != 2:
            rob.set_parking_cell(0, 0)
        else:
            rob.set_parking_cell(i, 9)

        rob.goto(i, 5)
Esempio n. 16
0
    def load_level(self, n):

        m = random.randint(15, 20)
        n = random.randint(15, 20)

        rob.set_field_size(m, n)

        for i in range(m - 1):
            if random.randint(0, 1) == 0:
                continue

            rob.goto(i, 0)

            k = random.randint(1, n - 2)
            for j in range(n):
                if j != k:
                    rob.put_wall(bottom=True)
                if j != n - 1:
                    rob.move_right()

        rob.set_parking_cell(m - 1, 0)

        rob.goto(0, n - 1)