コード例 #1
0
ファイル: Attack.py プロジェクト: Juddling/BattlePi
    def uber_eliminate(self, rand_i, rand_j):
        """
        DEPRECATED - when searching using squares of an odd/even pairity (just black squares on a chessboard), one can
        rule out certain squares based on it's neighbours
        """
        if not self.sunk_two_boat or not self.sunk_carrier:
            return False

        matches = transform.match_matrix([[0, 0, 0]], self.view_of_opponent)
        allowed_points = []

        for j, i in matches:  # reversed on purpose
            allowed_points.append((i, j))
            allowed_points.append((i, j + 1))
            allowed_points.append((i, j + 2))

        matches = transform.match_matrix([[0], [0], [0]], self.view_of_opponent)

        for j, i in matches:  # reversed on purpose
            allowed_points.append((i, j))
            allowed_points.append((i + 1, j))
            allowed_points.append((i + 2, j))

        unique_points = list(set(allowed_points))

        if (rand_i, rand_j) in unique_points:
            return False

        self.eliminated_points.append((rand_i, rand_j))

        return True
コード例 #2
0
ファイル: test_matrix.py プロジェクト: Juddling/BattlePi
    def test_matrix(self):
        test_pattern = [
            [1],
            [2],
            [2],
            [1]
        ]

        ship = [
            [1, 1, 1, 1, 1],
            [1, 1, 2, 1, 1],
            [1, 2, 2, 2, 1],
            [1, 2, 1, 2, 1],
            [1, 1, 1, 1, 1]
        ]

        expected = [
            (2,0),
            (1,1),
            (3,1)
        ]

        row_results = transform.match_matrix(test_pattern, ship)

        for index, row in enumerate(row_results):
            self.assertSequenceEqual(tuple(row), tuple(expected[index]))
コード例 #3
0
ファイル: test_matrix.py プロジェクト: Juddling/BattlePi
    def test_elimination(self):
        config = [[1, 1, 0, 1, 1, 0],
                  [0, 2, 2, 2, 2, 0],
                  [0, 1, 0, 0, 1, 0],
                  [1, 1, 0, 1, 0, 0],
                  [1, 2, 0, 0, 1, 0],
                  [0, 2, 0, 0, 0, 1],
                  [1, 2, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0],
                  [0, 1, 0, 0, 1, 0, 0, 1, 1, 2, 2, 1],
                  [0, 0, 1, 1, 2, 2, 0, 0, 1, 1, 1, 0],
                  [0, 0, 1, 2, 2, 1, 0, 0, 0, 1, 1, 0],
                  [0, 1, 1, 1, 2, 2, 0, 1, 2, 2, 2, 1],
                  [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1]]

        matches = transform.match_matrix([[0,0,0],
                                          [5,0,5],
                                          [5,0,5],
                                          [5,0,5]], config)

        co_ords = []

        for j, i in matches:
            co_ords.append((i, j))

        self.assertSequenceEqual(co_ords, [
            (6, 5)
        ])
コード例 #4
0
ファイル: test_matrix.py プロジェクト: Juddling/BattlePi
    def test_hovercraft_positions(self):
        board = [
            [2, 2, 2, 1, 0, 0, 1, 1, 1, 1, 1, 1],
            [0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1],
            [1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1],
            [1, 0, 1, 1, 0, 2, 1, 1, 1, 1, 1, 1],
            [0, 0, 0, 0, 1, 2, 1, 1, 1, 1, 1, 1],
            [0, 0, 1, 0, 1, 2, 1, 1, 1, 1, 1, 1],
            [0, 0, 1, 1, 2, 2, 2, 1, 1, 2, 1, 2],
            [0, 0, 0, 0, 1, 1, 1, 0, 1, 2, 2, 2],
            [0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 2, 0],
            [0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0],
            [0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0],
            [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]
        ]

        shape = [
            [5,0,5],
            [0,0,0],
            [0,5,0]
        ]

        co_ords = [
            (0,1),
            (1,0),
            (2,0),
            (1,1),
            (1,2),
            (2,2)
        ]

        bla = transform.ShapeAndCoOrds(shape, co_ords)

        allowed_points =  []
        single_matches = []

        for result in bla.all_transformations():
            matches = transform.match_matrix(result[0], board)

            for j, i in matches: # reversed on purpose
                single_matches.append((i, j))

                for relative_tuple in result[1]:
                    allowed_points.append((i+relative_tuple[0], j+relative_tuple[1]))

        self.assertCountEqual(single_matches, [
            (6,0),
            (9,9)
        ])

        self.assertCountEqual(allowed_points, [
            (7,0),
            (8,0),
            (6,1),
            (7,1),
            (7,2),
            (8,2)
        ])
