Created
August 20, 2024 15:32
-
-
Save JaiSuryaPrabu/826043dc5b0b0cb2f38624c9b370fba8 to your computer and use it in GitHub Desktop.
Tic Tac Toe function for checking the player is won or not
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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