#include #include #include bool check_str_is_int(char *s) { while (*s != '\0') { char a = *s - '0'; if (a < 0 || a > 9) return false; s++; } return true; } void usage(char *arg0, int ret) { printf("USAGE:\n%s [starting life total]\nruns through games of ragavan vs bolt\n", arg0); exit(ret); } typedef enum { Ragavan, Bolt } SpellType; typedef struct { int life_total; int deck_mountains; int deck_spells; int hand_mountains; int hand_spells; SpellType spell_type; } Player; Player *new_player(int life_total, SpellType spell_type) { Player *p = malloc(sizeof(Player)); *p = (Player) { .life_total = life_total, .deck_mountains = 20, .deck_spells = 40, .hand_mountains = 0, .hand_spells = 0, .spell_type = spell_type }; return p; } int main(int argc, char **argv) { int max_life; if (argc < 2) { max_life = 20; } else { if(!check_str_is_int(argv[1])) usage(*argv, 1); max_life = atoi(*argv); } printf("%d\n", max_life); Player *stupid_fucking_monkey = new_player(max_life, Ragavan); Player *sparky = new_player(max_life, Bolt); free(stupid_fucking_monkey); free(sparky); return 0; }