- Install Make
- Install Python 3.12.2. Example, first install
pyenv, then:pyenv install 3.12.2 $(pyenv which python3.12) -m venv .venv - Install poetry. Example:
source .venv/bin/activate pip install --upgrade pip pip install poetry poetry install --no-root - Install docker and docker-compose
Scores in leaderboard are the number of resources stolen
docker compose up
make rundocker run --name redis-stack -p 6379:6379 -p 8001:8001 -e redis/redis-stack:latest
The main reason for this task is to measure proficiency in programming and ability to learn new technologies under time pressure. You don’t have to complete all the requirements. You can move on to the next part, that requires a slightly different skill set, at any time. It’s important that you present your strongest side in this limited time.
Using language and a framework of your choice implement the backend service for registering players, providing leaderboards and accepting battle requests. Then implement an engine (worker / job / script etc) for processing submitted battles. It is recommended to use Redis as your main database.
-
Model the following in the primary database
- Player - should consist of at least the following
- Identifier
- Name (max length 20 characters, unique)
- Description (max length is 1k characters)
- Amount of gold (max value 1 bln)
- Amount of silver (max value 1 bln)
- Attack value, Hit points and luck value
- Player - should consist of at least the following
-
Implement the web application with the following endpoints / handlers
- Create player
- Validate and store details in database
- Submit battle - opponents
- Put the battle request into battle processor queue
- Retrieve leaderboard
- Retrieve list of all the players on the leaderboard, each entry consisting of rank/position, score and player identifier
- Create player
-
Implement the battle processor
- Players will submit battles, specifying who they want to attack. Those submissions should be
processed by a battle processor that needs to meet the following requirements
- Battles must happen in the order that they were submitted
- Each battle should only be executed once
- No battles should be missed
- Battles should be processed as soon as possible, but there is no hard requirement
- Processor should implement at least the following steps for each battle in the queue
- Process the battle - see sections 2 below
- Battle should be logged
- Resource should be subtracted from losing player
- Resource should be added to winning player
- The total amount of resources stolen should be submitted to the leaderboard
- Players will submit battles, specifying who they want to attack. Those submissions should be
processed by a battle processor that needs to meet the following requirements
- Implement the battle engine
-
The battle
-
The battle system is turn based, with whoever submitted the battle going first
-
With each attack, the attacker must calculate the damage it can do. The attack value is proportional to the players hit points. The lower the hit points - the lower the attack, with a cap at 50% of the base attack value.
- For example: with the loss of 1% of health, reduce attack by 1% rounded up, so starting health 100, attack 70, every time 10 damage is taken, the attack value is reduced by 7. In this scenario, the attack can never be reduced below 35 which is 50% of the base attack value.
-
The attacker then becomes the defender, and the defender the attacker.
-
Use the luck value of the defender to decide if an attack misses.
-
The battle continues until one of the players hit points value reaches zero.
-
-
Resources stolen should be between 10% and 20% of their total amount of resources, evenly distributed across their resources
-
A battle report should be generated - which contains a detailed log of everything that happened during the battle.
-
Implement concurrent execution of non-conflicting battles
-
- All endpoints should be protected against public/unauthorised access in some way.