コード例 #1
0
ファイル: Knight.py プロジェクト: Szimhead/KnightVsBishop
 def findAllNeighbours(self, position):
     neighbours = []
     positions = ([1, 2], [1, -2], [-1, 2], [-1, -2], [2, 1], [2, -1],
                  [-2, 1], [-2, -1])
     for pos in positions:
         newPosition = numpy.add(position, pos)
         if main.checkIfInBounds(newPosition):
             neighbours.append(newPosition)
     return neighbours
コード例 #2
0
ファイル: Knight.py プロジェクト: Szimhead/KnightVsBishop
 def findNeighbours(self, position):
     neighbours = []
     positions = ([1, 2], [1, -2], [-1, 2], [-1, -2], [2, 1], [2, -1],
                  [-2, 1], [-2, -1])
     for pos in positions:
         newPosition = numpy.add(position, pos)
         if main.checkIfInBounds(newPosition) and [
                 newPosition[0], newPosition[1]
         ] not in self.obstacles:
             neighbours.append(numpy.add(position, pos))
     return neighbours
コード例 #3
0
    def findNeighbours(self, position):
        i = position[0]
        j = position[1]

        neighbours = []

        while main.checkIfInBounds([i, j]):
            neighbours.append([i, j])
            i += 1
            j += 1

        i = position[0]
        j = position[1]

        while main.checkIfInBounds([i, j]):
            neighbours.append([i, j])
            i -= 1
            j -= 1

        i = position[0]
        j = position[1]

        while main.checkIfInBounds([i, j]):
            neighbours.append([i, j])
            i -= 1
            j += 1

        i = position[0]
        j = position[1]

        while main.checkIfInBounds([i, j]):
            neighbours.append([i, j])
            i += 1
            j -= 1

        return neighbours
コード例 #4
0
 def move(self, direction):
     new_position = numpy.add(self.pos, direction)
     if main.checkIfInBounds(new_position):
         self.pos = new_position