Compare commits

...

2 Commits

Author SHA1 Message Date
Quinten Kock cc20fa0ce5 smol fixes 2020-06-16 04:52:19 +02:00
Quinten Kock 3702bddfd3 Small optimizations, add benchmark 2020-06-16 04:30:02 +02:00
3 changed files with 27 additions and 19 deletions

View File

@ -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");
} }

15
Board.h
View File

@ -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,11 +148,9 @@ 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) {
// 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( if(
field[PTR_ENPASSANT] &&
piece_type == W_PAWN &&
(m.sq_to & 0x7) == (field[PTR_ENPASSANT] & 0x7) && (m.sq_to & 0x7) == (field[PTR_ENPASSANT] & 0x7) &&
(m.sq_to & 0x70) == (0x50 - 0x30*black_moving()) (m.sq_to & 0x70) == (0x50 - 0x30*black_moving())
) { ) {
@ -161,15 +159,14 @@ void Board::make(Move m) {
byte ep_field = m.sq_to - 16 + 32*black_moving(); byte ep_field = m.sq_to - 16 + 32*black_moving();
field[ep_field] = P_EMPTY; field[ep_field] = P_EMPTY;
} }
}
// Store the current enpassant situation // Store the current enpassant situation
u.enpassant = field[PTR_ENPASSANT]; u.enpassant = field[PTR_ENPASSANT];
// 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_abs == 32)
) { ) {
// we are doing a pawn double-move. // we are doing a pawn double-move.
// therefore, it allows enpassant in the next move. // therefore, it allows enpassant in the next move.

View File

@ -1,3 +1,6 @@
#ifndef __PANIC_H_INC
#define __PANIC_H_INC
void panic(const __FlashStringHelper* message) { void panic(const __FlashStringHelper* message) {
while(true) { while(true) {
Serial.println(F("PANIC!")); Serial.println(F("PANIC!"));
@ -5,3 +8,5 @@ void panic(const __FlashStringHelper* message) {
delay(1000); delay(1000);
} }
} }
#endif