KT-Robots is a port of the λ-Robots Team Hackathon Challenge.
The original idea can be traced back to the 70s RobotWar.
This repository is an implementation of the game in the kotlin programming language and the spring framework.
KT-Robots is a Team Hakcathon programming challenge build using serverless technologies.
In KT-Robots, you program a battle robot that participates in a square game field. Each turn, the server invokes your robot's Lambda function to get its action until the robot wins or is destroyed.
Install tools & setup code
Make sure that you have the following tools installed on your computer.
List of required tools
The challenge requires an AWS account. AWS provides a Free Tier, which is sufficient for the challenge.
Setup Instructions
NOTE:
For this challenge we will be using the US-EAST-1 region
Clone command
Run the following command to clone the KT-Robots challenge.
git clone [email protected]:onema/kt-robots.git
cd kt-robots
Deploy lambda functions and server
From the command line use gradlew
to run the deploy-robots
task:
./gradlew deploy-robots
Details
This task will
- Compile the
lambda-robots
project - Deploy the Lambda functions to your AWS account in the
us-east-1
region using the Serverless framework
Once the command has finished running, the output shows you the ARN of the lambda robots.
functions:
BringYourOwnRobot: kotlin-robots-dev-BringYourOwnRobot
YosemiteSam: kotlin-robots-dev-YosemiteSam
HotShot: kotlin-robots-dev-HotShot
RoboDog: kotlin-robots-dev-RoboDog
TargetRobot: kotlin-robots-dev-TargetRobot
The BringYourOwnRobot
is the robot you will be working on!
NOTE:
Open
lambda-robots/src/main/kotlin/io.onema.ktrobots.lambda/functions/BringYourOwnRobot
and customize the fieldNAME
of your robot to distinguish it from other robots.
From the command line use gradlew
to run the deploy-server
task:
./gradlew deploy-server
Details
This task performs the following actions:
- Compile the server
- Deploy the game server to your AWS account in the
us-east-1
region using CloudFormation - Creates a docker image that runs the server
- Create an ECR docker repository to host the image
- Pushes the image to the new docker repository
- Creates a Fargate cluster
- Creates a service and runs a task exposing port 80
Getting the task IP Address
Once the deployment has finished, you have to log in to AWS to get the server IP: - Amazon ECS - Clusters - ktrobots-server-cluster - Tasks - Select the task from the list - Copy the Public IP - You can also expand the task details and get a link to the CloudWatch logsOnce you have the IP paste it in your browser.
# For example
http://3.1.11.111/
Build your robot with the right equipment
The default server settings allow each robot to have 8
build points. You can spend your points in the following equipment:
Equipment type | Description |
---|---|
engine | Modify your robots speed and acceleration |
armor | Protect your robot against missile and collision damage. Heavier armor will affect your speed and acceleration |
missile | Missiles your robot can shoot. These have different velocity, damage points, ranges, blast radius and reload times |
radar | Allow your robot to detect enemies for a given distance and angle of view |
To customize your robot build, open the BringYourOwnRobot
function and update the values in the LambdaRobotBuild
method.
For additional details on the different equipment types see the Robot Build section in the Programming Reference.
NOTE:
If you go over the allotted number of points, your robot will be immediately disqualified
Develop your attack strategy
Now that you have deployed all the robots to your account add the ARN of the TargetRobot
multiple times to the KT-Robots server to create targets.
Update the behavior of BringYourOwnRobot
to shoot down the target robots.
For example, you can use luck, like YosemiteSam
, which shoots in random directions.
YosemiteSam Details
Yosemite Sam is fast and trigger happy!
This robot chooses a random angle on every turn and fires a missile. It has an extra-large engine that helps avoid attacks and keeps its distance from the edges of the game board to avoid collisions!
Equipment | Type | Points | Details |
---|---|---|---|
Armor | Light | 1 | |
Engine | Extra Large | 4 | |
Radar | Ultra Short Range | 0 | |
Missile | Dart | 0 | |
Total | 5 |
This robot uses the scan()
method to find enemies and aim missiles at them.
HotShot Details
HotShot is patient and accurate; it hardly ever misses its target!
This robot uses the scan()
method to find targets. If it doesn't find targets, it moves to a new location. If it receives damage, it initiates an evasive move.
Equipment | Type | Points | Details |
---|---|---|---|
Armor | Medium | 2 | |
Engine | Large | 3 | |
Radar | Short Range | 1 | |
Missile | Javelin | 2 | |
Total | 8 |
This robot uses the scan()
method to find enemies and chases them causing collision damage.
RoboDog Details
RoboDog moves at random and scans what is right in front of it. When this dog bites, it won't let go!
This robot uses the scan()
method to find targets right in from of it. If it does it adjust it's heading to move towards the target, this dog can hit you with a missile and with collision damage!
Equipment | Type | Points | Details |
---|---|---|---|
Armor | Light | 2 | |
Engine | Standard | 3 | |
Radar | Ultra Short Range | 0 | |
Missile | Cannon | 3 | |
Total | 8 |
This robot just sits down and waits to be hit.
TargetRobot Details
Please don't be the target robot, and nobody wants to be the target robot!
Equipment | Type | Points | Details |
---|---|---|---|
Armor | Heavy | 3 | |
Engine | Economy | 0 | |
Radar | Ultra Short Range | 0 | |
Missile | Dart | 0 | |
Total | 3 |
- Other robots may be out of radar range, requiring your robot to move periodically.
- Your robot can be damaged by its own missiles.
- Check
gameInfo.farHitRange
to make sure your target is beyond the damage range. - If you don't mind a bit of self-inflicted pain, you can also use
gameInfo.nearHitRange
or evengame.directHitRange
instead.
Develop your evasion strategy
Add the YosemiteSam
ARN twice to the KT-Robots server to create two attackers.
Now update the behavior of BringYourOwnRobot
to avoid getting shot.
Examples
You can be in continuous motion, like YosemiteSam
, which zig-zags across the board, react to damage like HotShot
, or chase and ram into your opponents like RoboDog
.
Beware that a robot cannot change heading without suddenly stopping if its speed exceeds Robot.MaxSpeed
.
Test if your robot is good enough
Add the HotShot
ARN once to the KT-Robots server to create one formidable opponent.
Consider tuning one more time your robots build by updating the equipment
- engine
- armor
- missile
- radar
🎯 Set the proper equipment to suit your attack and evasion strategies.
⚠️ Remember that your build cannot exceed 8 points or your robot will be disqualified from the competition.
Test if your robot is the best
For the boss level, your opponent is every other team! Submit your robot ARN and see how well it fares.
Before submitting your ARN for the competition, allow access to invoke your function:
aws lambda add-permission --function-name "YOUR FUNCTION ARN GOES HERE" --action lambda:InvokeFunction --statement-id kt-robots-invoke-function --principal '*' --region us-east-1
May the odds be ever in your favor!
The ECS Fargate task run on spot instances and this is the cost for running the server:
- 512 vCPU $0.00639685 per hour
- 1024 MiB $0.00140484 per hour
While it will cost you cents to run this task for a few hours, you want to turn it off after you are done with the challenge. Use the following commands to destroy all the resources:
./gradlew delete-robots
./gradlew delete-server