コード例 #5
0
ファイル: test_matrix.py プロジェクト: Juddling/BattlePi
    def test_carrier_positions(self):
        board = [
            [1, 1, 1, 1, 1, 1],
            [1, 0, 0, 0, 2, 1],
            [1, 1, 0, 1, 1, 1],
            [1, 1, 0, 1, 1, 1],
            [1, 2, 0, 1, 1, 1],
            [1, 2, 2, 2, 2, 1],
            [1, 2, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1],
            [1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 2, 1],
            [1, 1, 1, 1, 2, 2, 0, 0, 0, 0, 1, 1],
            [1, 1, 1, 2, 2, 1, 0, 0, 0, 0, 1, 1],
            [1, 1, 1, 1, 2, 2, 1, 1, 2, 2, 2, 1],
            [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
        ]

        shape = [
            [0,0,0],
            [5,0,5],
            [5,0,5],
            [5,0,5]
        ]

        co_ords = [
            (0,0),
            (0,1),
            (0,2),
            (1,1),
            (2,1),
            (2,1)
        ]

        bla = transform.ShapeAndCoOrds(shape, co_ords)

        single_matches = []

        for result in bla.all_transformations():
            matches = transform.match_matrix(result[0], board)

            for j, i in matches: # reversed on purpose
                single_matches.append((i, j))

        self.assertCountEqual(single_matches, [
            (6,6),
            (6,7),
            (7,6),
            (7,6),
            (1,1)
        ])
コード例 #6
0
ファイル: test_matrix.py プロジェクト: Juddling/BattlePi
    def test_carrier_squares(self):
        board = [
            [1, 1, 1, 1, 1, 1],
            [1, 0, 0, 0, 2, 1],
            [1, 1, 0, 1, 1, 1],
            [1, 1, 1, 1, 1, 1],
            [1, 2, 0, 1, 1, 1],
            [1, 2, 2, 2, 2, 1],
            [1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
            [1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 2, 1],
            [1, 1, 1, 1, 2, 2, 0, 0, 0, 0, 1, 1],
            [1, 1, 1, 2, 2, 1, 0, 1, 1, 0, 1, 1],
            [1, 1, 1, 1, 2, 2, 1, 1, 2, 2, 2, 1],
            [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
        ]

        shape = [
            [0,0,0],
            [5,0,5],
            [5,0,5],
            [5,0,5]
        ]

        co_ords = [
            (0,0),
            (0,1),
            (0,2),
            (1,1),
            (2,1),
            (3,1)
        ]

        bla = transform.ShapeAndCoOrds(shape, co_ords)

        allowed_points =  []
        single_matches = []

        for result in bla.all_transformations():
            matches = transform.match_matrix(result[0], board)

            for j, i in matches: # reversed on purpose
                single_matches.append((i, j))

                for relative_tuple in result[1]:
                    allowed_points.append((i+relative_tuple[0], j+relative_tuple[1]))

        self.assertCountEqual(single_matches, [
            (7,6),
            (7,6)
        ])

        self.assertCountEqual(tuple(allowed_points), [
            # horizonal at 7,6
            (7,6),
            (8,6),
            (9,6),
            (8,7),
            (8,8),
            (8,9),

            # horizonal at 7,6 other way
            (8,6),
            (8,7),
            (8,8),
            (8,9),
            (7,9),
            (9,9),
        ])