Compare commits
No commits in common. "36a4ff5676ef0cfa0e75012204894ff1ebac1a17" and "6d342e4e0e0a2418e42637600417549c84fc351e" have entirely different histories.
36a4ff5676
...
6d342e4e0e
|
|
@ -9,49 +9,9 @@
|
|||
#include "Movegen.h"
|
||||
#include "Types.h"
|
||||
|
||||
void debug_castle() {
|
||||
print();
|
||||
make({0x06, 0x25, P_EMPTY}); print();
|
||||
make({0x76, 0x55, P_EMPTY}); print();
|
||||
make({0x16, 0x26, P_EMPTY}); print();
|
||||
make({0x63, 0x43, P_EMPTY}); print();
|
||||
make({0x05, 0x16, P_EMPTY}); print();
|
||||
make({0x62, 0x42, P_EMPTY}); print();
|
||||
make({0x04, 0x06, P_EMPTY}); print();
|
||||
unmake(); print();
|
||||
unmake(); print();
|
||||
unmake(); print();
|
||||
unmake(); print();
|
||||
unmake(); print();
|
||||
unmake(); print();
|
||||
unmake(); print();
|
||||
}
|
||||
|
||||
void debug_ep() {
|
||||
print();
|
||||
make({0x14, 0x34, P_EMPTY});
|
||||
print();
|
||||
make({0x64, 0x54, P_EMPTY});
|
||||
print();
|
||||
make({0x34, 0x44, P_EMPTY});
|
||||
print();
|
||||
make({0x63, 0x43, P_EMPTY});
|
||||
print();
|
||||
make({0x44, 0x53, P_EMPTY});
|
||||
print();
|
||||
unmake();
|
||||
print();
|
||||
unmake();
|
||||
print();
|
||||
unmake();
|
||||
print();
|
||||
unmake();
|
||||
print();
|
||||
unmake();
|
||||
print();
|
||||
}
|
||||
|
||||
void bench() {
|
||||
board_init();
|
||||
|
||||
int startTime = micros();
|
||||
|
||||
make({0x14, 0x34, P_EMPTY});
|
||||
|
|
@ -76,7 +36,39 @@ void setup() {
|
|||
// put your setup code here, to run once:
|
||||
board_init();
|
||||
Serial.begin(115200);
|
||||
debug_castle();
|
||||
bench();
|
||||
Serial.println(F("hello"));
|
||||
|
||||
|
||||
board_init();
|
||||
int startTime = micros();
|
||||
print();
|
||||
make({0x14, 0x34, P_EMPTY});
|
||||
print();
|
||||
make({0x64, 0x54, P_EMPTY});
|
||||
print();
|
||||
make({0x34, 0x44, P_EMPTY});
|
||||
print();
|
||||
make({0x63, 0x43, P_EMPTY});
|
||||
print();
|
||||
make({0x44, 0x53, P_EMPTY});
|
||||
print();
|
||||
unmake();
|
||||
print();
|
||||
unmake();
|
||||
print();
|
||||
unmake();
|
||||
print();
|
||||
unmake();
|
||||
print();
|
||||
unmake();
|
||||
print();
|
||||
|
||||
int elapsed = micros() - startTime;
|
||||
Serial.print(elapsed);
|
||||
Serial.println(F("microseconds for 5 moves"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
|
|
|||
66
Board.h
66
Board.h
|
|
@ -16,11 +16,21 @@
|
|||
B_ROOK, B_KNGT, B_BSHP, B_QUEN, B_KING, B_BSHP, B_KNGT, B_ROOK, 0, 0, 0, 0, 0, 0, 0, 0, \
|
||||
};
|
||||
|
||||
|
||||
byte field[128];
|
||||
const byte field_default_value[] PROGMEM = BOARD_DEFAULT_VALUE;
|
||||
|
||||
void board_init() {
|
||||
for(int i = 0; i < 128; i++) {
|
||||
field[i] = pgm_read_byte_near(field_default_value + i);
|
||||
}
|
||||
}
|
||||
|
||||
// 0x88-fill definitions
|
||||
#define PTR_SIDE_AND_CASTLERIGHT 0x08 //byte (1=side, 2,4=white castle, 8,16=black)
|
||||
// CAN FILL 0x09
|
||||
#define PTR_W_KING 0x0A // byte (points to index or maybe 64-arr index)
|
||||
#define PTR_B_KING 0x0B // (PTR_W_KING | COLOR or PTR_W_KING + COLOR)
|
||||
// const byte PTR_B_KING = 0x0B; (PTR_W_KING | COLOR or PTR_W_KING + COLOR)
|
||||
#define PTR_ZOBRIST 0x0C // 4 bytes
|
||||
// 0x0D
|
||||
// 0x0E
|
||||
|
|
@ -32,28 +42,11 @@
|
|||
|
||||
#define PTR_UNMOVE_START 0x28
|
||||
#define PTR_UNMOVE_LAST 0x7F
|
||||
|
||||
byte field[128];
|
||||
byte PTR_UNMOVE = PTR_UNMOVE_START;
|
||||
|
||||
const byte field_default_value[] PROGMEM = BOARD_DEFAULT_VALUE;
|
||||
|
||||
void board_init() {
|
||||
for(int i = 0; i < 128; i++) {
|
||||
field[i] = pgm_read_byte_near(field_default_value + i);
|
||||
}
|
||||
field[PTR_SIDE_AND_CASTLERIGHT] = 0b11110; // all castle rights allowed, white to move
|
||||
field[PTR_W_KING] = 0x04; // e1
|
||||
field[PTR_B_KING] = 0x74; // e8
|
||||
long* zob = (long*)&field[PTR_ZOBRIST];
|
||||
*zob = 0xDEADBEEF;
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct Unmove {
|
||||
byte sq_from; // 0b(1unused)(3rank)(1unused)(3file)
|
||||
byte sq_to; // 0b(1promoted?)(3rank)(1ep_capture?)(3file)
|
||||
byte sq_to; // 0b(1promoted?)(3rank)(1unused)(3file)
|
||||
byte captured; // 0b(4enpassantinfo)(1color)(3piecetype)
|
||||
byte revmov; // 8bit integer
|
||||
};
|
||||
|
|
@ -124,6 +117,7 @@ void print() {
|
|||
}
|
||||
|
||||
void make(Move m) {
|
||||
// TODO handle revmov clock
|
||||
// TODO zobrist?
|
||||
|
||||
// fill unmove struct with basic data
|
||||
|
|
@ -142,7 +136,7 @@ void make(Move m) {
|
|||
}
|
||||
|
||||
// Calculate the move 'amount' (unique signature for dx,dy)
|
||||
int sq_diff = (int)m.sq_to - (int)m.sq_from;
|
||||
int sq_diff = (int)m.sq_from - (int)m.sq_to;
|
||||
int sq_diff_abs = abs(sq_diff);
|
||||
|
||||
|
||||
|
|
@ -164,18 +158,17 @@ void make(Move m) {
|
|||
// Handle castling rights
|
||||
// We are doing the simple way:
|
||||
// unset it any time a move is made from the original position.
|
||||
// TODO handle castle rights and unmake
|
||||
if(m.sq_from == 0x00) // white queenside rook
|
||||
if(m.sq_from == 0x00)
|
||||
field[PTR_SIDE_AND_CASTLERIGHT] &= ~0b00010;
|
||||
if(m.sq_from == 0x07) // white kingside rook
|
||||
if(m.sq_from == 0x07)
|
||||
field[PTR_SIDE_AND_CASTLERIGHT] &= ~0b00100;
|
||||
if(m.sq_from == 0x04) // white king
|
||||
if(m.sq_from == 0x04)
|
||||
field[PTR_SIDE_AND_CASTLERIGHT] &= ~0b00110;
|
||||
if(m.sq_from == 0x70) // black queenside rook
|
||||
if(m.sq_from == 0x70)
|
||||
field[PTR_SIDE_AND_CASTLERIGHT] &= ~0b01000;
|
||||
if(m.sq_from == 0x77) // black kingside rook
|
||||
if(m.sq_from == 0x77)
|
||||
field[PTR_SIDE_AND_CASTLERIGHT] &= ~0b10000;
|
||||
if(m.sq_from == 0x74) // black king
|
||||
if(m.sq_from == 0x74)
|
||||
field[PTR_SIDE_AND_CASTLERIGHT] &= ~0b11000;
|
||||
|
||||
|
||||
|
|
@ -199,7 +192,7 @@ void make(Move m) {
|
|||
// handle enpassant setup (double pawn move)
|
||||
if(
|
||||
piece_type == W_PAWN &&
|
||||
sq_diff_abs == 32
|
||||
(sq_diff_abs == 32)
|
||||
) {
|
||||
// we are doing a pawn double-move.
|
||||
// therefore, it allows enpassant in the next move.
|
||||
|
|
@ -251,23 +244,6 @@ void unmake() {
|
|||
// also undo the regular move
|
||||
field[u.sq_from] = field[sq_to];
|
||||
}
|
||||
// TODO handle castling rights
|
||||
|
||||
int sq_diff = (int)sq_to - (int)u.sq_from;
|
||||
int sq_diff_abs = abs(sq_diff);
|
||||
if((field[u.sq_from] & 0x7) == W_KING && sq_diff_abs == 2) {
|
||||
// we castled
|
||||
byte castle_source = 0x70*!black_moving();
|
||||
if(sq_diff == 2) {
|
||||
castle_source += 0x7;
|
||||
}
|
||||
byte castle_target = u.sq_from + (sq_diff/2);
|
||||
// move rook back to original position
|
||||
field[castle_source] = field[castle_target];
|
||||
// and clear where it was put
|
||||
field[castle_target] = P_EMPTY;
|
||||
}
|
||||
|
||||
|
||||
field[sq_to] = u.captured & 0b1111;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue