Created
August 4, 2018 00:53
-
-
Save listenlight/42f5297aa4de8d6461eb0ad368c8dec3 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.24+commit.e67f0147.js&optimize=true&gist=
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.24; | |
/* To Do | |
-- compare values of two cards | |
-- for matching against cards already drawn, just loop on random | |
-- match values in hand and assign uint handScore | |
-- betting | |
-- paying in/out | |
*/ | |
contract ChoicePoker { | |
uint8[52] deck; // 52 cards, jokers make 54 cards | |
address public offering; | |
struct Match { | |
address opponent; | |
// bool playersTurn; | |
// uint[5][1] results; | |
// address winner; | |
// array of cards played, remove from deck after drawn | |
} | |
// store all gameplay on client (no bc time delays, player pauses) | |
struct Game { | |
bool playerOfferingDrawsHigh; | |
bool over; | |
address turn; | |
address winner; | |
} | |
// struct Hand { | |
// } | |
mapping(address => Match[]) private matches; | |
constructor() public payable { | |
offering = address(0); | |
// for(uint8 i = 1; i < 53; i++) { | |
// deck[i - 1] = i; | |
// } | |
} | |
modifier noExistingOffer() { | |
require(offering != msg.sender, "Already waiting for a match"); | |
_; | |
} | |
function offer() public payable noExistingOffer { | |
if(offering == address(0)) { | |
offering = msg.sender; | |
} else { | |
matches[offering].push(Match({ opponent: msg.sender })); | |
// bool playerOneDrawsHighCard = playersDrawForHighCard(); | |
offering = address(0); | |
} | |
} | |
function playersDrawForHighCard() internal view returns (bool) { | |
// get random two cards from deck | |
uint _cardOne = random(52); | |
uint _cardTwo = random(52); | |
while(_cardOne == _cardTwo) { | |
_cardTwo = random(52); | |
} | |
// compare values of the cards | |
} | |
function drawCard(uint8[] _drawnCards) internal view returns (uint) { | |
// draw another card if random matches anything from the _drawnCards | |
_drawnCards; | |
return random(52); | |
} | |
// return a pseudo random number between lower and upper bounds | |
// given the number of previous blocks it should hash. | |
// see https://github.com/axiomzen/eth-random (nb on bitslicing this value) | |
function random(uint upper) private view returns (uint randomNumber) { | |
return uint(keccak256(bytes32ToBytes(bytes32(block.number - 1)))) % upper; | |
} | |
function compareTwoCards(uint8 _a, uint8 _b) private pure returns (uint8 _cardId) { | |
require(_a != _b); | |
return _cardId; | |
} | |
// keccak256 only accepts 'bytes' type | |
function bytes32ToBytes(bytes32 data) internal pure returns (bytes) { | |
uint i = 0; | |
while (i < 32 && uint(data[i]) != 0) { | |
++i; | |
} | |
bytes memory result = new bytes(i); | |
i = 0; | |
while (i < 32 && data[i] != 0) { | |
result[i] = data[i]; | |
++i; | |
} | |
return result; | |
} | |
// player var | |
// game var for 2 players | |
// payment var for game, incl. total of 0.2 ante | |
// Game | |
// player 1 draws card | |
// player 2 draws card | |
// player with high card bets first | |
// game is won by winning best of 3 hands | |
// player with high card bets first and draws 2nd | |
// players draw 5 cards | |
// players have 1 chance, before betting, to exchange 1 to 5 cards | |
// player with high card bets, then the other player can fold, call, or raise | |
// (can reraise?) | |
// call or fold forfeits choice of high or low hand to win | |
// (implying choice of high/low hand is made after betting, before show) | |
// higher betting player declares hi/lo choice for best hand | |
// players show cards, hand is scored, game is best of 5 hands | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.24; | |
import "./omnicat.sol"; | |
contract Dass42 is OmniCAT { | |
function setScores(address _contributor, uint8[42] _values) public payable { | |
uint8 i = 0; | |
while(i < 42) { | |
contributors[_contributor].dass42[i] = _values[i++]; | |
} | |
contributors[_contributor].stored["dass42"] = true; | |
} | |
// get submitted scores for a contributor | |
// and then compute/display results in the client | |
function getScores(address _contributor) public payable returns (uint8 _d, uint8 _a, uint8 _s) { | |
require(contributors[_contributor].stored["dass42"]); | |
_d = getDepressionScores(_contributor); | |
_a = getAnxietyScores(_contributor); | |
_s = getStressScores(_contributor); | |
return (_d, _a, _s); | |
} | |
function getDepressionScores(address _contributor) internal view returns (uint8 _d) { | |
// Depression statements # 3, 5, 10, 13, 16, 17, 21, 24, 26, 31, 34, 37, 38, 42 | |
_d = contributors[_contributor].dass42[2]; | |
_d += contributors[_contributor].dass42[4]; | |
_d += contributors[_contributor].dass42[9]; | |
_d += contributors[_contributor].dass42[12]; | |
_d += contributors[_contributor].dass42[15]; | |
_d += contributors[_contributor].dass42[16]; | |
_d += contributors[_contributor].dass42[20]; | |
_d += contributors[_contributor].dass42[23]; | |
_d += contributors[_contributor].dass42[25]; | |
_d += contributors[_contributor].dass42[30]; | |
_d += contributors[_contributor].dass42[33]; | |
_d += contributors[_contributor].dass42[36]; | |
_d += contributors[_contributor].dass42[37]; | |
_d += contributors[_contributor].dass42[41]; | |
return _d; | |
} | |
function getAnxietyScores(address _contributor) internal view returns (uint8 _a) { | |
// Anxiety statements # 2, 4, 7, 9, 15, 19, 20, 23, 25, 28, 30, 36, 40, 41 | |
_a = contributors[_contributor].dass42[1]; | |
_a += contributors[_contributor].dass42[3]; | |
_a += contributors[_contributor].dass42[6]; | |
_a += contributors[_contributor].dass42[8]; | |
_a += contributors[_contributor].dass42[14]; | |
_a += contributors[_contributor].dass42[18]; | |
_a += contributors[_contributor].dass42[19]; | |
_a += contributors[_contributor].dass42[22]; | |
_a += contributors[_contributor].dass42[24]; | |
_a += contributors[_contributor].dass42[27]; | |
_a += contributors[_contributor].dass42[29]; | |
_a += contributors[_contributor].dass42[35]; | |
_a += contributors[_contributor].dass42[39]; | |
_a += contributors[_contributor].dass42[40]; | |
return _a; | |
} | |
function getStressScores(address _contributor) internal view returns (uint8 _s) { | |
// Stress statements # 1, 6, 8, 11, 12, 14, 18, 22, 27, 29, 32, 33, 35, 39 | |
_s = contributors[_contributor].dass42[0]; | |
_s += contributors[_contributor].dass42[5]; | |
_s += contributors[_contributor].dass42[7]; | |
_s += contributors[_contributor].dass42[10]; | |
_s += contributors[_contributor].dass42[11]; | |
_s += contributors[_contributor].dass42[13]; | |
_s += contributors[_contributor].dass42[17]; | |
_s += contributors[_contributor].dass42[21]; | |
_s += contributors[_contributor].dass42[26]; | |
_s += contributors[_contributor].dass42[28]; | |
_s += contributors[_contributor].dass42[32]; | |
_s += contributors[_contributor].dass42[33]; | |
_s += contributors[_contributor].dass42[34]; | |
_s += contributors[_contributor].dass42[38]; | |
return _s; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.24; | |
import "./omnicat.sol"; | |
contract IronLevels is OmniCAT { | |
mapping (bytes32 => uint8) optimal; | |
mapping (bytes32 => uint8[2][2]) normal; | |
mapping (bytes32 => uint16[2][2]) suboptimal; | |
constructor() public payable { | |
optimal["SerumIron"] = 20; | |
normal["SerumIron"] = [[15, 19], [21, 25]]; | |
suboptimal["SerumIron"] = [[10, 14], [26, 33]]; | |
optimal["TransferrinIbc"] = 60; | |
normal["TransferrinIbc"] = [[55, 59], [61, 65]]; | |
suboptimal["TransferrinIbc"] = [[45, 54], [66, 70]]; | |
optimal["TransferrinSaturation"] = 40; | |
normal["TransferrinSaturation"] = [[35, 39], [41, 45]]; | |
suboptimal["TransferrinSaturation"] = [[16, 34], [46, 50]]; | |
optimal["SerumFerritinAssay"] = 150; | |
normal["SerumFerritinAssay"] = [[130, 149], [151, 180]]; | |
suboptimal["SerumFerritinAssay"] = [[uint16(20), uint16(129)], [uint16(181), 290]]; | |
} | |
function setValues(address _contributor, uint16 _si, uint16 _tibc, uint16 _ts, uint16 _sfa) public payable { | |
contributors[_contributor].ironLevels[0] = _si; // SerumIron | |
contributors[_contributor].ironLevels[1] = _tibc; // TransferrinIbc | |
contributors[_contributor].ironLevels[2] = _ts; // TransferrinSaturation | |
contributors[_contributor].ironLevels[3] = _sfa; // SerumFerritinAssay | |
contributors[_contributor].stored["ironLevels"] = true; | |
} | |
// Note: use returned _submittedValue and _optimalValue | |
// on the client side to find percent from optimal | |
function checkValue(bytes32 _name, uint16 _value) public view returns (string _report, uint16 _submittedValue, int8 _optimalValue) { | |
if (compareStrings(_name, "SerumIron")) { | |
if (_value == optimal["SerumIron"]) { | |
_report = "Optimal SerumIron Level"; | |
} else if (_value >= normal["SerumIron"][0][0] && _value <= normal["SerumIron"][0][1]) { | |
_report = "Normal Lower SerumIron Level"; | |
} else if (_value >= normal["SerumIron"][1][0] && _value <= normal["SerumIron"][1][1]) { | |
_report = "Normal Higher SerumIron Level"; | |
} else if (_value >= suboptimal["SerumIron"][0][0] && _value <= suboptimal["SerumIron"][0][1]) { | |
_report = "Suboptimal Lower SerumIron Level"; | |
} else if (_value >= suboptimal["SerumIron"][1][0] && _value <= suboptimal["SerumIron"][1][1]) { | |
_report = "Suboptimal Higher SerumIron Level"; | |
} else if (_value < suboptimal["SerumIron"][0][0]) { | |
_report = "Abnormal Lower SerumIron Level"; | |
} else if (_value > suboptimal["SerumIron"][1][0]) { | |
_report = "Abnormal Higher SerumIron Level"; | |
} | |
} else if (compareStrings(_name, "TransferrinIbc")) { | |
if (_value == optimal["TransferrinIbc"]) { | |
_report = "Optimal TransferrinIBC Level"; | |
} else if (_value >= normal["TransferrinIbc"][0][0] && _value <= normal["TransferrinIbc"][0][1]) { | |
_report = "Normal Lower TransferrinIBC Level"; | |
} else if (_value >= normal["TransferrinIbc"][1][0] && _value <= normal["TransferrinIbc"][1][1]) { | |
_report = "Normal Higher TransferrinIBC Level"; | |
} else if (_value >= suboptimal["TransferrinIbc"][0][0] && _value <= suboptimal["TransferrinIbc"][0][1]) { | |
_report = "Suboptimal Lower TransferrinIBC Level"; | |
} else if (_value >= suboptimal["TransferrinIbc"][1][0] && _value <= suboptimal["TransferrinIbc"][1][1]) { | |
_report = "Suboptimal Higher TransferrinIBC Level"; | |
} else if (_value < suboptimal["TransferrinIbc"][0][0]) { | |
_report = "Abnormal Lower TransferrinIBC Level"; | |
} else if (_value > suboptimal["TransferrinIbc"][1][0]) { | |
_report = "Abnormal Higher TransferrinIBC Level"; | |
} | |
} else if (compareStrings(_name, "TransferrinSaturation")) { | |
if (_value == optimal["TransferrinSaturation"]) { | |
_report = "Optimal TransferrinSaturation Level"; | |
} else if (_value >= normal["TransferrinSaturation"][0][0] && _value <= normal["TransferrinSaturation"][0][1]) { | |
_report = "Normal Lower TransferrinSaturation Level"; | |
} else if (_value >= normal["TransferrinSaturation"][1][0] && _value <= normal["TransferrinSaturation"][1][1]) { | |
_report = "Normal Higher TransferrinSaturation Level"; | |
} else if (_value >= suboptimal["TransferrinSaturation"][0][0] && _value <= suboptimal["TransferrinSaturation"][0][1]) { | |
_report = "Suboptimal Lower TransferrinSaturation Level"; | |
} else if (_value >= suboptimal["TransferrinSaturation"][1][0] && _value <= suboptimal["TransferrinSaturation"][1][1]) { | |
_report = "Suboptimal Higher TransferrinSaturation Level"; | |
} else if (_value < suboptimal["TransferrinSaturation"][0][0]) { | |
_report = "Abnormal Lower TransferrinSaturation Level"; | |
} else if (_value > suboptimal["TransferrinSaturation"][1][0]) { | |
_report = "Abnormal Higher TransferrinSaturation Level"; | |
} | |
} else if (compareStrings(_name, "SerumFerritinAssay")) { | |
if (_value == optimal["SerumFerritinAssay"]) { | |
_report = "Optimal SerumFerritinAssay Level"; | |
} else if (_value >= normal["SerumFerritinAssay"][0][0] && _value <= normal["SerumFerritinAssay"][0][1]) { | |
_report = "Normal Lower SerumFerritinAssay Level"; | |
} else if (_value >= normal["SerumFerritinAssay"][1][0] && _value <= normal["SerumFerritinAssay"][1][1]) { | |
_report = "Normal Higher SerumFerritinAssay Level"; | |
} else if (_value >= suboptimal["SerumFerritinAssay"][0][0] && _value <= suboptimal["SerumFerritinAssay"][0][1]) { | |
_report = "Suboptimal Lower SerumFerritinAssay Level"; | |
} else if (_value >= suboptimal["SerumFerritinAssay"][1][0] && _value <= suboptimal["SerumFerritinAssay"][1][1]) { | |
_report = "Suboptimal Higher SerumFerritinAssay Level"; | |
} else if (_value < suboptimal["SerumFerritinAssay"][0][0]) { | |
_report = "Abnormal Lower SerumFerritinAssay Level"; | |
} else if (_value > suboptimal["SerumFerritinAssay"][1][0]) { | |
_report = "Abnormal Higher SerumFerritinAssay Level"; | |
} | |
} else { | |
_report = "Please check name is one of SerumIron, TransferrinIbc, TransferrinSaturation, or SerumFerritinAssay"; | |
} | |
return (_report, _value, int8(getOptimalValues(_name))); | |
} | |
function getOptimalValues(bytes32 _name) public view returns (uint8) { | |
if (compareStrings(_name, "SerumIron")) { | |
return optimal["SerumIron"]; | |
} else if (compareStrings(_name, "TransferrinIbc")) { | |
return optimal["TransferrinIbc"]; | |
} else if (compareStrings(_name, "TransferrinSaturation")) { | |
return optimal["TransferrinSaturation"]; | |
} else if (compareStrings(_name, "SerumFerritinAssay")) { | |
return optimal["SerumFerritinAssay"]; | |
} | |
} | |
function getNormalValues(bytes32 _name) public view returns (uint8[2][2]) { | |
if (compareStrings(_name, "SerumIron")) { | |
return normal["SerumIron"]; | |
} else if (compareStrings(_name, "TransferrinIbc")) { | |
return normal["TransferrinIbc"]; | |
} else if (compareStrings(_name, "TransferrinSaturation")) { | |
return normal["TransferrinSaturation"]; | |
} else if (compareStrings(_name, "SerumFerritinAssay")) { | |
return normal["SerumFerritinAssay"]; | |
} | |
} | |
function getSuboptimalValues(bytes32 _name) public view returns (uint16[2][2]) { | |
if (compareStrings(_name, "SerumIron")) { | |
return suboptimal["SerumIron"]; | |
} else if (compareStrings(_name, "TransferrinIbc")) { | |
return suboptimal["TransferrinIbc"]; | |
} else if (compareStrings(_name, "TransferrinSaturation")) { | |
return suboptimal["TransferrinSaturation"]; | |
} else if (compareStrings(_name, "SerumFerritinAssay")) { | |
return suboptimal["SerumFerritinAssay"]; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.24; | |
contract OmniCAT { | |
struct Contribution { | |
mapping (bytes32 => bool) stored; // stored["dass42"] = true | |
uint8[42] dass42; // these two seem out of place from their own contract | |
uint16[4] ironLevels; | |
} | |
// or address => Contribution[] | |
mapping (address => Contribution) contributors; | |
function compareStrings(bytes32 a, bytes32 b) internal pure returns (bool) { | |
return keccak256(bytes32ToBytes(a)) == keccak256(bytes32ToBytes(b)); | |
} | |
function bytes32ToBytes(bytes32 data) internal pure returns (bytes) { | |
uint i = 0; | |
while (i < 32 && uint(data[i]) != 0) { | |
++i; | |
} | |
bytes memory result = new bytes(i); | |
i = 0; | |
while (i < 32 && data[i] != 0) { | |
result[i] = data[i]; | |
++i; | |
} | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment