def next(self): raw_entry = self.next_raw() source_x = ((raw_entry[1] >> 6) & 077) & 0x7 source_y = (((raw_entry[1] >> 6) & 077) >> 3) & 0x7 target_x = (raw_entry[1] & 077) & 0x7 target_y = ((raw_entry[1] & 077) >> 3) & 0x7 promote = (raw_entry[1] >> 12) & 0x7 move = Move( source=Square.from_x_and_y(source_x, source_y), target=Square.from_x_and_y(target_x, target_y), promotion="nbrq"[promote + 1] if promote else None) # Replace the non standard castling moves. if move.uci == "e1h1": move = Move.from_uci("e1g1") elif move.uci == "e1a1": move = Move.from_uci("e1c1") elif move.uci == "e8h8": move = Move.from_uci("e8g8") elif move.uci == "e8a8": move = Move.from_uci("e8c8") return { "position_hash": raw_entry[0], "move": move, "weight": raw_entry[2], "learn": raw_entry[3] }
def next(self): raw_entry = self.next_raw() source_x = ((raw_entry[1] >> 6) & 077) & 0x7 source_y = (((raw_entry[1] >> 6) & 077) >> 3) & 0x7 target_x = (raw_entry[1] & 077) & 0x7 target_y = ((raw_entry[1] & 077) >> 3) & 0x7 promote = (raw_entry[1] >> 12) & 0x7 move = Move(source=Square.from_x_and_y(source_x, source_y), target=Square.from_x_and_y(target_x, target_y), promotion="nbrq"[promote + 1] if promote else None) # Replace the non standard castling moves. if move.uci == "e1h1": move = Move.from_uci("e1g1") elif move.uci == "e1a1": move = Move.from_uci("e1c1") elif move.uci == "e8h8": move = Move.from_uci("e8g8") elif move.uci == "e8a8": move = Move.from_uci("e8c8") return { "position_hash": raw_entry[0], "move": move, "weight": raw_entry[2], "learn": raw_entry[3] }
def text(self): """The FEN string representing the position.""" # Board setup. empty = 0 fen = "" for y in range(7, -1, -1): for x in range(0, 8): square = Square.from_x_and_y(x, y) p = self._pieces[square._x88] # Add pieces. if not p: empty += 1 else: if empty > 0: fen += str(empty) empty = 0 fen += p # Boarder of the board. if empty > 0: fen += str(empty) # if were not the first iteration if not (x == 7 and y == 0): fen += "/" empty = 0 return ' '.join([ fen, self.turn, self.castle_rights, str(self.ep_square), str(self.fifty_move), str(self.full_move) ])
def test_from_x_and_y(self): square = Square.from_x_and_y(0, 0 ) self.assertEqual('a1', str(square))