# Calculon

Home * Engines * Calculon

Calculon [1]

Calculon,
a Java chess engine by Barry Smith named after the Futurama character. It is open source, licensed under the Apache License, Version 2.0 and hosted at GitHub [2]. Calculon is UCI compatible, uses bitboards as basic data structure, and applies Negamax alpha-beta. The engine regularly plays on ICC under the name CalculonX and has Blitz/Standard ratings there around the 1750 mark.

# getPiece

Calculon's getPiece routine to get a the piece code of a square (the least significant one-bit of the passed bitboard pos, typically single populated) from the six piece bitboards of its board representation emphasizes a central bitboard weakness, and the cause to keep a redundant mailbox board representation with some additional update costs during make/unmake. Taking the union (val) of six piece-specific rotates (left by 1..6) of six piece disjoint intersections for the absolute difference of the trailing zero counts of that union and the passed square bitboard (pos) elegantly avoids some branches, but is a bit too much calculation for that purpose [3].

```public class BitBoard { // Position object

public byte getPiece(long pos) {
long val = Long.rotateLeft(bitmaps[MAP_PAWNS]   & pos, MAP_PAWNS)
| Long.rotateLeft(bitmaps[MAP_KNIGHTS] & pos, MAP_KNIGHTS)
| Long.rotateLeft(bitmaps[MAP_BISHOPS] & pos, MAP_BISHOPS)
| Long.rotateLeft(bitmaps[MAP_ROOKS]   & pos, MAP_ROOKS)
| Long.rotateLeft(bitmaps[MAP_QUEENS]  & pos, MAP_QUEENS)
| Long.rotateLeft(bitmaps[MAP_KINGS]   & pos, MAP_KINGS);
if(val == 0) {
return Piece.EMPTY;
}
return (byte) ((Long.numberOfTrailingZeros(val) - Long.numberOfTrailingZeros(pos)) & 0x07);
}
}
```