VectorGuesser (http://vectorguesser.duckdns.org or http://vectorguesser.chickenkiller.com/)
A geography-based guessing game where players use vectors (distance and bearing) to guess hidden cities. Each correct guess increases your score by distance to the target, while incorrect guesses decrease attempts. The goal is to guess as many cities as possible and get as much score as you can.
- Dynamic Difficulty Levels: Easy, Medium, and Hard city selections
- Capitals Only Mode: Toggle to guess only capital cities
- Vector-Based Gameplay: Each round shows a start city, distance, and bearing to a hidden target city
- Interactive Map: Visualized vectors and city locations using Leaflet.js
- Autocomplete Suggestions: Dynamic city suggestions based on selected difficulty and mode
- Scoring System: Earn points based on distance of correct guesses
- Session Management: Track attempts, cities guessed, and score
- RESTful API: C++ backend with Crow framework
- SQLite Database: Pre-populated with world cities and their attributes
- Docker Support: Easy deployment with containerization
- Language: C++20
- HTTP Server: Crow (header-only)
- Database: SQLite3 with RAII wrappers
- Build System: CMake 3.16+
- Containerization: Docker
- Map Library: Leaflet.js
- Styling: CSS3
- Logic: JavaScript
- Assets: Custom vector markers
CREATE TABLE cities (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
latitude REAL NOT NULL,
longitude REAL NOT NULL,
country TEXT NOT NULL,
difficulty TEXT NOT NULL CHECK (difficulty IN ('easy', 'medium', 'hard')),
capital INTEGER NOT NULL DEFAULT 0 CHECK (capital IN (0, 1))
);- C++ compiler with C++20 support (GCC 9+, Clang 9+, MSVC 2019+)
- CMake 3.16 or higher
- SQLite3 development libraries
- Git
- Docker (optional, for containerized deployment)
-
Build the Docker image
docker build -t vectorguesser . -
Run the container
docker run -p 80:18080 vectorguesser
The server will start on http://0.0.0.0
-
Clone the repository
git clone https://github.com/kaherro/VectorGuesser cd VectorGuesser -
Build the project
mkdir build && cd build cmake .. make
-
Initialize the database (if not already present)
sqlite3 data/cities.db < data/cities.sql -
Run the server
./VectorGuesser
- Redirects to
/index.html
- Serves static files from the
webdirectory
- Starts a new game session
- Query Parameters:
difficulty(required):easy,medium, orhardcapitals_only(required):trueorfalse
- Response:
{ "city": { "id": <integer>, "name": <string>, "latitude": <number>, "longitude": <number>, "country": <string> }, "session_id": <string>, "attempts_left": <integer>, "vector": { "distance_km": <integer>, "angle_deg": <number> } }
- Makes a guess for the current session
- Query Parameters:
from(required): City name to guesssession_id(required): Session identifier
- Response:
- On correct guess:
"Correct"(plain text) - On error with attempts left: JSON with city, vector, and attempts_left
- On game over:
"No attempts left. Game over. Target city was: <city name>"(plain text) - On error: JSON with error message
- On correct guess:
- Loads the next round in the same session
- Query Parameters:
session_id(required): Session identifier
- Response: Same format as
/api/start
- Gets list of city names for autocomplete
- Query Parameters:
difficulty(required):easy,medium, orhardcapitals_only(required):trueorfalse
- Response: JSON array of city names
VectorGuesser/
├── data/
│ ├── cities.db # SQLite database (generated from cities.sql)
│ └── cities.sql # Database schema and initial data
├── src/
│ ├── main.cpp # Entry point and API handlers
│ ├── db_manager.h # Database manager declaration
│ └── db_manager.cpp # Database manager implementation
├── web/
│ ├── index.html # Main HTML file
│ ├── style.css # Stylesheet
│ └── script.js # Frontend game logic
├── CMakeLists.txt # CMake build configuration
├── Dockerfile # Docker build instructions
└── README.md # This file
- Select a difficulty level (Easy, Medium, Hard)
- Optionally enable "Capitals Only" mode
- Click "Start Game" to begin
- A start city will be shown with a vector (distance and bearing) to a hidden target city
- Type your guess in the input field and click "Guess" or press Enter
- Correct guesses:
- Increase your score by the distance
- Load a new round with the same attempts
- Incorrect guesses:
- Consume one attempt
- Show the error vector
- Game ends when you run out of attempts
- Click "New Game" to restart
- Leaflet.js for interactive maps
- Crow C++ framework for the web server
- SQLite for embedded database
- OpenStreetMap contributors for map data
