Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enlarged board for outside board detection #133

Open
MarkZH opened this issue Nov 6, 2023 · 3 comments
Open

Enlarged board for outside board detection #133

MarkZH opened this issue Nov 6, 2023 · 3 comments

Comments

@MarkZH
Copy link
Owner

MarkZH commented Nov 6, 2023

Use a board representation that 12x12 to detect when moves are outside the board. The 8x8 actual board sits in the middle. When generating moves step-by-step, the border around the board allows for detection of moves that exit the board without needing if statements based on rank and file calculations. A two-square border is needed for keeping knight moves on the board. This should simplify the below code.

Square& Square::operator+=(const Square_Difference& diff) noexcept
{
assert(std::abs(diff.file_change) < 8 && std::abs(diff.rank_change) < 8);
const square_index_t new_rank_index = square_index + diff.rank_change;
if(new_rank_index/8 != square_index/8) // make sure file did not change (happens if new square is off the board vertically)
{
square_index = invalid_index;
return *this;
}
square_index = new_rank_index + 8*(diff.file_change);
return *this;
}

@MarkZH
Copy link
Owner Author

MarkZH commented Feb 26, 2024

Another important improvement is that Square_Difference only requires a single int to specify the move (the square index difference). The linear algebra operations on Square_Difference (are_parallel(), same_direction()) will need some thought.

@MarkZH
Copy link
Owner Author

MarkZH commented Feb 26, 2024

A 10x12 board with 4 extended ranks and 2 extended files is sufficient because a knight jumping horizontally off the board from the edge will always end on an index that is too large (either through wrapping a negative value off the a-file or landing on a too large index off the h-file.

Reference: https://www.chessprogramming.org/10x12_Board

@MarkZH
Copy link
Owner Author

MarkZH commented Feb 26, 2024

Would a const std::bitset<120> be faster than index comparisons for out-of-board determinations?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant