1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:07:35 +00:00

Chess: Fix signed/unsigned issues

Make everything signed so that we don't have to deal with silly casting
issues thoughout the Chess code. I am unsure if this affects the chess
AI negatively, it seems just as "intelligent" before and after this
change :^)
This commit is contained in:
Jean-Baptiste Boric 2021-05-16 14:55:20 +02:00 committed by Linus Groh
parent d0eb376520
commit 0262a99a1f
3 changed files with 25 additions and 27 deletions

View file

@ -37,7 +37,7 @@ void ChessWidget::paint_event(GUI::PaintEvent& event)
size_t tile_width = frame_inner_rect().width() / 8;
size_t tile_height = frame_inner_rect().height() / 8;
unsigned coord_rank_file = (side() == Chess::Color::White) ? 0 : 7;
int coord_rank_file = (side() == Chess::Color::White) ? 0 : 7;
Chess::Board& active_board = (m_playback ? board_playback() : board());
@ -362,13 +362,13 @@ void ChessWidget::set_piece_set(const StringView& set)
Chess::Square ChessWidget::mouse_to_square(GUI::MouseEvent& event) const
{
unsigned tile_width = frame_inner_rect().width() / 8;
unsigned tile_height = frame_inner_rect().height() / 8;
int tile_width = frame_inner_rect().width() / 8;
int tile_height = frame_inner_rect().height() / 8;
if (side() == Chess::Color::White) {
return { (unsigned)(7 - (event.y() / tile_height)), (unsigned)(event.x() / tile_width) };
return { 7 - (event.y() / tile_height), event.x() / tile_width };
} else {
return { (unsigned)(event.y() / tile_height), (unsigned)(7 - (event.x() / tile_width)) };
return { event.y() / tile_height, 7 - (event.x() / tile_width) };
}
}