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