int main(void){ DDRD |= (1<<THROW) | (1<<BUMP0) | (1<<BUMP1); //Initializing outputs DDRD |= (1<<ENABLE) | (1<<STEP) | (1<<DIRECT); DDRD &= ~(1<<PD1) | ~(1<<PD0); //Initialize inputs PORTD |= (1<<THROW); //Solenoid needs to be down DDRC |= (1<<PC3); //Setting up an output so i can choose the plays DDRC &= ~(1<<PC1) | ~(1<<PC2) | ~(1<<PC0); //Define input pins for plays and offence/defence PORTC |= (1<<PC3); //Always output a 1 //#define Play1 (PINC & (1 << PC1)) do{ if(Defence == 0){ do{ defense(); } while(1); }else if((Play1 == 0) & (Play2 == 0) & (Defence == 1)){ do{ play_1(); } while(1); } } while(1); }
int check_nb_lines(t_var *board) { int nb_no_empty; int res; int *no_empty; nb_no_empty = count_not_empty_lines(board); no_empty = get_filled_lines_id(board, nb_no_empty); if (board->total_allum == 1) play_6(board, no_empty); else if (nb_no_empty == 1) play_1(board, no_empty, nb_no_empty); else if (nb_no_empty == 2) check_2_lines(board, no_empty, nb_no_empty); else if (nb_no_empty == 3) check_3_lines(board, no_empty, nb_no_empty); else check_else(board, no_empty, nb_no_empty); my_free(no_empty); }
void ttt_1(char *host) { int player = 0; CLIENT *clnt; char * *result_1; char *currentboard_1_arg; char **final_board; int *result_2; play_args play_1_arg; int *result_3; char *checkwinner_1_arg; int *result_4; simbolo_args trocarsimbolos_1_arg; int go=0; char simb; #ifndef DEBUG clnt = clnt_create (host, TTT, V1, "udp"); if (clnt == NULL) { clnt_pcreateerror (host); exit (1); } #endif /* DEBUG */ result_4 = trocarsimbolos_1(&trocarsimbolos_1_arg, clnt); if(result_4 == (int*) NULL){ clnt_perror(clnt,"call failed"); } printf("Introduza o seu símbolo: "); scanf(" %c", &simb); trocarsimbolos_1_arg.simbolo1 = simb; printf("Introduza o seu símbolo: "); scanf(" %c", &simb); trocarsimbolos_1_arg.simbolo2 = simb; do{ do{ result_1 = currentboard_1((void*)¤tboard_1_arg,clnt); if(result_1 == (char**)NULL) clnt_perror(clnt,"call failed"); printf("%s\n",*result_1); printf("\nPlayer %d, please enter the number of the square " "where you want to place your %c (or 0 to refresh the board): ", player,(player==1)?trocarsimbolos_1_arg.simbolo1:trocarsimbolos_1_arg.simbolo2); scanf(" %d", &go); if(go==0) continue; play_1_arg.row=--go/3; play_1_arg.column=go%3; play_1_arg.player = player; printf("LINHA:%d\n",play_1_arg.row); printf("COL:%d\n",play_1_arg.column); printf("PLAYER:%d\n",play_1_arg.player); result_2 = play_1(&play_1_arg,clnt); if(result_2 == (int*)NULL) clnt_perror(clnt, "call failed"); if(*result_2 != 0) printf("Invalid move. Try Again...\n"); }while(*result_2 == 0); result_3 = checkwinner_1((void*)&checkwinner_1_arg, clnt); if(result_3 == (int*)NULL){ clnt_perror(clnt,"call failed"); } player = (player+1)%2; }while(*result_3==-1); final_board=currentboard_1(¤tboard_1_arg,clnt); if(final_board == (char**)NULL){ clnt_perror(clnt, "call failed"); } printf("%s\n",*result_3); if(*result_3==2) printf("\nHow boring, it is a draw\n"); else printf("\nCongratulations, player %d, YOU ARE THE WINNER!\n", *result_3); #ifndef DEBUG clnt_destroy (clnt); #endif /* DEBUG */ }