I made this fun little project to test out Groq and learn how to use AI function calling in a real app. It's basically Rock-Paper-Scissors but with a twist: the moves actually do things like dealing damage or healing, and you're fighting a pretty smart AI! ๐๏ธ๐ฅ
- โญ Smart AI: Powered by Groq, the AI actually thinks about its moves based on the game state.
- ๐ฅ Combat System: Moves aren't just for winning roundsโRock blocks damage, Paper heals you, and Scissors deals heavy damage!
- ๐ง AI Reasoning: You can see exactly why the AI made its choice after every turn.
- ๐ Battle History: Automatically saves your games so you can look back at your epic wins (or sad losses).
- ๐ Exportable Logs: Download your battle history as a clean Text file or a JSON file.
- ๐จ Beautiful UI: Built with DaisyUI for a clean, modern look with dark mode support.
- Svelte 5: Using the new Runes system for super smooth state management.
- SvelteKit: The framework keeping everything snappy.
- Groq SDK: The "brain" behind the AI opponent.
- Tailwind CSS & DaisyUI: For the pretty colors and layout.
- TypeScript: To keep the code clean and bug-free.
src/lib/game.svelte.ts: This is where all the game logic and rules live.src/routes/game: The main screen where you actually battle the AI.src/routes/history: A list of all your past matches.src/routes/api/ai: The secret sauce that talks to Groq.static/: All the icons and images used in the game.
It's easy to play, but hard to master! Both you and the AI start with 10 HP.
- Rock ๐ชจ: Blocks any incoming damage for that turn.
- Paper ๐: Heals you for 1 HP, but be carefulโif the opponent plays Scissors, you take damage instead!
- Scissors โ๏ธ: Deals 2 damage to your opponent.
- Goal: Bring the AI's HP down to 0 before it does the same to you!
- Clone the project: Grab the code from GitHub.
- Install dependencies: Run
npm installin your terminal. - Set up your API Key: Create a file named
.envin the root folder and add your Groq key like this:GROQ_API_KEY=your_key_here
- Start the game: Run
npm run devand open the link in your browser!
Have fun battling the AI! ๐โจ