philRG

Starter FC 2020 (langage C)

Apr 28th, 2021 (edited)
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.97 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdbool.h>
  5.  
  6.  
  7. typedef struct {
  8.     int id;
  9.     char *type;
  10.     int delta[4];
  11.     int price, tome_index, tax_count;
  12.     bool castable, repeatable;
  13. } ACTION;
  14.  
  15. typedef struct {
  16.     int inv[4];
  17.     int score;
  18. } INVENTORY;
  19.  
  20.  
  21. int main() {
  22.  
  23.     INVENTORY myInv;
  24.     ACTION firstAction;
  25.     ACTION lastAction;
  26.  
  27.     // game loop
  28.     while (1) {
  29.         // the number of spells and recipes in play
  30.         int action_count;
  31.         scanf("%d", &action_count);
  32.         fprintf(stderr, "%d\n", action_count);
  33.  
  34.         ACTION *actions = (ACTION *) malloc(action_count * sizeof(ACTION));
  35.         INVENTORY *invs = (INVENTORY *) malloc(action_count * sizeof(INVENTORY));
  36.  
  37.         for (int i = 0; i < action_count; i++) {
  38.  
  39.             // the unique ID of this spell or recipe
  40.             int action_id;
  41.             // in the first league: BREW; later: CAST, OPPONENT_CAST, LEARN, BREW
  42.             char action_type[21];
  43.             // tier-0 ingredient change
  44.             int delta_0;
  45.             // tier-1 ingredient change
  46.             int delta_1;
  47.             // tier-2 ingredient change
  48.             int delta_2;
  49.             // tier-3 ingredient change
  50.             int delta_3;
  51.             // the price in rupees if this is a potion
  52.             int price;
  53.             // in the first two leagues: always 0; later: the index in the tome if this is a tome spell, equal to the read-ahead tax; For brews, this is the value of the current urgency bonus
  54.             int tome_index;
  55.             // in the first two leagues: always 0; later: the amount of taxed tier-0 ingredients you gain from learning this spell; For brews, this is how many times you can still gain an urgency bonus
  56.             int tax_count;
  57.             // in the first league: always 0; later: 1 if this is a castable player spell
  58.             bool castable;
  59.             // for the first two leagues: always 0; later: 1 if this is a repeatable player spell
  60.             bool repeatable;
  61.             int _castable;
  62.             int _repeatable;
  63.             scanf("%d%s%d%d%d%d%d%d%d%d%d", &action_id, action_type, &delta_0, &delta_1, &delta_2, &delta_3, &price,
  64.                   &tome_index, &tax_count, &_castable, &_repeatable);
  65.             fprintf(stderr, "%d %s %d %d %d %d %d %d %d %d %d\n", action_id, action_type, delta_0, delta_1, delta_2, delta_3, price,
  66.                     tome_index, tax_count, _castable, _repeatable);
  67.  
  68.             ACTION action = {
  69.                     .id = action_id,
  70.                     .type = action_type,
  71.                     .delta = {delta_0, delta_1, delta_2, delta_3},
  72.                     .price = price,
  73.                     .tome_index = tome_index,
  74.                     .tax_count = tax_count,
  75.                     .repeatable = repeatable
  76.             };
  77.             //*(actions + i) = action;
  78.             actions[i] = action;
  79.         }
  80.  
  81.         for (int i = 0; i < 2; i++) {
  82.             // tier-0 ingredients in inventory
  83.             int inv_0;
  84.             int inv_1;
  85.             int inv_2;
  86.             int inv_3;
  87.             // amount of rupees
  88.             int score;
  89.             scanf("%d%d%d%d%d", &inv_0, &inv_1, &inv_2, &inv_3, &score);
  90.             fprintf(stderr, "%d %d %d %d %d\n", inv_0, inv_1, inv_2, inv_3, score);
  91.             INVENTORY inv = {
  92.                     .inv = {inv_0, inv_1, inv_2, inv_3},
  93.                     .score = score
  94.             };
  95.             //*(invs + i) = inv;
  96.             invs[i] = inv;
  97.         }
  98.         myInv = invs[0];
  99.         firstAction = actions[0];
  100.         lastAction = actions[action_count - 1];
  101.         // Write an action using printf(). DON'T FORGET THE TRAILING \n
  102.         // To debug: fprintf(stderr, "Debug messages...\n");
  103.  
  104.         // in the first league: BREW <id> | WAIT; later: BREW <id> | CAST <id> [<times>] | LEARN <id> | REST | WAIT
  105.         printf("BREW 0\n");
  106.  
  107.         free(actions);
  108.         free(invs);
  109.         exit(0);
  110.     }
  111.     return 0;
  112. }
Add Comment
Please, Sign In to add comment