Difference between revisions of "LeggedRaces"
Line 9: | Line 9: | ||
[[File:LeggedRaceScreenShot.png]] | [[File:LeggedRaceScreenShot.png]] | ||
− | == | + | ==SequentialLeggedRace== |
In this implementation, try to solve the problem sequentially. Your method should go through the array of participants and make each one takeStep until you do this for every stepIndex up until the stepCount for every participant. | In this implementation, try to solve the problem sequentially. Your method should go through the array of participants and make each one takeStep until you do this for every stepIndex up until the stepCount for every participant. | ||
Line 15: | Line 15: | ||
Hint: Basically, you will need two for loops. One that iterates up until the stepCount and another which goes through the array of participants. | Hint: Basically, you will need two for loops. One that iterates up until the stepCount and another which goes through the array of participants. | ||
− | == | + | ==ForallLeggedRace== |
In this implementation, you will do what you did sequentially with a forall loop. Think about where to place the forall loop so that the program only progresses to the next stepIndex after every participant has performed a takeStep with the current index value. | In this implementation, you will do what you did sequentially with a forall loop. Think about where to place the forall loop so that the program only progresses to the next stepIndex after every participant has performed a takeStep with the current index value. | ||
− | == | + | ==ForallPhasedLeggedRace== |
In this implementation, you will build on what you did with the forall implementation to incorporate an array of phasers. Start this off by instantiating an array of phasers at DEFAULT_MODE so that the phasers can both signal and wait. Afterwards, takeStep as you did before with each participant, but remember that the partner phaser should wait until the participant phaser signals something. Remember that you must still ensure that every participant must take a step at the current index value before moving on to the next index. | In this implementation, you will build on what you did with the forall implementation to incorporate an array of phasers. Start this off by instantiating an array of phasers at DEFAULT_MODE so that the phasers can both signal and wait. Afterwards, takeStep as you did before with each participant, but remember that the partner phaser should wait until the participant phaser signals something. Remember that you must still ensure that every participant must take a step at the current index value before moving on to the next index. | ||
Hint: next() might be helpful, as well | Hint: next() might be helpful, as well | ||
+ | |||
+ | ==ForallPhasedPointToPointLeggedRace== |
Revision as of 07:15, 25 October 2017
Contents
Background
In a legged race, a group of people must try to move forward as quickly as possible with their legs tied to each other. In other words, the group can only be as quick as its slowest link and they must try to move in unison. In many ways, this concept mirrors parallel phasers. In this studio, you will use phasers and forall loops in order to simulate a legged race.
Where to Start
Navigate your way to the legged-race folder and then to leggedrace.studio
. You will have to implement four separate approaches to this problem: sequential, forall, forall_phased (which just uses next() barriers), and forall_phased_point_to_point (which uses an array of phasers to signal and wait). For each of these implementations, you must just complete the takeSteps method.
SequentialLeggedRace
In this implementation, try to solve the problem sequentially. Your method should go through the array of participants and make each one takeStep until you do this for every stepIndex up until the stepCount for every participant.
Hint: Basically, you will need two for loops. One that iterates up until the stepCount and another which goes through the array of participants.
ForallLeggedRace
In this implementation, you will do what you did sequentially with a forall loop. Think about where to place the forall loop so that the program only progresses to the next stepIndex after every participant has performed a takeStep with the current index value.
ForallPhasedLeggedRace
In this implementation, you will build on what you did with the forall implementation to incorporate an array of phasers. Start this off by instantiating an array of phasers at DEFAULT_MODE so that the phasers can both signal and wait. Afterwards, takeStep as you did before with each participant, but remember that the partner phaser should wait until the participant phaser signals something. Remember that you must still ensure that every participant must take a step at the current index value before moving on to the next index.
Hint: next() might be helpful, as well