Put more stuff in namespaces
This commit is contained in:
parent
21e956519e
commit
e00f9231fb
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// put your setup code here, to run once:
|
// put your setup code here, to run once:
|
||||||
board_init();
|
Board::init();
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
pinMode(LED_BUILTIN, OUTPUT);
|
pinMode(LED_BUILTIN, OUTPUT);
|
||||||
//perft_test();
|
//perft_test();
|
||||||
|
|
@ -21,5 +21,5 @@ void setup() {
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// put your main code here, to run repeatedly:
|
// put your main code here, to run repeatedly:
|
||||||
handle_uci();
|
Uci::handle_uci();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
6
Board.h
6
Board.h
|
|
@ -5,6 +5,8 @@
|
||||||
#include "Panic.h"
|
#include "Panic.h"
|
||||||
#include "Move.h"
|
#include "Move.h"
|
||||||
|
|
||||||
|
namespace Board {
|
||||||
|
|
||||||
#define BOARD_DEFAULT_VALUE { \
|
#define BOARD_DEFAULT_VALUE { \
|
||||||
W_ROOK, W_KNGT, W_BSHP, W_QUEN, W_KING, W_BSHP, W_KNGT, W_ROOK, 0, 0, 0, 0, 0, 0, 0, 0, \
|
W_ROOK, W_KNGT, W_BSHP, W_QUEN, W_KING, W_BSHP, W_KNGT, W_ROOK, 0, 0, 0, 0, 0, 0, 0, 0, \
|
||||||
W_PAWN, W_PAWN, W_PAWN, W_PAWN, W_PAWN, W_PAWN, W_PAWN, W_PAWN, 0, 0, 0, 0, 0, 0, 0, 0, \
|
W_PAWN, W_PAWN, W_PAWN, W_PAWN, W_PAWN, W_PAWN, W_PAWN, W_PAWN, 0, 0, 0, 0, 0, 0, 0, 0, \
|
||||||
|
|
@ -38,7 +40,7 @@ byte PTR_UNMOVE;
|
||||||
|
|
||||||
const byte field_default_value[] PROGMEM = BOARD_DEFAULT_VALUE;
|
const byte field_default_value[] PROGMEM = BOARD_DEFAULT_VALUE;
|
||||||
|
|
||||||
void board_init() {
|
void init() {
|
||||||
for(int i = 0; i < 128; i++) {
|
for(int i = 0; i < 128; i++) {
|
||||||
field[i] = pgm_read_byte_near(field_default_value + i);
|
field[i] = pgm_read_byte_near(field_default_value + i);
|
||||||
}
|
}
|
||||||
|
|
@ -288,5 +290,7 @@ void unmake() {
|
||||||
field[PTR_ENPASSANT] = u.captured >> 4;
|
field[PTR_ENPASSANT] = u.captured >> 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
38
Movegen.h
38
Movegen.h
|
|
@ -28,11 +28,11 @@ Move Movegen::next_move() {
|
||||||
while(square <= 0x77) {
|
while(square <= 0x77) {
|
||||||
if(square & 0x88) square += 8;
|
if(square & 0x88) square += 8;
|
||||||
|
|
||||||
byte piece_type = field[square] & 0x7;
|
byte piece_type = Board::field[square] & 0x7;
|
||||||
|
|
||||||
if(
|
if(
|
||||||
(field[square] & 0x7) &&
|
(Board::field[square] & 0x7) &&
|
||||||
(field[square] & 0x8) == black_moving() << 3
|
(Board::field[square] & 0x8) == Board::black_moving() << 3
|
||||||
) {
|
) {
|
||||||
// there is an own piece to investigate
|
// there is an own piece to investigate
|
||||||
Move m;
|
Move m;
|
||||||
|
|
@ -78,8 +78,8 @@ Move Movegen::generate_sliding(byte piece_type) {
|
||||||
}
|
}
|
||||||
// currently, we are at the next move target
|
// currently, we are at the next move target
|
||||||
// this means: we can try to generate this as a move!
|
// this means: we can try to generate this as a move!
|
||||||
byte piece = field[square];
|
byte piece = Board::field[square];
|
||||||
byte target = field[target_square];
|
byte target = Board::field[target_square];
|
||||||
if(target) {
|
if(target) {
|
||||||
// we encountered a piece! there are two outcomes here:
|
// we encountered a piece! there are two outcomes here:
|
||||||
// second, it can be the opponent's. then, we can capture it!
|
// second, it can be the opponent's. then, we can capture it!
|
||||||
|
|
@ -112,8 +112,8 @@ Move Movegen::generate_non_sliding(byte piece_type) {
|
||||||
|
|
||||||
direction++;
|
direction++;
|
||||||
|
|
||||||
byte target = field[target_square];
|
byte target = Board::field[target_square];
|
||||||
byte piece = field[square];
|
byte piece = Board::field[square];
|
||||||
|
|
||||||
if((target_square & 0x88) || (target && (target & 0x8) == (piece & 0x8))) {
|
if((target_square & 0x88) || (target && (target & 0x8) == (piece & 0x8))) {
|
||||||
// uh oh, off board or same color obstacle
|
// uh oh, off board or same color obstacle
|
||||||
|
|
@ -125,7 +125,7 @@ Move Movegen::generate_non_sliding(byte piece_type) {
|
||||||
Move Movegen::generate_pawn() {
|
Move Movegen::generate_pawn() {
|
||||||
// TODO: implement capture promotion
|
// TODO: implement capture promotion
|
||||||
|
|
||||||
byte color = black_moving();
|
byte color = Board::black_moving();
|
||||||
byte offset;
|
byte offset;
|
||||||
byte target;
|
byte target;
|
||||||
GP_START:
|
GP_START:
|
||||||
|
|
@ -135,7 +135,7 @@ Move Movegen::generate_pawn() {
|
||||||
direction = 1; // next try, go ahead further
|
direction = 1; // next try, go ahead further
|
||||||
offset = color ? -0x10 : 0x10;
|
offset = color ? -0x10 : 0x10;
|
||||||
target_square = square + offset;
|
target_square = square + offset;
|
||||||
if(field[target_square] ||
|
if(Board::field[target_square] ||
|
||||||
(square & 0x70) == (color ? 0x10 : 0x60)
|
(square & 0x70) == (color ? 0x10 : 0x60)
|
||||||
) {
|
) {
|
||||||
// moving ahead is not possible, not even a capture!
|
// moving ahead is not possible, not even a capture!
|
||||||
|
|
@ -152,7 +152,7 @@ Move Movegen::generate_pawn() {
|
||||||
direction = 2;
|
direction = 2;
|
||||||
offset = color ? -0x20 : 0x20;
|
offset = color ? -0x20 : 0x20;
|
||||||
target_square = square + offset;
|
target_square = square + offset;
|
||||||
if(!(field[target_square]) &&
|
if(!(Board::field[target_square]) &&
|
||||||
(square & 0x70) == (color ? 0x60 : 0x10)
|
(square & 0x70) == (color ? 0x60 : 0x10)
|
||||||
) {
|
) {
|
||||||
return Move{square, target_square, P_EMPTY};
|
return Move{square, target_square, P_EMPTY};
|
||||||
|
|
@ -165,15 +165,15 @@ Move Movegen::generate_pawn() {
|
||||||
direction = 3;
|
direction = 3;
|
||||||
offset = color ? -0x11 : 0xF;
|
offset = color ? -0x11 : 0xF;
|
||||||
target_square = square + offset;
|
target_square = square + offset;
|
||||||
target = field[target_square];
|
target = Board::field[target_square];
|
||||||
if(!(target_square & 0x88)) {
|
if(!(target_square & 0x88)) {
|
||||||
if(target && (target & 0x8) != (field[square] & 0x8)) {
|
if(target && (target & 0x8) != (Board::field[square] & 0x8)) {
|
||||||
// normal capture allowded
|
// normal capture allowded
|
||||||
return Move{square, target_square, P_EMPTY};
|
return Move{square, target_square, P_EMPTY};
|
||||||
} else if(field[PTR_ENPASSANT]) {
|
} else if(Board::field[PTR_ENPASSANT]) {
|
||||||
// note that EP being legal only happens
|
// note that EP being legal only happens
|
||||||
// when the target field is empty. so this saves some effort.
|
// when the target field is empty. so this saves some effort.
|
||||||
byte ep_col = field[PTR_ENPASSANT] & 0x7;
|
byte ep_col = Board::field[PTR_ENPASSANT] & 0x7;
|
||||||
if(
|
if(
|
||||||
ep_col == (target_square & 0x7) &&
|
ep_col == (target_square & 0x7) &&
|
||||||
(square & 0x70) == (color ? 0x30 : 0x40)
|
(square & 0x70) == (color ? 0x30 : 0x40)
|
||||||
|
|
@ -189,15 +189,15 @@ Move Movegen::generate_pawn() {
|
||||||
direction = 4;
|
direction = 4;
|
||||||
offset = color ? -0xF : 0x11;
|
offset = color ? -0xF : 0x11;
|
||||||
target_square = square + offset;
|
target_square = square + offset;
|
||||||
target = field[target_square];
|
target = Board::field[target_square];
|
||||||
if(!(target_square & 0x88)) {
|
if(!(target_square & 0x88)) {
|
||||||
if(target && (target & 0x8) != (field[square] & 0x8)) {
|
if(target && (target & 0x8) != (Board::field[square] & 0x8)) {
|
||||||
// normal capture allowded
|
// normal capture allowded
|
||||||
return Move{square, target_square, P_EMPTY};
|
return Move{square, target_square, P_EMPTY};
|
||||||
} else if(field[PTR_ENPASSANT]) {
|
} else if(Board::field[PTR_ENPASSANT]) {
|
||||||
// note that EP being legal only happens
|
// note that EP being legal only happens
|
||||||
// when the target field is empty. so this saves some effort.
|
// when the target field is empty. so this saves some effort.
|
||||||
byte ep_col = field[PTR_ENPASSANT] & 0x7;
|
byte ep_col = Board::field[PTR_ENPASSANT] & 0x7;
|
||||||
if(
|
if(
|
||||||
ep_col == (target_square & 0x7) &&
|
ep_col == (target_square & 0x7) &&
|
||||||
(square & 0x70) == (color ? 0x30 : 0x40)
|
(square & 0x70) == (color ? 0x30 : 0x40)
|
||||||
|
|
@ -213,7 +213,7 @@ Move Movegen::generate_pawn() {
|
||||||
direction = 5;
|
direction = 5;
|
||||||
offset = color ? -0x10 : 0x10;
|
offset = color ? -0x10 : 0x10;
|
||||||
target_square = square + offset;
|
target_square = square + offset;
|
||||||
target = field[target_square];
|
target = Board::field[target_square];
|
||||||
if(target && (target_square & 0x70) == (color ? 0x70 : 0x00)) {
|
if(target && (target_square & 0x70) == (color ? 0x70 : 0x00)) {
|
||||||
// we can promote!
|
// we can promote!
|
||||||
return Move{square, target_square, (Piece)(W_QUEN | color << 3)};
|
return Move{square, target_square, (Piece)(W_QUEN | color << 3)};
|
||||||
|
|
|
||||||
3
Uci.h
3
Uci.h
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#define PS2(s) ([]{ static const char c[] PROGMEM = (s); return &c[0]; }())
|
#define PS2(s) ([]{ static const char c[] PROGMEM = (s); return &c[0]; }())
|
||||||
|
|
||||||
|
namespace Uci {
|
||||||
typedef void uci_return;
|
typedef void uci_return;
|
||||||
typedef uci_return (*uci_handler)();
|
typedef uci_return (*uci_handler)();
|
||||||
|
|
||||||
|
|
@ -115,6 +116,6 @@ uci_return handle_uci() {
|
||||||
clear_line();
|
clear_line();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue