reset password
Author Message
Eric Liao
Posts: 158
Posted 17:07 Mar 11, 2014 |

A few questions I got today are all pointing to the player variable in calculateMoney method.

In calculateMoney method under AI_Teplate.java, you have a few parameters:

  • player
    This is the variable that many students were confused today. My description for this method might be confusing. Therefore, lets explain this variable in detail.

This variable is only going to be 1 or 2 indicating whether your bot is currently playing as player 1 or player 2. What is important because you have to assign myMoney and theirMoney at the end of this method.

Say for example, player is equal to 1, which means your bot is playing as player 1. Then, you would need to assign myMoney equals to first_money and theirMoney equals to second_money. Remember that I have this first_money and second_money in the code that is going to be the money from the first player, and the second money from the second player. Reuse them wisely.

But, that is not finished yet. At the end we only return the result as an array. Check the comment closely, we have to return the array in the correct format. The format is the first item in the result array is myMoney, second item in this array is theirMoney, and third item in this array is tieBreaker. And after you assigning them correctly, the rest of my code should take care of it.

  • first_moves
    The history moves of first player
  • second_moves
    The history moves of second player

 

ladodgersfan
Posts: 13
Posted 21:35 Mar 11, 2014 |

i have a problem returning the right amount of money according to the player if the player is 1, the tester returns the right result but when the player is two it does not. can anyone tell me what is wrong, i just need this to finish

static int[] calculateMoney(int player, int[] first_moves,
    int[] second_moves) {
        int[] result = new int[3];

        
        int first_money = 100;
        int second_money = 100;
        int draw = 1;

     
        for (int i = 0; i < first_moves.length; i ++) {
            // using array so that it is mutable
            /**
             * Helper method for calculate_bid method above
             * Hint: recall how you calculate who wins the bid from part 1
             *
             * We will return an array of integer that
             *    result[0] = my money
             *    result[1] = opponent money
             *    result[2] = tie breaker
             */
            result = calculateBid(first_moves[i], second_moves[i], draw,
                first_money, second_money);

            if (player == 1)
            {

                first_money = result[0];
                second_money = result[1];
                draw = result[2];
            }

            else if (player == 2)
            {
                
                second_money = result[0];
                first_money = result[1];
                draw = result[2];
                
            }

      

        }

      

        return result;
    }

 

Eric Liao
Posts: 158
Posted 21:38 Mar 11, 2014 |

You need to assign money to result not result to money.