#include #include #include #define TAM 3 typedef struct piece { int up; int down; struct piece *next; }Piece; typedef struct player { Piece *hand; struct player *next; }Player; Player *start() { Player *player = (Player*) malloc(sizeof(Player)); player->hand = (Piece*) malloc(TAM*sizeof(Piece)); int i; for(i = 0; ihand[i].up = rand() % 7; srand( rand() ); player->hand[i].down = rand() % 7; } return player; } int starting_value(Player player) { int i, cont = 0; for(i = 0; inext = player_two; player_two->next = player_one; //print_pieces(player_one->hand); //print_pieces(player_two->hand); one_max = starting_value(*player_one); two_max = starting_value(*player_two); //printf("%d, %d", one_max, two_max); if(one_max >= two_max) { current_player = player_one; } else { current_player = player_two; } printf("\n(%d -> %d)",starting_value(*current_player),starting_value(*(current_player->next))); do { if(left == -1 && right == -1) { print_pieces(current_player->hand); printf("This is the first turn, so you can select any piece to play.\n"); printf("Select a piece to play:\n1 - fisrt\n2 - second\n3 - third\n"); scanf("%d",&selected_piece); if(selected_piece == 1 || selected_piece == 2 || selected_piece == 3) { left = current_player->hand[selected_piece-1].up; right = current_player->hand[selected_piece-1].down; printf("\nSucess!"); cont--; } else { printf("\nThis is not a valid choice!"); } } else { print_pieces(current_player->hand); printf("You have two options: %d or %d",left, right); printf("Select a piece to play:\n1 - fisrt\n2 - second\n3 - third\n"); scanf("%d",&selected_piece); printf("Select a direction to play:\n1 - left\n2 - right\n"); scanf("%d",&selected_direction); if(selected_piece == 1 || selected_piece == 2 || selected_piece == 3) { if(selected_direction == 1) { if(current_player->hand[selected_direction-1].up == left) { } else if(current_player->hand[selected_direction-1].down == left) { } else { } } else if(selected_direction == 2) { if(current_player->hand[selected_direction-1].up == right) { } else if(current_player->hand[selected_direction-1].down == right) { } else { } } else { } } else { } } }while(cont>0); return 0; }