#pragma once #include #include #include "bitboard.h" #include "types.h" namespace rigby { namespace zobrist { void init(); } // Plain copy-make position. Small enough to copy at every tree step. struct Position { u64 pieces[6] = {}; u64 colors[2] = {}; u8 board[64]; int stm = WHITE; int castling = 0; int ep = NO_SQUARE; // only set when a capture there is pseudo-legal int halfmove = 0; int fullmove = 1; u64 key = 0; Position(); bool set_fen(std::string_view fen); std::string fen() const; void make_move(Move m); u64 occupancy() const { return colors[WHITE] | colors[BLACK]; } u64 pieces_of(int color, int type) const { return pieces[type] & colors[color]; } int king_square(int color) const { return lsb(pieces_of(color, KING)); } int piece_on(int sq) const { return board[sq]; } u64 attackers_to(int sq, u64 occ) const; bool square_attacked(int sq, int by, u64 occ) const; u64 checkers() const { return attackers_to(king_square(stm), occupancy()) & colors[stm ^ 1]; } bool in_check() const { return checkers() != 0; } bool insufficient_material() const; // Returns a null move when the string is not a legal move here. Move parse_uci(std::string_view uci) const; std::string pretty() const; private: void put_piece(int piece, int sq); void remove_piece(int sq); void move_piece(int from, int to); }; void generate_legal(const Position& pos, MoveList& list); // Legal captures (en passant included) and queen promotions, in the order // generate_legal lists them. void generate_noisy(const Position& pos, MoveList& list); // Same as a non-empty generate_legal, but stops at the first move it finds. bool has_legal_move(const Position& pos); } // namespace rigby