This project presents a fully structured and normalized relational database design for a simplified version of a Clash of Clans-like strategy game. The database supports essential gameplay features such as managing users, buildings, troops, and attacks.
- Track user profiles and their progress (resources, town hall level, trophies, etc.)
- Manage user-placed buildings with coordinates and levels
- Define and unlock troop types with upgrade levels
- Record and analyze attacks between users
- Track troops used and buildings destroyed in each attack
- Analyze user progression, troop efficiency, and strategic behavior
- Fully normalized up to Third Normal Form (3NF) (plus BCNF for
BuildingTypes
)
- Primary Key:
UserID
- Stores player details: username, level, resources, trophies, signup date, and town hall level.
- Primary Key:
BuildingID
- References
BuildingTypes(Name)
to get building category (Defensive
,Resource
,Army
) - Stores upgrade costs, size, and level.
- Primary Key:
Name
- Specifies type/category of building (Defensive, Army, Resource)
- Primary Key:
UserBuildingID
- Links users with the buildings they’ve placed, including location (
XCoordinate
,YCoordinate
).
- Primary Key:
TroopID
- General troop definitions with attributes like hit points, damage, type, and resource type.
- Composite Key:
(UserID, TroopID)
- Indicates which troops are unlocked for each user, and their current upgrade level.
- Primary Key:
AttackID
- Captures battle details: attacker, defender, destruction percentage, stars earned, and attack duration.
- Composite Key:
(AttackID, TroopID)
- Shows how many of each troop type were used during a specific attack.
- Composite Key:
(AttackID, UserBuildingID)
- Lists which buildings were destroyed in a specific attack.
- Recommended Troop Upgrade System: Suggests troops for upgrade based on successful players of similar level.
- Trophy Evaluation: Classifies player trophies as High, Normal, or Low relative to average of their level group.
- Player Efficiency Scoring:
- Measures how efficiently players convert time + resources into progress.
- Detects behavior patterns:
- Troop-Focused vs Building-Focused
- Specialist vs Generalist
- Dominant Building Type (e.g., Defensive-heavy base)
- Defense Effectiveness: Identifies users who successfully defend based on attack results.
- Attack Timing Statistics: For each level, calculates what % of attacks last under 60 seconds.
- Most Effective Troops: Tracks which troop types are most used in successful attacks by each player.
Table | Normalized To | Candidate Keys |
---|---|---|
Users | 3NF | UserID |
Buildings | BCNF | BuildingID |
BuildingTypes | 3NF | Name |
UserBuildings | 3NF | UserBuildingID |
Troops | 3NF | TroopID |
UserTroops | 3NF | (UserID, TroopID) |
Attacks | 3NF | AttackID |
AttackTroops | 3NF | (AttackID, TroopID) |
AttackDestroyedBuildings | 3NF | (AttackID, UserBuildingID) |
- In the original design, the Buildings table contained a Type field:
BuildingID | Name | Type | ...
-----------|--------------|------------|-----
1 | Archer Tower | Defensive | ...
2 | Gold Mine | Resource | ...
- This caused a transitive functional dependency:
BuildingID → Name → Type
- To fully normalize the schema (3NF and BCNF), we decomposed the table to remove this dependency.
- Step 1 – Create the new table
BuildingTypes
:
CREATE TABLE BuildingTypes (
Name VARCHAR(50) PRIMARY KEY,
Type VARCHAR(20) NOT NULL CHECK (Type IN ('Defensive', 'Resource', 'Army'))
);
- Step 2 – Populate
BuildingTypes
from existingBuildings
:
INSERT INTO BuildingTypes (Name, Type)
SELECT DISTINCT Name, Type
FROM Buildings;
- Step 3 – Remove Type column from Buildings:
ALTER TABLE Buildings
DROP COLUMN Type;
- Step 4 – Add foreign key constraint from
Buildings
toBuildingTypes
:
ALTER TABLE Buildings
ADD CONSTRAINT FK_Buildings_BuildingTypes
FOREIGN KEY (Name) REFERENCES BuildingTypes(Name);
- SQL Server (Transact-SQL)
- ER Modeling (ERD link in project files)
- GitHub for version control
- Optional data generation: Python (for synthetic data)
You can view the full ER diagram here:
📊 Canva ER Diagram
To set up and test this database:
- Run the provided SQL scripts in Microsoft SQL Server.
- Populate sample data using data generators or manually.
- Use the provided queries for analytics or integrate with a front-end UI.
- Add timestamps for building/troop upgrades and attacks
- Introduce clan/guild systems
- Integrate with game simulation engine for real-time data
Created by Monire
For academic purposes
Contact via GitHub or telegram