Part 4: Players that Use Information

Part 4.1: The API to the makeDecision function

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.

Part 4.2: Creating Random Raj

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.

  1. Follow the steps from Part 2 to create a new player. A good name for the file would be randomRaj.js.
  2. Edit the your new player's name to be "Random Raj".
  3. The following code is the start of Random Raj's makeDecision function:
    // Program the makeDecision function to play in the contest!
    makeDecision: function(me, partner, capital) {
    var randomNumber = Math.random();
    
    
    
    }
    
    1. Add a conditional to check if randomNumber is greater than the reputation of his partner. If the random number is greater then return "s". Otheriwse, return "h".
      • Random Raj will slack only if he picks a random number larger that his partner's reputation. If the reputation is 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.
    2. Once you've got it, save the file!
  4. Follow the steps from Part 2.4 to add a new player to the HTML page. Make sure to refer to the correct file name, as Random Riko is probably in players/randomRaj.js.

Part 4.3: Testing Everything so Far

If you completed everything correctly so far, you can run your third CS 105 Hunger Games!

  1. Open cs105HungerGames.html in a web browser.
  2. Press Play!

If everything works, you should be able to watch CS 105's Hunger Games unfold before your very eyes!

Part 5