Skip to content

Instantly share code, notes, and snippets.

@JaiSuryaPrabu
Created August 20, 2024 15:32
Show Gist options
  • Save JaiSuryaPrabu/826043dc5b0b0cb2f38624c9b370fba8 to your computer and use it in GitHub Desktop.
Save JaiSuryaPrabu/826043dc5b0b0cb2f38624c9b370fba8 to your computer and use it in GitHub Desktop.
Tic Tac Toe function for checking the player is won or not
fn check_win(player : String, board : Vec<String>) -> bool{
let mut is_win = false;
if board[0] == player && board[1] == player && board[2] == player {
is_win = true;
} else if board[3] == player && board[4] == player && board[5] == player {
is_win = true;
} else if board[6] == player && board[7] == player && board[8] == player {
is_win = true;
} else if board[0] == player && board[3] == player && board[6] == player {
is_win = true;
} else if board[1] == player && board[4] == player && board[7] == player {
is_win = true;
} else if board[2] == player && board[5] == player && board[8] == player {
is_win = true;
} else if board[0] == player && board[4] == player && board[8] == player {
is_win = true;
} else if board[2] == player && board[4] == player && board[6] == player {
is_win = true;
}
return is_win;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment