private static BitBoard makeWithoutFileH() { BitBoard result = new BitBoard(); for (BoardSquare s : BoardSquare.values()) { if (s.file() != 'h') { result.set(s); } } return result; }
private static BitBoard makeInteriorSquares() { BitBoard result = new BitBoard(); for (BoardSquare bs : BoardSquare.values()) { if (!bs.onEdge()) { result.set(bs); } } return result; }
public static BitBoard makeKnightMoves(BoardSquare kn) { BitBoard result = new BitBoard(); for (BoardSquare bs : BoardSquare.values()) { if (kn.hasKnightMoveTo(bs)) { result.set(bs); } } return result; }
public static BitBoard makeBishopMoves(BoardSquare bish) { BitBoard result = new BitBoard(); for (BoardSquare bs : BoardSquare.values()) { if (bish.hasBishopMoveTo(bs)) { result.set(bs); } } return result; }
public static BitBoard makeRookMoves(BoardSquare rook) { BitBoard result = new BitBoard(); for (BoardSquare bs : BoardSquare.values()) { if (rook.hasRookMoveTo(bs)) { result.set(bs); } } return result; }
public BitBoard(String rep) { this(); int displayIndex = 0; for (int i = 0; i < rep.length(); ++i) { if (rep.charAt(i) != '\n') { if (rep.charAt(i) == '1') { set(BoardSquare.values()[displayIndex]); } displayIndex += 1; } } }
public String toString() { StringBuilder sb = new StringBuilder(); int nextRow = 8; for (BoardSquare bs : BoardSquare.values()) { sb.append(isSet(bs) ? '1' : '0'); nextRow -= 1; if (nextRow == 0) { sb.append('\n'); nextRow = 8; } } return sb.toString(); }
public void clear(BoardSquare bs) { bits &= ~bs.getMask(); }
public void set(BoardSquare bs) { bits |= bs.getMask(); }
public boolean isSet(BoardSquare s) { return (bits & s.getMask()) != 0; }
@Override public BoardSquare next() { prev = unseen & -unseen; unseen -= prev; return BoardSquare.values()[Long.numberOfTrailingZeros(prev)]; }