Put more stuff in namespaces
This commit is contained in:
parent
21e956519e
commit
e00f9231fb
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
board_init();
|
||||
Board::init();
|
||||
Serial.begin(115200);
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
//perft_test();
|
||||
|
|
@ -21,5 +21,5 @@ void setup() {
|
|||
|
||||
void loop() {
|
||||
// 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 "Move.h"
|
||||
|
||||
namespace Board {
|
||||
|
||||
#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_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;
|
||||
|
||||
void board_init() {
|
||||
void init() {
|
||||
for(int i = 0; i < 128; i++) {
|
||||
field[i] = pgm_read_byte_near(field_default_value + i);
|
||||
}
|
||||
|
|
@ -288,5 +290,7 @@ void unmake() {
|
|||
field[PTR_ENPASSANT] = u.captured >> 4;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
|||
38
Movegen.h
38
Movegen.h
|
|
@ -28,11 +28,11 @@ Move Movegen::next_move() {
|
|||
while(square <= 0x77) {
|
||||
if(square & 0x88) square += 8;
|
||||
|
||||
byte piece_type = field[square] & 0x7;
|
||||
byte piece_type = Board::field[square] & 0x7;
|
||||
|
||||
if(
|
||||
(field[square] & 0x7) &&
|
||||
(field[square] & 0x8) == black_moving() << 3
|
||||
(Board::field[square] & 0x7) &&
|
||||
(Board::field[square] & 0x8) == Board::black_moving() << 3
|
||||
) {
|
||||
// there is an own piece to investigate
|
||||
Move m;
|
||||
|
|
@ -78,8 +78,8 @@ Move Movegen::generate_sliding(byte piece_type) {
|
|||
}
|
||||
// currently, we are at the next move target
|
||||
// this means: we can try to generate this as a move!
|
||||
byte piece = field[square];
|
||||
byte target = field[target_square];
|
||||
byte piece = Board::field[square];
|
||||
byte target = Board::field[target_square];
|
||||
if(target) {
|
||||
// we encountered a piece! there are two outcomes here:
|
||||
// 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++;
|
||||
|
||||
byte target = field[target_square];
|
||||
byte piece = field[square];
|
||||
byte target = Board::field[target_square];
|
||||
byte piece = Board::field[square];
|
||||
|
||||
if((target_square & 0x88) || (target && (target & 0x8) == (piece & 0x8))) {
|
||||
// uh oh, off board or same color obstacle
|
||||
|
|
@ -125,7 +125,7 @@ Move Movegen::generate_non_sliding(byte piece_type) {
|
|||
Move Movegen::generate_pawn() {
|
||||
// TODO: implement capture promotion
|
||||
|
||||
byte color = black_moving();
|
||||
byte color = Board::black_moving();
|
||||
byte offset;
|
||||
byte target;
|
||||
GP_START:
|
||||
|
|
@ -135,7 +135,7 @@ Move Movegen::generate_pawn() {
|
|||
direction = 1; // next try, go ahead further
|
||||
offset = color ? -0x10 : 0x10;
|
||||
target_square = square + offset;
|
||||
if(field[target_square] ||
|
||||
if(Board::field[target_square] ||
|
||||
(square & 0x70) == (color ? 0x10 : 0x60)
|
||||
) {
|
||||
// moving ahead is not possible, not even a capture!
|
||||
|
|
@ -152,7 +152,7 @@ Move Movegen::generate_pawn() {
|
|||
direction = 2;
|
||||
offset = color ? -0x20 : 0x20;
|
||||
target_square = square + offset;
|
||||
if(!(field[target_square]) &&
|
||||
if(!(Board::field[target_square]) &&
|
||||
(square & 0x70) == (color ? 0x60 : 0x10)
|
||||
) {
|
||||
return Move{square, target_square, P_EMPTY};
|
||||
|
|
@ -165,15 +165,15 @@ Move Movegen::generate_pawn() {
|
|||
direction = 3;
|
||||
offset = color ? -0x11 : 0xF;
|
||||
target_square = square + offset;
|
||||
target = field[target_square];
|
||||
target = Board::field[target_square];
|
||||
if(!(target_square & 0x88)) {
|
||||
if(target && (target & 0x8) != (field[square] & 0x8)) {
|
||||
if(target && (target & 0x8) != (Board::field[square] & 0x8)) {
|
||||
// normal capture allowded
|
||||
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
|
||||
// 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(
|
||||
ep_col == (target_square & 0x7) &&
|
||||
(square & 0x70) == (color ? 0x30 : 0x40)
|
||||
|
|
@ -189,15 +189,15 @@ Move Movegen::generate_pawn() {
|
|||
direction = 4;
|
||||
offset = color ? -0xF : 0x11;
|
||||
target_square = square + offset;
|
||||
target = field[target_square];
|
||||
target = Board::field[target_square];
|
||||
if(!(target_square & 0x88)) {
|
||||
if(target && (target & 0x8) != (field[square] & 0x8)) {
|
||||
if(target && (target & 0x8) != (Board::field[square] & 0x8)) {
|
||||
// normal capture allowded
|
||||
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
|
||||
// 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(
|
||||
ep_col == (target_square & 0x7) &&
|
||||
(square & 0x70) == (color ? 0x30 : 0x40)
|
||||
|
|
@ -213,7 +213,7 @@ Move Movegen::generate_pawn() {
|
|||
direction = 5;
|
||||
offset = color ? -0x10 : 0x10;
|
||||
target_square = square + offset;
|
||||
target = field[target_square];
|
||||
target = Board::field[target_square];
|
||||
if(target && (target_square & 0x70) == (color ? 0x70 : 0x00)) {
|
||||
// we can promote!
|
||||
return Move{square, target_square, (Piece)(W_QUEN | color << 3)};
|
||||
|
|
|
|||
Loading…
Reference in New Issue