|
|
|
@ -24,26 +24,49 @@ int free_spaces(); |
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]){ |
|
|
|
|
char flag = ' '; |
|
|
|
|
int players; |
|
|
|
|
clear_board(); |
|
|
|
|
|
|
|
|
|
do{ |
|
|
|
|
flag = check_win(); |
|
|
|
|
if(free_spaces() == 0){ |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
printf("How many players? (1/2)\n> "); |
|
|
|
|
scanf("%d", &players); |
|
|
|
|
|
|
|
|
|
//this could be tidier i think
|
|
|
|
|
if(players == 1){ |
|
|
|
|
do{ |
|
|
|
|
flag = check_win(); |
|
|
|
|
if(free_spaces() == 0){ |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
print_board(); |
|
|
|
|
|
|
|
|
|
player_choice('X'); |
|
|
|
|
print_board(); |
|
|
|
|
|
|
|
|
|
print_board(); |
|
|
|
|
cpu_choice('O'); |
|
|
|
|
flag = check_win(); |
|
|
|
|
print_board(); |
|
|
|
|
|
|
|
|
|
player_choice('X'); |
|
|
|
|
flag = check_win(); |
|
|
|
|
print_board(); |
|
|
|
|
} while(flag == ' '); |
|
|
|
|
|
|
|
|
|
player_choice('O'); |
|
|
|
|
flag = check_win(); |
|
|
|
|
print_board(); |
|
|
|
|
} else if(players == 2){ |
|
|
|
|
do{ |
|
|
|
|
flag = check_win(); |
|
|
|
|
if(free_spaces() == 0){ |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} while(flag == ' '); |
|
|
|
|
print_board(); |
|
|
|
|
|
|
|
|
|
player_choice('X'); |
|
|
|
|
print_board(); |
|
|
|
|
|
|
|
|
|
player_choice('O'); |
|
|
|
|
flag = check_win(); |
|
|
|
|
print_board(); |
|
|
|
|
|
|
|
|
|
} while(flag == ' '); |
|
|
|
|
} |
|
|
|
|
if(flag == ' ')
|
|
|
|
|
printf(BOLDMAGENTA "\nNo-one won!" RESET); |
|
|
|
|
else |
|
|
|
|