reset password
Author Message
ytsai8
Posts: 47
Posted 21:10 Feb 26, 2014 |

So the bug I am having is that when one of the player's money is equal to 0, (1) it is returning Invalid and automatically loses (2) it's his or her last all-in move (and wins), it returns Invalid, but the person still wins the game.

However, I realize even when one player is bankrupted, the game might still be a tie (when another one's money is less than the position he or she needs to earn in order to win, the prize would not reach position 0 or 10).

Here is my doMove() method, can anybody help me debug or any hint????

public String doMoves(int p1bid, int p2bid) {
        p1History = p1History + String.valueOf(p1bid) + " ";
        p2History = p2History + String.valueOf(p2bid) + " ";
        
        if(p1bid>p2bid)
        {
            firstMoney -=p1bid;
            pos -= 1;
            winner = "P1";
        }
        else if(p2bid>p1bid)
        {
            secondMoney -= p2bid;
            pos += 1;
            winner = "P2";
        }
        else
        {
            if(tie % 2 == 0 )
            {
                firstMoney -= p1bid;
                pos -= 1;
                tie++;
                winner = "tie";
            }
            else
            {
                secondMoney -= p2bid;
                pos += 1;
                tie++;
                winner = "tie";
            }
        }

       
         if((p1bid>firstMoney || p1bid<0) &&(p2bid>secondMoney || p2bid<0))
        {
            winner = "tie"; 
            return "Tie-Invalid";
        }
         else if(p2bid>secondMoney || p2bid<0)
        {
            winner = "P1";
            return "P2-Invalid";
        }
        else if(p1bid>firstMoney || p1bid<0)
        {
            winner = "P2";
            return "P1-Invalid";
        }
        else
        {
            return "Valid";
        }
  
    }

 

And here is one of the example output.

P2-Invalid
Token Position: 2
 Player 1 has 20 gold.
 Player 2 has 0 gold.
 Player 1 move history: 20 20 20 20 20 
 Player 2 move history: 0 0 0 0 100 

 The final Winner is P1.