/// flip() flips position with the white and black sides reversed. This /// is only useful for debugging especially for finding evaluation symmetry bugs. internal void flip() { // Make a copy of current position before to start changing Position pos = new Position(this); clear(); sideToMove = pos.sideToMove ^ 1; thisThread = pos.this_thread(); nodes = pos.nodes; chess960 = pos.chess960; startPosPly = pos.startpos_ply_counter(); for (Square s = SquareC.SQ_A1; s <= SquareC.SQ_H8; s++) if (!pos.is_empty(s)) put_piece((pos.piece_on(s) ^ 8), Utils.flip_S(s)); if (pos.can_castle_CR(CastleRightC.WHITE_OO) != 0) set_castle_right(ColorC.BLACK, Utils.flip_S(pos.castle_rook_square(ColorC.WHITE, CastlingSideC.KING_SIDE))); if (pos.can_castle_CR(CastleRightC.WHITE_OOO) != 0) set_castle_right(ColorC.BLACK, Utils.flip_S(pos.castle_rook_square(ColorC.WHITE, CastlingSideC.QUEEN_SIDE))); if (pos.can_castle_CR(CastleRightC.BLACK_OO) != 0) set_castle_right(ColorC.WHITE, Utils.flip_S(pos.castle_rook_square(ColorC.BLACK, CastlingSideC.KING_SIDE))); if (pos.can_castle_CR(CastleRightC.BLACK_OOO) != 0) set_castle_right(ColorC.WHITE, Utils.flip_S(pos.castle_rook_square(ColorC.BLACK, CastlingSideC.QUEEN_SIDE))); if (pos.st.epSquare != SquareC.SQ_NONE) st.epSquare = Utils.flip_S(pos.st.epSquare); // Checkers st.checkersBB = attackers_to(king_square(sideToMove)) & pieces_C(Utils.flip_C(sideToMove)); // Hash keys st.key = compute_key(); st.pawnKey = compute_pawn_key(); st.materialKey = compute_material_key(); // Incremental scores st.psqScore = compute_psq_score(); // Material st.npMaterialWHITE = compute_non_pawn_material(ColorC.WHITE); st.npMaterialBLACK = compute_non_pawn_material(ColorC.BLACK); Debug.Assert(pos_is_ok()); }