Compare commits

..

No commits in common. "cc20fa0ce5630ad91ae48ed8c8ea0850e7b0f956" and "a995784aac58dcf375e8a19eb6565529e3f55e21" have entirely different histories.

3 changed files with 19 additions and 27 deletions

View File

@ -35,20 +35,14 @@ 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();
int elapsed = micros() - startTime;
Serial.print(elapsed);
Serial.println("microseconds for 5 moves");
b.print();
}

31
Board.h
View File

@ -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] & 0x7;
byte piece_type = field[m.sq_from] & 0x8;
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(piece_type == W_KING && sq_diff_abs == 2) {
if((m.sq_from & 0b111) == 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,16 +148,19 @@ void Board::make(Move m) {
// TODO: test enpassant code more than basics
// handle enpassant capture
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;
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;
}
}
// Store the current enpassant situation
@ -165,8 +168,8 @@ void Board::make(Move m) {
// handle enpassant setup (double pawn move)
if(
piece_type == W_PAWN &&
(sq_diff_abs == 32)
(field[m.sq_from] & 0b111) == W_PAWN &&
(sq_diff == 32 || sq_diff == -32)
) {
// we are doing a pawn double-move.
// therefore, it allows enpassant in the next move.

View File

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