Understand the systems and calculations that power Daily GeoGame.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/igorek05m/daily-geogame/llms.txt
Use this file to discover all available pages before exploring further.
Guess validation
Country matching
When you submit a guess, the game:- Normalizes your input (converts to lowercase, trims whitespace)
- Searches the country database for an exact name match
- Validates against 195+ countries from the RestCountries API
- Rejects the guess if the country name is invalid or already guessed
Duplicate prevention
The game tracks all your guesses in the session and prevents duplicate entries. If you try to guess the same country twice, you’ll see an “Already guessed!” alert.Distance calculation
Haversine formula
Daily GeoGame uses the Haversine formula to calculate the great-circle distance between two points on a sphere (Earth). This provides accurate distances between countries based on their geographic centers.app/lib/geoUtils.ts:5 for the implementation.
Distances are calculated from the latitude/longitude coordinates of each country’s geographic center, not political capitals.
Bearing and direction
Direction calculation
The bearing angle determines which direction to travel from your guess to reach the target country. The game calculates this using trigonometric functions on the latitude/longitude coordinates.app/lib/geoUtils.ts:33 for the implementation.
Visual representation
The bearing angle rotates an arrow icon (↑) using CSS transforms. An angle of 0° points north, 90° points east, 180° points south, and 270° points west.Neighbor highlighting
Border detection
The game identifies neighboring countries using ISO 3166-1 alpha-3 country codes. When you make a guess, the system:- Retrieves the target country’s
bordersarray (e.g.,["DEU", "CZE", "SVK"]for Poland) - Checks if your guessed country’s alpha-3 code is in that array
- Highlights the guess with a yellow pin icon if it’s a neighbor
- Updates the map to visually show border countries
app/api/progress/route.ts:44-48 for the connection logic.
Geographic hierarchy
If your guess isn’t a neighbor, the game checks broader geographic connections:- Subregion match: Same subregion (e.g., “Central Europe”)
- Region match: Same continent (e.g., “Europe”)
- No connection: Different region entirely
Progressive hint system
Hint generation
Hints are generated when the daily game is created (at midnight UTC). The system:- Fetches data from the CIA World Factbook using the country’s FIPS code
- Organizes facts into themed packages (Geography, Economy, People, etc.)
- Extracts specific data points (climate, terrain, GDP, population, etc.)
- Stores up to 6 hint packages in the database
app/api/daily/route.ts:114 for hint generation.
Hint unlocking
The unlock mechanism is controlled server-side to prevent cheating:app/api/daily/route.ts:139-156 for the unlock implementation.
Session persistence
Anonymous session tracking
Daily GeoGame uses session cookies to save your progress without requiring login:- On your first visit, the server generates a UUID session ID
- The ID is stored in a secure, HTTP-only cookie (
geo_session) - Your guesses, wins, and stats are linked to this session ID in MongoDB
- The cookie persists for 10 years (
maxAge: 60 * 60 * 24 * 365 * 10)
app/api/progress/route.ts:18-22 for session creation.
Progress saving
After each guess, the game saves your progress via POST to/api/progress:
Progress is stored per date, so you can play previous days’ games and each maintains separate progress.
Daily reset
Country selection
Every day at midnight UTC, a new country is selected:- The game randomly picks from the country database
- Fetches detailed data from RestCountries API
- Retrieves CIA World Factbook data using the country’s FIPS code
- Generates hint packages
- Stores the game in MongoDB with the date as the key
app/api/daily/route.ts:71-137 for the daily game creation logic.
Date-based routing
The game uses YYYY-MM-DD date strings to identify each daily puzzle:- Default: Today’s date (
new Date().toISOString().split('T')[0]) - Archive: Access previous games via
?date=2024-03-15query parameter - Validation: Dates must be between the game start date and today
Stats tracking
The game tracks both personal and global statistics:Personal stats
- Games played: Total number of days you’ve played
- Wins: Number of correct guesses
- Win rate: Percentage of games won
Global stats
- Total players: Number of unique sessions that played each day
- Total winners: Players who guessed correctly
- Global win rate: Percentage of all players who won
- Guess distribution: Histogram showing which guess number players won on