contract PowerFour is PowerTwo {
    
    /**
     * @dev Makes the bid to the PowerFour game.
     */
    function makePowerFourBid(
        uint256 numberOne,
        uint256 numberTwo,
        uint256 numberThree,
        uint256 numberFour
        )
        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!");
            require(numberThree >= minNumber && numberThree <= maxNumber, "The third number chosen is invalid!");
            require(numberFour >= minNumber && numberFour <= maxNumber, "The fourth chosen is invalid!");
            
            uint256 payment = SafeMath.add(powerFourBid, powerFourFee);
            uint256 totalPayment = SafeMath.add(payment, megaJackpotFee);
            
            require(msg.value == totalPayment, "Wrong payment value!");
            
            randomQueryId += 1;
            
            powerFourFeesToCollect ++;
            
            // 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\":4,\"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] = 4;
            
            powerNumberOne[queryId] = numberOne;
            powerNumberTwo[queryId] = numberTwo;
            powerNumberThree[queryId] = numberThree;
            powerNumberFour[queryId] = numberFour;
            
            powerFourJackpot += powerFourBid;
            
            megaJackpot += megaJackpotFee;

            totalGamesPlayed ++;
                
        }
        
    /**
     * @dev Internal core logic of the PowerFour game
     */
    
    function _powerFour(
        string result,
        uint256 pnOne,
        uint256 pnTwo,
        uint256 pnThree,
        uint256 pnFour,
        address playerAddress
        ) internal {
            
        // Sanity check
        require(pnOne != 0, "Invalid game, refunded!");
        require(pnTwo != 0, "Invalid game, refunded!");
        require(pnThree != 0, "Invalid game, refunded!");
        require(pnFour != 0, "Invalid game, refunded!");
                
        require(powerFourJackpot <= 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(powerFourBid, powerFourFee))) {
                
                playerFundsToWithdraw[playerAddress] = SafeMath.add(powerFourBid, powerFourFee);                  
            }
                    
            playerAddress = 0x0;
                    
            return;
                    
        }
                
        if (_checkFour(
            parts[1],
            parts[2],
            parts[3],
            parts[4],
            pnOne,
            pnTwo,
            pnThree,
            pnFour)) {
                        
            _checkMegaJackpotCap(playerAddress);
                    
            // Calculating the eligible payout
            uint256 eligiblePayout = SafeMath.div(SafeMath.mul(powerFourJackpot, platformCut), 100);
            uint256 platformCutPayout = SafeMath.sub(powerFourJackpot, eligiblePayout);
                    
            playerAddress.transfer(eligiblePayout);
                    
            // Transfering the MegaJackpot to the winner
            playerAddress.transfer(megaJackpot);
                    
            ceoAddress.transfer(platformCutPayout);

            emit PowerEtherResults(
                playerAddress,
                parts[0],
                4,
                pnOne,
                pnTwo,
                pnThree,
                pnFour,
                eligiblePayout,
                true,
                true
                );

            totalEtherWon += eligiblePayout;
                    
            powerFourWinCounter ++;
                    
            megaJackpot = 0;
                    
            powerFourJackpot = 0;
                    
            playerAddress = 0x0;

        } else if (!_checkFour(
            parts[1],
            parts[2],
            parts[3],
            parts[4],
            pnOne,
            pnTwo,
            pnThree,
            pnFour)) {
                        
            emit PowerEtherResults(
                playerAddress,
                parts[0],
                4,
                pnOne,
                pnTwo,
                pnThree,
                pnFour,
                eligiblePayout,
                false,
                false
                );

            playerAddress = 0x0;

        }
        
    }
    
}
function makePowerFourBid(
        uint256 numberOne,
        uint256 numberTwo,
        uint256 numberThree,
        uint256 numberFour
        )
        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!");
            require(numberThree >= minNumber && numberThree <= maxNumber, "The third number chosen is invalid!");
            require(numberFour >= minNumber && numberFour <= maxNumber, "The fourth chosen is invalid!");
            
            uint256 payment = SafeMath.add(powerFourBid, powerFourFee);
            uint256 totalPayment = SafeMath.add(payment, megaJackpotFee);
            
            require(msg.value == totalPayment, "Wrong payment value!");
            
            randomQueryId += 1;
            
            powerFourFeesToCollect ++;
            
            // 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\":4,\"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] = 4;
            
            powerNumberOne[queryId] = numberOne;
            powerNumberTwo[queryId] = numberTwo;
            powerNumberThree[queryId] = numberThree;
            powerNumberFour[queryId] = numberFour;
            
            powerFourJackpot += powerFourBid;
            
            megaJackpot += megaJackpotFee;

            totalGamesPlayed ++;
                
        }
/**
 * @dev Makes the bid to the PowerFour game.
 */