feat: added check_line for player win detection

This commit is contained in:
DarthMooMancer
2025-09-02 13:38:40 -04:00
parent 18773da6c4
commit 9546b47d82
6 changed files with 47 additions and 14 deletions
+20 -4
View File
@@ -15,7 +15,23 @@ void Point::to_string() {
std::cout << "(" << m_row << ", " << m_col << ")" << std::endl;
}
// Tile::Tile(int row, int col) {
// m_pos.assign(row, col);
// m_symbol = ' ';
// }
void Player::check_line(Tile (&tile_list)[9]) {
for(int i = 0; i <= 6; i += 3) {
if(tile_list[i].m_symbol == tile_list[i+1].m_symbol && tile_list[i+1].m_symbol == tile_list[i+2].m_symbol) {
if(tile_list[i].m_symbol == m_symbol) {
m_win = true;
}
}
}
if(tile_list[0].m_symbol == tile_list[4].m_symbol && tile_list[4].m_symbol == tile_list[8].m_symbol) {
if(tile_list[0].m_symbol == m_symbol) {
m_win = true;
}
}
if(tile_list[2].m_symbol == tile_list[4].m_symbol && tile_list[4].m_symbol == tile_list[6].m_symbol) {
if(tile_list[2].m_symbol == m_symbol) {
m_win = true;
}
}
}