hey guys, i know this isn't mac related, but I trust this forum more than my own mother, so I thought i'd ask. We are using functions now. The assignment is:
The board game named Risk simulates world conquest, by representing large armies taking over large territories. In each turn and invading army attempts to defeat the defenders in an adjacent territory.
Each battle is represented by a series of competitive die rolls, using six-sided dice. The invading army may roll up to three dice (but no more than the number of fighting units present). The defending army may roll up to two dice (again, not more than the number of fighting units present).
To resolve the outcome of the battle, the dice results are compared. The best die for each side, the second-best die for each side, etc. Ties favor the defender. The loss of a die competition translates into a loss of a fighting unit.
For example, if the attacker rolls a 3, 6, and a 4, and the defender rolls a 4 and a 5, the 6 pairs with the 5 (attacker wins) and the 4's pair with each other (defender wins). In this example, both the attacker and defender lose one fighting unit.
The battle continues until either of the two forces is eliminated, or until the attack simply decides to cease attacking. Sometimes the battle is very short (very small armies), but sometimes it can be very lengthy (very large armies).
Some players lose interest late in the Risk game when the armies are very large. This program would assist the players by managing a long combat for them.
PROGRAM SPECIFICATIONS
The program is to be designed to handle any number of complete battles in sequence (the user determines when the game ends).
Each battle is itself a series of competitive die rolls. Of course, before this can begin, the size of the two competing armies must be provided (as keyboard input). However, to reduce the necessity of many inputs while managing a large battle, the attacker is to be given the following options:
* Roll just one competitive die roll.
In the regular board game, the attacker usually decides these one at a time.
* Fight until either of the two armies is completely wiped out.
This would especially be chosen with vastly superior forces.
* Fight until the attacker's army is reduced to some specified size.
This would be yet another input value (which may even be typed in at the same moment as the command is issued).
This would be a more conservative approach to a long battle, and then further prospects would be analyzed.
* Withdraw from combat, ending the battle immediately.
Sometimes prudence is better than valor.
Note that this interface may itself be repeated within a large battle. The battle is only truly over until one side is eliminated, or the attacker chooses to withdraw.
Of course, the attacker is free to initiate a battle on a new front, with new armies involved. (So this program will repeat).
CODE REQUIREMENTS
Appropriate use of functions is absolutely required for this assignment. Not all functions will be specified in advance -- part of the exercise is to learn to identify the appropriate time to use them.
During program design, identify significant portions of code that can be easily described in a sentence or two, and define those to be functions. Sometimes a function may very well be further qualified into smaller steps which themselves would be functions.
A couple hints of common operations to get you started:
-- sorting two or three die rolls into decreaasing order
especially if you can have one function handle all sorting
-- managing exactly one competitive die roll, adjusting army sizes (also displaying the actual die rolls and their effect)
SO....
The board game named Risk simulates world conquest, by representing large armies taking over large territories. In each turn and invading army attempts to defeat the defenders in an adjacent territory.
Each battle is represented by a series of competitive die rolls, using six-sided dice. The invading army may roll up to three dice (but no more than the number of fighting units present). The defending army may roll up to two dice (again, not more than the number of fighting units present).
To resolve the outcome of the battle, the dice results are compared. The best die for each side, the second-best die for each side, etc. Ties favor the defender. The loss of a die competition translates into a loss of a fighting unit.
For example, if the attacker rolls a 3, 6, and a 4, and the defender rolls a 4 and a 5, the 6 pairs with the 5 (attacker wins) and the 4's pair with each other (defender wins). In this example, both the attacker and defender lose one fighting unit.
The battle continues until either of the two forces is eliminated, or until the attack simply decides to cease attacking. Sometimes the battle is very short (very small armies), but sometimes it can be very lengthy (very large armies).
Some players lose interest late in the Risk game when the armies are very large. This program would assist the players by managing a long combat for them.
PROGRAM SPECIFICATIONS
The program is to be designed to handle any number of complete battles in sequence (the user determines when the game ends).
Each battle is itself a series of competitive die rolls. Of course, before this can begin, the size of the two competing armies must be provided (as keyboard input). However, to reduce the necessity of many inputs while managing a large battle, the attacker is to be given the following options:
* Roll just one competitive die roll.
In the regular board game, the attacker usually decides these one at a time.
* Fight until either of the two armies is completely wiped out.
This would especially be chosen with vastly superior forces.
* Fight until the attacker's army is reduced to some specified size.
This would be yet another input value (which may even be typed in at the same moment as the command is issued).
This would be a more conservative approach to a long battle, and then further prospects would be analyzed.
* Withdraw from combat, ending the battle immediately.
Sometimes prudence is better than valor.
Note that this interface may itself be repeated within a large battle. The battle is only truly over until one side is eliminated, or the attacker chooses to withdraw.
Of course, the attacker is free to initiate a battle on a new front, with new armies involved. (So this program will repeat).
CODE REQUIREMENTS
Appropriate use of functions is absolutely required for this assignment. Not all functions will be specified in advance -- part of the exercise is to learn to identify the appropriate time to use them.
During program design, identify significant portions of code that can be easily described in a sentence or two, and define those to be functions. Sometimes a function may very well be further qualified into smaller steps which themselves would be functions.
A couple hints of common operations to get you started:
-- sorting two or three die rolls into decreaasing order
especially if you can have one function handle all sorting
-- managing exactly one competitive die roll, adjusting army sizes (also displaying the actual die rolls and their effect)
SO....