contract StakeDiceGame
{
    // Prevent people from losing Ether by accidentally sending it to this contract.
    function () payable external
    {
        revert();
    }
    
    ///////////////////////////////
    /////// GAME PARAMETERS
    
    StakeDice public stakeDice;
    
    // Number between 0 and 10 000. Examples:
    // 700 indicates 7% chance.
    // 5000 indicates 50% chance.
    // 8000 indicates 80% chance.
    uint256 public winningChance;
    
    // Examples of multiplierOnWin() return values:
    // 10 000 indicates 1x returned.
    // 13 000 indicated 1.3x returned
    // 200 000 indicates 20x returned
    function multiplierOnWin() public view returns (uint256)
    {
        uint256 beforeHouseEdge = 10000;
        uint256 afterHouseEdge = beforeHouseEdge - stakeDice.houseEdge();
        return afterHouseEdge * 10000 / winningChance;
    }
    
    function maximumBet() public view returns (uint256)
    {
        uint256 availableTokens = stakeDice.stakeTokenContract().balanceOf(address(stakeDice));
        return availableTokens * 10000 / multiplierOnWin() / 5;
    }
    

    
    ///////////////////////////////
    /////// OWNER FUNCTIONS
    
    // Constructor function
    // Provide a number between 0 and 10 000 to indicate the winning chance and house edge.
    constructor(StakeDice _stakeDice, uint256 _winningChance) public
    {
        // Ensure the parameters are sane
        require(_winningChance > 0);
        require(_winningChance < 10000);
        require(_stakeDice != address(0x0));
        require(msg.sender == address(_stakeDice));
        
        stakeDice = _stakeDice;
        winningChance = _winningChance;
    }
    
    // Allow the owner to change the winning chance
    function setWinningChance(uint256 _newWinningChance) external
    {
        require(msg.sender == stakeDice.owner());
        require(_newWinningChance > 0);
        require(_newWinningChance < 10000);
        winningChance = _newWinningChance;
    }
    
    // Allow the owner to withdraw STAKE tokens that
    // may have been accidentally sent here.
    function withdrawStakeTokens(uint256 _amount, address _to) external
    {
        require(msg.sender == stakeDice.owner());
        require(_to != address(0x0));
        stakeDice.stakeTokenContract().transfer(_to, _amount);
    }
}
function withdrawStakeTokens(uint256 _amount, address _to) external
{
    require(msg.sender == stakeDice.owner());
    require(_to != address(0x0));
    stakeDice.stakeTokenContract().transfer(_to, _amount);
}

// Allow the owner to withdraw STAKE tokens that
// may have been accidentally sent here.