Created
June 13, 2021 13:07
-
-
Save mohamad-wael/bccf08194a52565333c2682b9916788f to your computer and use it in GitHub Desktop.
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
private void | |
player_started_play | |
( ){ | |
int coordinates [ ] = null; | |
int machine_row_open_for_win = -1 ; | |
int machine_col_open_for_win = -1 ; | |
int player_row_open_for_win = -1 ; | |
int player_col_open_for_win = -1; | |
if (!is_center_occupied ( ) ){ | |
machine_got_center = true; | |
coordinates = center_coordinates ( ); } | |
if (machine_got_center && turn_count != 2 ){ | |
coordinates = where_a_player_might_win(id_machine); | |
if (coordinates != null ){ | |
id_winner = id_machine; } | |
else{ | |
coordinates = where_a_player_might_win(id_player); | |
if (coordinates == null ){ | |
machine_row_open_for_win = get_row_where_possibility_of_win (id_machine ); | |
player_row_open_for_win = get_row_where_possibility_of_win (id_player ); | |
player_col_open_for_win = get_col_where_possibility_of_win (id_player ); | |
if (machine_row_open_for_win != -1 ) | |
coordinates = get_any_free_coordinate_from_a_row(machine_row_open_for_win ); | |
else if (player_row_open_for_win != -1 && | |
player_col_open_for_win != -1 && | |
player_moves [player_row_open_for_win ] [player_col_open_for_win ] == id_no_player ){ | |
coordinates = new int [ ]{player_row_open_for_win , player_col_open_for_win }; } | |
else | |
coordinates = get_any_open_coordinate ( );}}} | |
else if (!machine_got_center ){ | |
coordinates = where_a_player_might_win (id_machine ); | |
if (coordinates != null ){ | |
id_winner = id_machine; } | |
else{ | |
coordinates = where_a_player_might_win (id_player ); | |
if (coordinates == null ){ | |
machine_row_open_for_win = get_row_where_possibility_of_win(id_machine); | |
machine_col_open_for_win = get_row_where_possibility_of_win(id_machine); | |
if (is_there_a_free_corner( ) ) | |
coordinates = get_random_free_corner( ); | |
else if (machine_row_open_for_win != -1 ) | |
coordinates = get_any_free_coordinate_from_a_row (machine_row_open_for_win ); | |
else if (machine_col_open_for_win != -1 ) | |
coordinates = get_any_free_coordinate_from_a_col (machine_col_open_for_win ); | |
else | |
coordinates = get_any_open_coordinate( );}}} | |
player_moves [coordinates [0 ]] [coordinates [1 ]] = id_machine; | |
turn_machine = !turn_machine; | |
turn_count++; | |
invalidate ( );} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment