Created
June 29, 2017 07:46
-
-
Save fabslab/02f28bdd384e3940115defa3e576005e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Instructions: | |
You'll be writing a C-style command line program to assign teams for a simple game. Here's how the game works: | |
Each team in the game is composed of units. Each unit has two attributes: an "attack power" and a "defense power", both integers. | |
Each round of the game, we choose a random order for the teams. This defines a set of pairs of teams, which face off against each other. So, the first team in the list fights the second team in the list, the third team fights the fourth team, and so on. If we have an odd number of teams, the last team in the list always becomes the first team in the list for the next round. | |
When two teams face off, they do simultaneous damage to each other. The maximum amount of damage done to a team is the difference between the sum of the team's unit's "defense power" attributes and the sum of the other team's unit's "attack power". The actual damage done to each team in a fight is a random integer between 0 and that difference. | |
Each team starts with the same number of hit points, which goes down as that team takes damage. When a team's hit point value hits zero, it's removed from the game. | |
The last team left wins. | |
Your program will take a list of units and a number of teams, and assign units to teams to create a balanced fight. | |
The input for your program is a CSV-style list (to stdin or std::cin). The first line of the input is the number of teams in the game. After that, the units are listed, one per line, with each unit's attack power and defense power separated by a comma. There's no white space in the file other than the ends of line. | |
Here's an example input file: | |
2 | |
5,1 | |
9,1 | |
7,4 | |
1,3 | |
1,3 | |
10,4 | |
4,5 | |
7,4 | |
Your program generates a CSV-style list (to stdout or std::cout) assigning teams to each of the units. Your goal is to generate a balanced set of N teams. Your output file lists the unit assigned to each team by unit index. | |
Given the example input file, here's a reasonable output file: | |
1,3,6,7 | |
0,2,4,5 | |
This output file has assigned units 1, 3, 6 and 7 to team 0 and units 0, 2, 4 and 5 to team 1. Team 0 has total attack strength 21 and total defense strength 13, while team 1 has total attack strength 23 and total defense strength 12. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment