def updateAura(self): # deprecated because king can be cut aura = [] for dx, dy in KING_MOVES: x = self.x + dx y = self.y + dy if onBoard(x, y): aura.append((x, y)) self._aura = aura
def test_onBoard(self): self.assertTrue(onBoard(1, 1)) self.assertTrue(onBoard(8, 8)) self.assertFalse(onBoard(0, 1)) self.assertFalse(onBoard(9, 1)) self.assertFalse(onBoard(1, 0)) self.assertFalse(onBoard(1, 9))
def isProtected(self, x, y, color): # deprecated because king can be cut if not onBoard(x, y): raise OutOfBoardError for fig in self.figures: if fig.color != color: continue if isinstance(fig, King): moves = fig.royalAura() else: moves = fig.getMoves() if (x, y) in moves: return True return False
def is_valid(self): coors = self.form['move'].split('-') if len(coors) != 2: return self.error('move format must be like e2-e4') try: for coor in coors: if not onBoard(*coors2pos(coor)): raise ValueError(coor) except ValueError: return self.error('some coordinate is incorrect') self.cleaned_data = { 'coor1': coors[0], 'coor2': coors[1], } return super(GameMoveValidator, self).is_valid()
def getVisibleCells(self): cells = [] if self.color == WHITE: if self.y == 2: cells.append((self.x, 3)) if not self.board.cell2Figure(self.x, 3): cells.append((self.x, 4)) elif self.y < 8: cells.append((self.x, self.y + 1)) cells += [(self.x - 1, self.y + 1), (self.x + 1, self.y + 1)] else: if self.y == 7: cells.append((self.x, 6)) if not self.board.cell2Figure(self.x, 6): cells.append((self.x, 5)) elif self.y > 1: cells.append((self.x, self.y - 1)) cells += [(self.x - 1, self.y - 1), (self.x + 1, self.y - 1)] return [cell for cell in cells if onBoard(*cell)]
def cell2Figure(self, x, y): if not onBoard(x, y): raise OutOfBoardError for fig in self.figures: if fig.x == x and fig.y == y: return fig