i want to create a little website game called "guess the ai model". in this game the player gets to see the prompt and the response from the llm. after that, the user has the option to decide between 3 ai models. one of these 3 options included the actual model the response was generated with and the player has to guess it correctly. if he does, his score is up and he will go onto the next prompt and response. if he doesn't, his score resets and he has to restart with a score of one. his high score will still be shown and the player is incentivised to beat his high score. could you try and create a game like that for me? you can use filler text for the prompt and the response. i can add in the prompt and the response later.
Assistant
Sure! I'd be happy to help you create a simple web-based game called "Guess the AI Model". Below, I'll provide you with the HTML, CSS, and JavaScript code to set up the game. You can replace the placeholder prompts and responses with your actual content later.
Overview
The game will display:
A prompt given to an AI model.
The response generated by the model.
Three options for the user to guess which AI model produced the response.
The player's score increases with each correct guess. If the player guesses incorrectly, the score resets to zero. The high score is displayed and persists between sessions using localStorage.
Files and Code
1. index.html
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Guess the AI Model</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="game-container">
<h1>Guess the AI Model</h1>
<div class="scoreboard">
<p>Score: <span id="score">0</span></p>
<p>High Score: <span id="high-score">0</span></p>
</div>
<div class="prompt-response">
<h2>Prompt:</h2>
<p id="prompt-text"></p>
<h2>Response:</h2>
<p id="response-text"></p>
</div>
<div class="choices">
<h2>Which AI model generated this response?</h2>
<div id="choice-buttons"></div>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
// Placeholder data - replace with your actual prompts, responses, and models
const data = [
{
prompt: "Write a short poem about the ocean.",
response: "The waves dance under the moon's gentle gaze, whispering secrets.",
correctModel: "OceanGPT",
options: ["NatureAI", "PoetBot", "OceanGPT"]
},
{
prompt: "Explain the theory of relativity in simple terms.",
response: "Energy and mass are interchangeable; as objects move faster, time slows down for them.",
correctModel: "SmartModel X",
options: ["EinsteinAI", "SmartModel X", "RelativityBot"]
},
// Add more data objects here
];
let currentIndex = 0;
let currentScore = 0;
let highScore = 0;
// Load high score from localStorage
function loadHighScore() {
const savedHighScore = localStorage.getItem('highScore');
if (savedHighScore !== null) {
highScore = parseInt(savedHighScore);
document.getElementById('high-score').innerText = highScore;
}
}
// Save high score to localStorage
function saveHighScore() {
localStorage.setItem('highScore', highScore);
}
// Update the score display
function updateScoreDisplay() {
document.getElementById('score').innerText = currentScore;
document.getElementById('high-score').innerText = highScore;
}
// Load the current question
function loadQuestion() {
if (currentIndex >= data.length) {
currentIndex = 0; // Restart from the first question
}
const currentData = data[currentIndex];
// Display prompt and response
document.getElementById('prompt-text').innerText = currentData.prompt;
document.getElementById('response-text').innerText = currentData.response;
// Display choice buttons
const choiceButtonsDiv = document.getElementById('choice-buttons');
choiceButtonsDiv.innerHTML = ''; // Clear previous choices
// Shuffle options
const shuffledOptions = currentData.options.sort(() => Math.random() - 0.5);
shuffledOptions.forEach(option => {
const button = document.createElement('button');
button.classList.add('choice-button');
button.innerText = option;
button.addEventListener('click', () => handleChoice(option));
choiceButtonsDiv.appendChild(button);
});
}
// Handle the user's choice
function handleChoice(selectedOption) {
const currentData = data[currentIndex];
if (selectedOption === currentData.correctModel) {
currentScore++;
if (currentScore > highScore) {
highScore = currentScore;
saveHighScore();
}
alert('Correct!');
} else {
alert(`Incorrect! The correct answer was "${currentData.correctModel}".`);
currentScore = 0;
}
updateScoreDisplay();
currentIndex++;
loadQuestion();
}
// Initialize the game
function initGame() {
loadHighScore();
updateScoreDisplay();
loadQuestion();
}
// Start the game when the page loads
window.addEventListener('load', initGame);
Instructions to Customize the Game
1. Replace Placeholder Data
In the script.js file, replace the placeholder data with your actual prompts, responses, and models.
Example:
javascript
const data = [
{
prompt: "Your first prompt here.",
response: "Response from the AI model.",
correctModel: "ActualModelName",
options: ["ActualModelName", "OtherModel1", "OtherModel2"]
},
{
prompt: "Your second prompt here.",
response: "Another response from the AI model.",
correctModel: "DifferentModel",
options: ["ModelA", "ModelB", "DifferentModel"]
},
// Add more data objects as needed
];
prompt: The text provided to the AI model.
response: The AI model's response.
correctModel: The name of the model that generated the response.
options: An array containing three model names, including the correct one.
Make sure that correctModel matches one of the options in the options array.
2. Add More Questions
To make the game more engaging, add as many prompt-response pairs as you like to the data array.
3. Customize the Appearance
You can modify the styles.css file to change the look and feel of the game. Adjust colors, fonts, and layout to match your preferences or branding.
4. Deploy the Game
Option 1: Run Locally
Save the index.html, styles.css, and script.js files in the same folder.
Open index.html in a web browser to play the game.
Option 2: Host Online
Upload the files to a web hosting service or server.
For free hosting, consider using platforms like GitHub Pages.
5. Test the Game
Ensure that the prompt and response display correctly.
Click on the choices to test if the score updates as expected.
Verify that the high score persists after refreshing the page.
Additional Features (Optional)
Feedback Messages
You can enhance user experience by providing more detailed feedback after each guess.
In the handleChoice function in script.js, replace the alert messages with custom modal dialogs or on-page messages.
Randomize Question Order
To present questions in random order, shuffle the data array before starting the game:
javascript
function shuffleData() {
data.sort(() => Math.random() - 0.5);
}
function initGame() {
shuffleData();
loadHighScore();
updateScoreDisplay();
loadQuestion();
}
Limit Repeats
To prevent repeating the same questions within a session, keep track of asked questions:
javascript
let askedQuestions = [];
function loadQuestion() {
if (askedQuestions.length === data.length) {
askedQuestions = []; // Reset if all questions have been asked
}
// Get a random index that hasn't been used yet
let randomIndex;
do {
randomIndex = Math.floor(Math.random() * data.length);
} while (askedQuestions.includes(randomIndex));
askedQuestions.push(randomIndex);
currentIndex = randomIndex;
// ... rest of the loadQuestion function ...
}
Notes
High Score Storage: The high score is stored in the browser's localStorage, so it will persist between sessions on the same device and browser.
Browser Compatibility: Ensure that users are using modern browsers for the best experience.
Testing: After making changes, test the game thoroughly to ensure everything works as intended.
Need Further Assistance?
If you have any questions or need help customizing the game further—such as adding features, improving the design, or troubleshooting issues—feel free to ask!