- if direction == BITS.NORTH and y > 0:
- return (x, y - 1)
- elif direction == BITS.SOUTH and y < 4:
- return (x, y + 1)
- elif direction == BITS.EAST and x < 4:
- return (x + 1, y)
- elif direction == BITS.WEST and x > 0:
- return (x - 1, y)
- else:
- # Not a legal space.
- return None
-
- def move(self, direction):
- if not self.bits.check_bit(direction):
- return False
- new_position = self.get_adjacent_position(direction)
- if new_position is not None:
- self.position = new_position
- return True
- return False
+
+ if self.bits.check_bit(BITS.NORTH) and y > 0:
+ positions.append((x, y - 1))
+ if self.bits.check_bit(BITS.SOUTH) and y < 4:
+ positions.append((x, y + 1))
+ if self.bits.check_bit(BITS.EAST) and x < 4:
+ positions.append((x + 1, y))
+ if self.bits.check_bit(BITS.WEST) and x > 0:
+ positions.append((x - 1, y))
+
+ return positions
+
+ def get_knight_positions(self):
+ positions = set([self.position])
+
+ x, y = self.position
+
+ for a in (2, -2):
+ for b in (1, -1):
+ i, j = x + a, y + b
+ if 0 <= i < 5 and 0 <= j < 5:
+ positions.add((i, j))
+
+ i, j = x + b, y + a
+ if 0 <= i < 5 and 0 <= j < 5:
+ positions.add((i, j))
+
+ return sorted(list(positions))
+
+ def get_bishop_positions(self):
+ positions = set()
+
+ x, y = self.position
+
+ for i in range(5):
+ j = i + y - x
+ if 0 <= j < 5:
+ positions.add((i, j))
+
+ j = x + y - i
+ if 0 <= j < 5:
+ positions.add((i, j))
+
+ return sorted(list(positions))
+
+ def get_castle_positions(self):
+ positions = set()
+
+ x, y = self.position
+
+ for i in range(5):
+ positions.add((x, i))
+ positions.add((i, y))
+
+ return sorted(list(positions))