80's Kids #6: Rock 'Em, Sock 'Em Robots
Description:
You and your friends have been battling it out with your Rock 'Em, Sock 'Em robots, but things have gotten a little boring. You've each decided to add some amazing new features to your robot and automate them to battle to the death.
Each robot will be represented by an object. You will be given two robot objects, and an object of battle tactics and how much damage they produce. Each robot will have a name, hit points, speed, and then a list of battle tactics they are to perform in order. Whichever robot has the best speed, will attack first with one battle tactic.
Your job is to decide who wins.
Example:
robot1 = {
"name": "Rocky",
"health": 100,
"speed": 20,
"tactics": ["punch", "punch", "laser", "missile"]
}
robot2 = {
"name": "Missile Bob",
"health": 100,
"speed": 21,
"tactics": ["missile", "missile", "missile", "missile"]
}
tactics = {
"punch": 20,
"laser": 30,
"missile": 35
}
fight(robot1, robot2, tactics) -> "Missile Bob has won the fight."
robot2 uses the first tactic, "missile" because he has the most speed. This reduces robot1's health by 35. Now robot1 uses a punch, and so on.
Rules
- A robot with the most speed attacks first. If they are tied, the first robot passed in attacks first.
- Robots alternate turns attacking. Tactics are used in order.
- A fight is over when a robot has 0 or less health or both robots have run out of tactics.
- A robot who has no tactics left does no more damage, but the other robot may use the rest of his tactics.
- If both robots run out of tactics, whoever has the most health wins. If one robot has 0 health, the other wins. Return the message "{Name} has won the fight."
- If both robots run out of tactics and are tied for health, the fight is a draw. Return "The fight was a draw."
To Java warriors
Robot
class is immutable.
80's Kids #2: Help Alf Find His Spaceship
80's Kids #3: Punky Brewster's Socks
80's Kids #4: Legends of the Hidden Temple
80's Kids #5: You Can't Do That on Television
80's Kids #6: Rock 'Em, Sock 'Em Robots
80's Kids #7: She's a Small Wonder
80's Kids #8: The Secret World of Alex Mack
Similar Kata:
Stats:
Created | Dec 11, 2015 |
Published | Dec 11, 2015 |
Warriors Trained | 7268 |
Total Skips | 1884 |
Total Code Submissions | 39304 |
Total Times Completed | 2481 |
JavaScript Completions | 964 |
Ruby Completions | 168 |
CoffeeScript Completions | 14 |
Java Completions | 365 |
Python Completions | 1013 |
Total Stars | 272 |
% of votes with a positive feedback rating | 92% of 425 |
Total "Very Satisfied" Votes | 369 |
Total "Somewhat Satisfied" Votes | 46 |
Total "Not Satisfied" Votes | 10 |
Total Rank Assessments | 19 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 7 kyu |