Bitboard => how to display board

Code, algorithms, languages, construction...
Post Reply
Terradon
Posts: 6
Joined: Fri Nov 23, 2012 9:11 pm
Real Name: Peter

Bitboard => how to display board

Post by Terradon » Fri Nov 23, 2012 9:18 pm

Hi all,
I wanted to rewrite an existing online chessgame (in PHP) because of limitations in the current script.
After readng a lot, it's time to start coding.
First part is the boardpresentation.
Starting with 14 bitboards for all kind of pieces, including 2 for all white and all black pieces), how do i display the game?

In current script (without bitboards), we use a multi-array like $aBoard[row][column] = piecenumber, created by an database query, which returns all pieces and location.

Do i still need this kind of arrays? Or is it possible to directly create a presentation directly from the bitboards?

geko
Posts: 34
Joined: Mon Aug 01, 2011 5:11 pm

Re: Bitboard => how to display board

Post by geko » Sat Nov 24, 2012 10:17 am

Hi Terradon,
this is the display method of my engine Butterfly, i've 12 bitboards: chessboard[12]

Code: Select all


void ChessBoard::display() {
    int t;
    char x;
    cout << "\n.....a   b   c   d   e   f   g   h";
    for (t = 0; t <= 63; t++) {
        if (!(t % 8)) {
            cout << "\n...---------------------------------\n";
        };
        x = FEN_PIECE[getPieceAtWhite( TABLOG[63 - t])];
        if (x == '-')
            x = FEN_PIECE[getPieceAtBlack( TABLOG[63 - t])];
        if (x == '-')
            x = ' ';
        switch (t) {
        case 0:
            cout << " 8 | ";
            break;
        case 8:
            cout << " 7 | ";
            break;
        case 16:
            cout << " 6 | ";
            break;
        case 24:
            cout << " 5 | ";
            break;
        case 32:
            cout << " 4 | ";
            break;
        case 40:
            cout << " 3 | ";
            break;
        case 48:
            cout << " 2 | ";
            break;
        case 56:
            cout << " 1 | ";
            break;
        default:
            ;
            break;
        }
        if (x != ' ')
            cout << x;
        else if (t == 0 || t == 2 || t == 4 || t == 6 || t == 9 || t == 11 || t == 13 || t == 15 || t == 16 || t == 18 || t == 20 || t == 22
                 || t == 25 || t == 27 || t == 29 || t == 31 || t == 32 || t == 34 || t == 36 || t == 38 || t == 41 || t == 43 || t == 45 || t == 47
                 || t == 48 || t == 50 || t == 52 || t == 54 || t == 57 || t == 59 || t == 61 || t == 63)
            cout << " ";
        else
            cout << ".";
        cout << " | " << flush;
    };
    cout << "\n";
    cout << "...---------------------------------\n";
    cout << ".....a   b   c   d   e   f   g   h\n\n";
 
}
int ChessBoard::getPieceAtWhite( u64 pos) {
    return(chessboard[PAWN_WHITE] & pos) ? PAWN_WHITE :
          ((chessboard[KING_WHITE] & pos) ? KING_WHITE :
           ((chessboard[ROOK_WHITE] & pos) ? ROOK_WHITE :
            ((chessboard[BISHOP_WHITE] & pos) ? BISHOP_WHITE :
             ((chessboard[KNIGHT_WHITE] & pos) ? KNIGHT_WHITE :
              ((chessboard[QUEEN_WHITE] & pos) ? QUEEN_WHITE : SQUARE_FREE)))));
}
int ChessBoard::getPieceAtBlack( u64 pos) {
    return (chessboard[PAWN_BLACK] & pos) ? PAWN_BLACK :
           ((chessboard[KING_BLACK] & pos) ? KING_BLACK :
            ((chessboard[ROOK_BLACK] & pos) ? ROOK_BLACK :
             ((chessboard[BISHOP_BLACK] & pos) ? BISHOP_BLACK :
              ((chessboard[KNIGHT_BLACK] & pos) ? KNIGHT_BLACK :
               ((chessboard[QUEEN_BLACK] & pos) ? QUEEN_BLACK : SQUARE_FREE)))));
}

Terradon
Posts: 6
Joined: Fri Nov 23, 2012 9:11 pm
Real Name: Peter

Re: Bitboard => how to display board

Post by Terradon » Sat Nov 24, 2012 8:38 pm

Ok, what i have in mind now:
Per game:
saving the 14 bitboards (12 for pieces and 2 for all white en al blackpieces, easier for evaluation of valid moves) in my database.
retrieve the bitboards, loop trough the bitboards, create and display the board.
If moved, check move via bitboard mechanism. (include all chessrules)

Another few questions:
How to keep track of castling/check/50moves rule?
What is the best way to save history?
Which standards should i use (for general compatibility purpose)

geko
Posts: 34
Joined: Mon Aug 01, 2011 5:11 pm

Re: Bitboard => how to display board

Post by geko » Sun Nov 25, 2012 11:28 am

for castle use an global variable for castle rights and set/unset it respectively in makemove and unmakemove

For history usually using the zobrist keys; in makemove store key in a global array and in unmakemove remove key
from this array see 50moves rule and 3 fold repetition.
From zobrist key you can not get the original board, if you want it, you should store every played move and with unmakemove get the stack of the boards.

What do you want to know about the check?

Terradon
Posts: 6
Joined: Fri Nov 23, 2012 9:11 pm
Real Name: Peter

Re: Bitboard => how to display board

Post by Terradon » Sun Nov 25, 2012 9:11 pm

In present script all moves are stored in a database, retrieved from ther and put in an array $aHistory. if in chess, it is added to the move.
I did not know about the zobrist keys, so just read it, and i have to read it several times more to understand the principles of it.
We do not use a kind of undoing a move, in real chessworld it is forbidden too.
We do need to have the possibility to play back a game, including the ongoing game. (players can play up to 255 games simultaniously).
We have an own javascript for that purpose, but not bugfree. We want to use PGN standard for this part. Via a PGN string we can also keep track of the history and using a PGN viewer to play it back. (Probably we need a conversion of our chessboard somehow). Therefore we want to remember chess too.

Our first goal is to rewrite our script completely from beginning, using better principles and better performance.
We also hope, by using the right standards, it will be compatible with other software. For example, we now have no good PGN output for use in other chess software.
And ultimately, we want the possibility to play against software, for learning purposes and trying to auto-detect possible cheaters (almost uncurable disease of some players). Now we manually investigate suspicious players (time-consuming!!)

geko
Posts: 34
Joined: Mon Aug 01, 2011 5:11 pm

Re: Bitboard => how to display board

Post by geko » Sun Nov 25, 2012 10:48 pm

one question.. your php script is a complete chess engine or simply a GUI like Arena or winboard?

Terradon
Posts: 6
Joined: Fri Nov 23, 2012 9:11 pm
Real Name: Peter

Re: Bitboard => how to display board

Post by Terradon » Sun Nov 25, 2012 11:55 pm

it is just a simple GUI: a table with pieces and some php and javascript to handle moves and validation, using a few arrays, everything stored in mysql database. it's just a local online chess game website. The script is quit in-efficient coded and not bugfree.

Post Reply