The problem is when the prize is allocated to those winners for claim, the allocation is double upon allocating prizes.

Code for allocating prize:

``````// Generates a number between 1 and 10 that will be the winner
function allocatePrizes(uint _gameId, uint16 teamWinner) public onlyAgent {
Game storage game = gameInfo[_gameId];
require(bettingActive == false);
//We have to create a temporary in memory array with fixed size
//Let's choose 1000

uint256 LoserBet = 0; //This will take the value of all losers bet
uint256 WinnerBet = 0; //This will take the value of all winners bet

//We loop through the player array to check who selected the winner team
for(uint256 i = 0; i < players.length; i++){
//If the player selected the winner team
count++;
}
}

//We define which bet sum is the Loser one and which one is the winner
if ( teamWinner == 1){
LoserBet = totalBetsTwo;
WinnerBet = totalBetsOne;
//We loop through the array of winners, to give ethers to the winners
for(uint256 j = 0; j < count; j++){
// Check that the address in this fixed array is not empty

// token.transfer(winners[j],  (bets*(10000+(LoserBet*fee /WinnerBet)))/10000 );
rewards = (bets*(10000+(LoserBet*fee /WinnerBet)))/10000;
}

}
gameInfo[_gameId] = Game(_gameId, State.Finished);
game.state == State.Finished;
delete playerInfo[playerAddress]; // Delete all the players
players.length = 0; // Delete all the players array
LoserBet = 0; //reinitialize the bets
WinnerBet = 0;
totalBetsOne = 0;
totalBetsTwo = 0;

}
else if(teamWinner == 2){
LoserBet = totalBetsOne;
WinnerBet = totalBetsTwo;
//We loop through the array of winners, to give ethers to the winners
for(uint256 k = 0; k < count; k++){

// Check that the address in this fixed array is not empty

// token.transfer(winners[k],  (bets*(10000+(LoserBet*fee /WinnerBet)))/10000 );
rewards = (bets*(10000+(LoserBet*fee /WinnerBet)))/10000;
}
}
gameInfo[_gameId] = Game(_gameId, State.Finished);
game.state == State.Finished;
delete playerInfo[playerAddress]; // Delete all the players
players.length = 0; // Delete all the players array
LoserBet = 0; //reinitialize the bets
WinnerBet = 0;
totalBetsOne = 0;
totalBetsTwo = 0;

}
else if(teamWinner == 3){
//We loop through the player array to check who selected the winner team

for(uint256 l = 0; l < players.length; l++){

num++;
}
}
//We loop through the array of winners, to give ethers to the winners
for(uint256 m = 0; m < num; m++){
// Check that the address in this fixed array is not empty

// token.transfer(draw[m], (bets*(fee))/10000 );

rewards = (bets*(fee))/10000;
}
gameInfo[_gameId] = Game(_gameId, State.Finished);
game.state == State.Finished;
delete playerInfo[add]; // Delete all the players
players.length = 0; // Delete all the players array
LoserBet = 0; //reinitialize the bets
WinnerBet = 0;
totalBetsOne = 0;
totalBetsTwo = 0;
}

}

}
``````

and the claim function:

``````function balanceOf(address user) public constant returns (uint256) {
uint256 levs = _pendingBalance[user];
return levs;
}

function claimRewards()  public {
uint256 balance = balanceOf(msg.sender);
require(balance > 0);
_pendingBalance[msg.sender] = 0;
token.transfer(msg.sender, balance);
emit ClaimRewards(msg.sender, balance);
}
``````