Due: Friday, Oct. 9th by 8:00pm
When you have created the previous three players, you may have noticed that
the makeDecision
function has three arguments: me
,
partner
, and capital
.
Each of those variables contian information that may allow you to make a better decision. The full API is detailed in Part 5, but one of the most important values is the player reputation.
A player's reputation is the percentage of times that player has hunted
(instead of slacking off). It is stored as a percentage, a Number in the range
[0, 1], in the partner.reputation
variable.
0
indicates that they NEVER hunt.
Sam the Slacker will always have a reputation of 0.
1
indicates that they ALWAYS hunt.
Hue the Hunter will always have a reputation of 1.
Random Raj will the be the very last player that we guide you through creating. Instead of hunting and slacking exactly half the time, Random Raj will hunt or slack based on the reputation of his hunting partner.
randomRaj.js
.
"Random Raj"
.
makeDecision
function:
// Program the makeDecision function to play in the contest! makeDecision: function(me, partner, capital) { var randomNumber = Math.random(); }
randomNumber
is greater than
the reputation of his partner. If the random number is greater then
return "s"
. Otheriwse, return "h"
.
1.0
,
we can never pick a number larger than that so we always hunt with
that partner; likewise, if the reputation is 0.0
, we
will always pick a number larger than that so we will always slack
with that partner.
players/randomRaj.js
.
If you completed everything correctly so far, you can run your third CS 105 Hunger Games!
cs105HungerGames.html
in a web browser.
If everything works, you should be able to watch CS 105's Hunger Games unfold before your very eyes!