Initial commit

This commit is contained in:
2025-05-28 09:31:58 -05:00
commit 26419756f3
2 changed files with 60 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/game

59
game.c Normal file
View File

@ -0,0 +1,59 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
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);
return 0;
}