#include <stdio.h>
#include <stdlib.h>
#include <time.h>

const char *major_arcana[22] = {
  "0 - The Fool", "1 - The Magician", "2 - The High Priestess", "3 - The Empress",
  "4 - The Emperor", "5 - The Hierophant", "6 - The Lovers", "7 - The Chariot",
  "8 - Strength", "9 - The Hermit", "10 - Wheel of Fortune", "11 - Justice",
  "12 - The Hanged Man", "13 - Death", "14 - Temperance", "15 - The Devil",
  "16 - The Tower", "17 - The Star", "18 - The Moon", "19 - The Sun",
  "20 - Judgment", "21 - The World"
};

const char *suits[4] = {"Wands", "Cups", "Swords", "Pentacles"};

const char *ranks[14] = {
  "Ace", "Two", "Three", "Four", "Five", "Six", "Seven",
  "Eight", "Nine", "Ten", "Page", "Knight", "Queen", "King"
};

void draw_tarot_card() {
  // 22 Major Arcana + 56 Minor Arcana = 78 cards total
  int card_index = rand() % 78;
  int is_reversed = rand() % 2; // 0 = Upright, 1 = Reversed
  const char *orientation = is_reversed ? "Reversed" : "Upright";

  if (card_index < 22) {
    printf("Card Drawn: %s (%s)\n", major_arcana[card_index], orientation);
  } else {
    int minor_index = card_index - 22;
    int suit_index = minor_index / 14;
    int rank_index = minor_index % 14;
    printf("Card Drawn: %s of %s (%s)\n", ranks[rank_index], suits[suit_index], orientation);
  }
}

int main() {
  char choice;
  // Seed the random number generator
  srand((unsigned int)time(NULL));

  printf("=== Simple C Tarot Card Drawer ===\n");

  do {
    draw_tarot_card();
    printf("\nDraw another card? (y/n): ");
    scanf(" %c", &choice);
  } while (choice == 'y' || choice == 'Y');

  printf("Blessed be!\n");
  return 0;
}
