def fen(self, value): try: board, cl, cst, enp, clock, move_num = value.split() except ValueError: raise ValueError('wrong number of fields') self._clear() self._parse_fen_board(board) self.color = self._parse_color(cl) self.castle = castle.parse(cst) if enp != '-': try: self.enp = square.sq(enp) except ValueError: raise ValueError('bad en passant data') self.enp = enp try: self.halfmove_clock = int(clock) except ValueError: raise ValueError('bad halfmove clock') try: self.move_num = int(move_num) except ValueError: raise ValueError('bad move number')
def _clear(self): self.piece_bbs = {} for pc in piece.all(): self.piece_bbs[pc] = 0L self.color_bbs = {} self.color_bbs[0] = 0L self.color_bbs[1] = 0L self.squares = {} for sq in square.all(): self.squares[sq] = 0L self.castle = castle.parse('KQkq') self.enp = square.sq() self.halfmove_clock = 0 self.move_num = 1