Here you can find the source of printBitboard(long bitboard)
bitboardToString
to System.out
.
Parameter | Description |
---|---|
bitboard | the bitboard to print. |
public static void printBitboard(long bitboard)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from ww w.j a v a2 s . co m*/ * Prints a bitboard by sending the result of <code>bitboardToString</code> * to <code>System.out</code>. * * @param bitboard * the bitboard to print. */ public static void printBitboard(long bitboard) { System.out.println(bitboardToString(bitboard)); } /** * Converts a <i>bitboard</i>, not a board, to a string. The string will * look identical to the result of Board.toString, except that pieces are * instead shown as 'X'. * * @param bitboard * the bitboard to represent as a string. * @return a string representation of the bitboard. */ public static String bitboardToString(long bitboard) { String asBinary = Long.toBinaryString(bitboard); while (asBinary.length() != 64) asBinary = "0" + asBinary; String s = " a b c d e f g h\n"; s += " +---+---+---+---+---+---+---+---+\n 8 | "; for (int up = 7; up >= 0; up--) { for (int out = 0; out < 8; out++) { if (asBinary.charAt(63 - (up * 8 + out)) == '1') s += "X | "; else s += " | "; } s += (up + 1) + "\n +---+---+---+---+---+---+---+---+"; if (up != 0) s += "\n " + up + " | "; } s += "\n a b c d e f g h\n"; return s; } }