Small optimizations, add benchmark
This commit is contained in:
parent
a995784aac
commit
3702bddfd3
|
|
@ -35,14 +35,20 @@ void setup() {
|
|||
//delay(1000);
|
||||
Serial.println(F("hello"));
|
||||
|
||||
|
||||
b = Board();
|
||||
int startTime = micros();
|
||||
b.make({0x14, 0x34, P_EMPTY});
|
||||
b.make({0x64, 0x54, P_EMPTY});
|
||||
b.make({0x34, 0x44, P_EMPTY});
|
||||
b.make({0x63, 0x43, P_EMPTY});
|
||||
b.print();
|
||||
//b.print();
|
||||
b.make({0x44, 0x53, P_EMPTY});
|
||||
b.print();
|
||||
//b.print();
|
||||
|
||||
int elapsed = micros() - startTime;
|
||||
Serial.print(elapsed);
|
||||
Serial.println("microseconds for 5 moves");
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
28
Board.h
28
Board.h
|
|
@ -98,7 +98,7 @@ void Board::make(Move m) {
|
|||
u.sq_from = m.sq_from;
|
||||
u.sq_to = m.sq_to;
|
||||
|
||||
byte piece_type = field[m.sq_from] & 0x8;
|
||||
byte piece_type = field[m.sq_from] & 0x7;
|
||||
|
||||
if(u.captured || piece_type == W_PAWN) {
|
||||
field[PTR_REVMOV]++;
|
||||
|
|
@ -115,7 +115,7 @@ void Board::make(Move m) {
|
|||
|
||||
// TODO do any castling testing
|
||||
// Handle castling
|
||||
if((m.sq_from & 0b111) == W_KING && sq_diff_abs == 2) {
|
||||
if(piece_type == W_KING && sq_diff_abs == 2) {
|
||||
// We are castling! After all, a king cannot move
|
||||
// more than one position except when castling.
|
||||
// Since we don't care about legality; just do it
|
||||
|
|
@ -148,19 +148,15 @@ void Board::make(Move m) {
|
|||
// TODO: test enpassant code more than basics
|
||||
|
||||
// handle enpassant capture
|
||||
if(field[PTR_ENPASSANT] && (field[m.sq_from] & 0b111) == W_PAWN) {
|
||||
// en-passant capture is allowed.
|
||||
// we are also doing a pawn move
|
||||
// do further checks to see if we should remove the EP-pawn.
|
||||
if(
|
||||
(m.sq_to & 0x7) == (field[PTR_ENPASSANT] & 0x7) &&
|
||||
(m.sq_to & 0x70) == (0x50 - 0x30*black_moving())
|
||||
) {
|
||||
// we are also going to the correct square to do EP.
|
||||
// therefore, delete the EP-vurnerable pawn
|
||||
byte ep_field = m.sq_to - 16 + 32*black_moving();
|
||||
field[ep_field] = P_EMPTY;
|
||||
}
|
||||
if(
|
||||
field[PTR_ENPASSANT] && piece_type == W_PAWN &&
|
||||
(m.sq_to & 0x7) == (field[PTR_ENPASSANT] & 0x7) &&
|
||||
(m.sq_to & 0x70) == (0x50 - 0x30*black_moving())
|
||||
) {
|
||||
// we are also going to the correct square to do EP.
|
||||
// therefore, delete the EP-vurnerable pawn
|
||||
byte ep_field = m.sq_to - 16 + 32*black_moving();
|
||||
field[ep_field] = P_EMPTY;
|
||||
}
|
||||
|
||||
// Store the current enpassant situation
|
||||
|
|
@ -168,7 +164,7 @@ void Board::make(Move m) {
|
|||
|
||||
// handle enpassant setup (double pawn move)
|
||||
if(
|
||||
(field[m.sq_from] & 0b111) == W_PAWN &&
|
||||
piece_type == W_PAWN &&
|
||||
(sq_diff == 32 || sq_diff == -32)
|
||||
) {
|
||||
// we are doing a pawn double-move.
|
||||
|
|
|
|||
Loading…
Reference in New Issue