Created
May 11, 2017 19:48
-
-
Save anonymous/984146cd5d8f50b2182603932dd822ea to your computer and use it in GitHub Desktop.
Created using browser-solidity: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://ethereum.github.io/browser-solidity/#version=soljson-v0.4.11+commit.68ef5810.js&optimize=undefined&gist=
This file contains 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.2; | |
contract Deck { | |
// returns random number from 0 to 51 | |
// let's say 'value' % 4 means suit (0 - Hearts, 1 - Spades, 2 - Diamonds, 3 - Clubs) | |
// 'value' / 4 means: 0 - King, 1 - Ace, 2 - 10 - pip values, 11 - Jacket, 12 - Queen | |
function deal(address player, uint8 cardNumber) | |
external | |
returns (uint8) | |
{ | |
uint b = block.number; | |
uint timestamp = block.timestamp; | |
return uint8(uint256(keccak256(block.blockhash(b), player, cardNumber, timestamp)) % 52); | |
} | |
function valueOf(uint8 card, bool isBigAce) | |
constant | |
external | |
returns (uint8) | |
{ | |
uint8 value = card / 4; | |
if (value == 0 || value == 11 || value == 12) { // Face cards | |
return 10; | |
} | |
if (value == 1 && isBigAce) { // Ace is worth 11 | |
return 11; | |
} | |
return value; | |
} | |
function equalDenomination(uint8 card1, uint8 card2) | |
constant | |
external | |
returns (bool) | |
{ | |
return card1 / 4 == card2 / 4; | |
} | |
function isAce(uint8 card) | |
constant | |
external | |
returns (bool) | |
{ | |
return card / 4 == 1; | |
} | |
function isTen(uint8 card) | |
constant | |
external | |
returns (bool) | |
{ | |
return card / 4 == 10; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment