contract PowerTwo is PowerOne {
    
    /**
     * @dev Makes the bid to the PowerTwo game.
     */
    function makePowerTwoBid(
        uint256 numberOne,
        uint256 numberTwo
        )
        public
        payable
        isHuman
        isActivated {
            
            require(numberOne >= minNumber && numberOne <= maxNumber, "The first  number chosen is invalid!");
            require(numberTwo >= minNumber && numberTwo <= maxNumber, "The second number chosen is invalid!");
            
            uint256 payment = SafeMath.add(powerTwoBid, powerTwoFee);
            uint256 totalPayment = SafeMath.add(payment, megaJackpotFee);
            
            require(msg.value == totalPayment, "Wrong payment value!");
            
            randomQueryId += 1;
            
            powerTwoFeesToCollect ++;
            
            // Compose the Oraclize query
            string memory queryStringOne = "[URL] ['json(https://api.random.org/json-rpc/1/invoke).result.random[\"serialNumber\",\"data\"]', '\\n{\"jsonrpc\":\"2.0\",\"method\":\"generateSignedIntegers\",\"params\":{\"apiKey\":\"${[decrypt] BEna2ojyJ8x3euQmExkugHrukwYeMH2Z7o3e9XEqATmN1ApOokRElT5IJEp1JNFhbn3dvdEo3wLaDaZJu5PqRUaoI4ZnbDTwAmMtkfLP1jBD7OldcYReDzG4cc5tdjCdP2KbzhIOEuXskoW3PzkqHzGq641e}\",\"n\":2,\"min\":1,\"max\":10,\"replacement\":false,\"base\":10${[identity] \"}\"},\"id\":";
            string memory queryStringTwo = uint2str(randomQueryId);
            string memory queryStringThree = "${[identity] \"}\"}']";
            
            string memory queryStringOne_Two = queryStringOne.toSlice().concat(queryStringTwo.toSlice());
            string memory queryStringOne_Two_Three = queryStringOne_Two.toSlice().concat(queryStringThree.toSlice());
            
            bytes32 queryId = oraclize_query("nested", queryStringOne_Two_Three, gasForOraclize);
            
            senderAddresses[queryId] = msg.sender;
            
            gameTypes[queryId] = 2;
            
            powerNumberOne[queryId] = numberOne;
            powerNumberTwo[queryId] = numberTwo;
            
            powerTwoJackpot += powerTwoBid;
            
            megaJackpot += megaJackpotFee;

            totalGamesPlayed ++;
            
            emit LogQuery(
                msg.sender,
                2,
                randomQueryId,
                numberOne,
                numberTwo,
                0,
                0
                );
                
        }
    
    /**
     * @dev Internal core logic of the PowerTwo game
     */
    function _powerTwo(
        string result,
        uint256 pnOne,
        uint256 pnTwo,
        address playerAddress
        ) internal {
            
        // Sanity check
        require(pnOne != 0, "Invalid game, refunded!");
        require(pnTwo != 0, "Invalid game, refunded!");
                
        require(powerTwoJackpot <= address(this).balance, "Insufficient funds!");
                
        strings.slice memory res = result.toSlice();
        strings.slice memory delim = " ".toSlice();
        uint256[] memory parts = new uint256[](res.count(delim) + 1);
        for (uint256 i = 0; i < parts.length; i ++) {
            parts[i] = parseInt(res.split(delim).toString());
        }
                
        // Refunding if the result is 0 or no proof is provided.
        if (bytes(result).length == 0) {
                    
            emit Refund(
                playerAddress,
                1
                );
                
            if (!playerAddress.send(SafeMath.add(powerTwoBid, powerTwoFee))) {
                
                playerFundsToWithdraw[playerAddress] = SafeMath.add(powerTwoBid, powerTwoFee);                     
            }
                    
            playerAddress = 0x0;
                    
            return;
                    
        }
                
        if (_checkTwo(
            parts[1],
            parts[2],
            pnOne,
            pnTwo)) {
                        
            if(_checkMegaJackpotCap(playerAddress)) {
                bool checkResult = true;
            } else {
                checkResult = false;
            }
                    
            powerTwoWinCounter ++;
                    
            // Calculating the eligible payout
            uint256 eligiblePayout = SafeMath.div(SafeMath.mul(powerTwoJackpot, platformCut), 100);
            uint256 platformCutPayout = SafeMath.sub(powerTwoJackpot, eligiblePayout);
                    
            playerAddress.transfer(SafeMath.div(SafeMath.mul(powerTwoJackpot, platformCut), 100));
                    
            ceoAddress.transfer(platformCutPayout);

            emit PowerEtherResults(
                playerAddress,
                parts[0],
                2,
                pnOne,
                pnTwo,
                0,
                0,
                eligiblePayout,
                true,
                checkResult
                );

            totalEtherWon += eligiblePayout;
                    
            powerTwoJackpot = 0;
                        
            playerAddress = 0x0;

        } else if (!_checkTwo(
            parts[1],
            parts[2],
            pnOne,
            pnTwo)) {
                    
            emit PowerEtherResults(
                playerAddress,
                parts[0],
                2,
                pnOne,
                pnTwo,
                0,
                0,
                eligiblePayout,
                false,
                false
                );
                    
            playerAddress = 0x0;

        }
        
    }
    
}
function makePowerTwoBid(
    uint256 numberOne,
    uint256 numberTwo
    )
    public
    payable
    isHuman
    isActivated {
            
        require(numberOne >= minNumber && numberOne <= maxNumber, "The first  number chosen is invalid!");
        require(numberTwo >= minNumber && numberTwo <= maxNumber, "The second number chosen is invalid!");
            
        uint256 payment = SafeMath.add(powerTwoBid, powerTwoFee);
        uint256 totalPayment = SafeMath.add(payment, megaJackpotFee);
            
        require(msg.value == totalPayment, "Wrong payment value!");
            
        randomQueryId += 1;
            
        powerTwoFeesToCollect ++;
            
        // Compose the Oraclize query
        string memory queryStringOne = "[URL] ['json(https://api.random.org/json-rpc/1/invoke).result.random[\"serialNumber\",\"data\"]', '\\n{\"jsonrpc\":\"2.0\",\"method\":\"generateSignedIntegers\",\"params\":{\"apiKey\":\"${[decrypt] BEna2ojyJ8x3euQmExkugHrukwYeMH2Z7o3e9XEqATmN1ApOokRElT5IJEp1JNFhbn3dvdEo3wLaDaZJu5PqRUaoI4ZnbDTwAmMtkfLP1jBD7OldcYReDzG4cc5tdjCdP2KbzhIOEuXskoW3PzkqHzGq641e}\",\"n\":2,\"min\":1,\"max\":10,\"replacement\":false,\"base\":10${[identity] \"}\"},\"id\":";
        string memory queryStringTwo = uint2str(randomQueryId);
        string memory queryStringThree = "${[identity] \"}\"}']";
            
        string memory queryStringOne_Two = queryStringOne.toSlice().concat(queryStringTwo.toSlice());
        string memory queryStringOne_Two_Three = queryStringOne_Two.toSlice().concat(queryStringThree.toSlice());
            
        bytes32 queryId = oraclize_query("nested", queryStringOne_Two_Three, gasForOraclize);
            
        senderAddresses[queryId] = msg.sender;
            
        gameTypes[queryId] = 2;
            
        powerNumberOne[queryId] = numberOne;
        powerNumberTwo[queryId] = numberTwo;
            
        powerTwoJackpot += powerTwoBid;
            
        megaJackpot += megaJackpotFee;

        totalGamesPlayed ++;
            
        emit LogQuery(
            msg.sender,
            2,
            randomQueryId,
            numberOne,
            numberTwo,
            0,
            0
            );
                
    }

/**
 * @dev Makes the bid to the PowerTwo game.
 */