Post
Topic
Board Altcoin Discussion
Re: [ANN][POK] Pokercoin Reboot - 100,000 POK Premine DESTROYED!
by
hotcoldcoin
on 06/09/2013, 09:26:02 UTC
New! - Pokercoin 1.0.2 code now released!  See https://github.com/superblocks/Pokercoin

This update adds a checkpoint at block #15000, and a new rpc command: getcards.

getcards draws 5 playing cards based on a block hash.  It's also added to getinfo, based on the current block hash:

Code:
   "blocks" : 15691,
    "cards" : "Ace of Diamonds, Queen of Spades, 8 of Diamonds, 10 of Hearts, 4 of Hearts, ",

Example usage:   Get a hand from the pokercoin genesis hash:
Code:
# ./pokercoind getblockhash 0
5b08cbe328392be8151f5deec2dc92e7609dcbd20e0dac335904ccf538df68e8

# ./pokercoind getcards 5b08cbe328392be8151f5deec2dc92e7609dcbd20e0dac335904ccf538df68e8
5 of Hearts, Queen of Hearts, 2 of Hearts, 3 of Hearts, 2 of Hearts,

The getcards command will take in any well formed hash: 64 chars long, only hexademical characters.

Cards are determined by splitting the block hash into 2 character segments.  For each segment, first character is the card, and second character is the suit.  Here's the code to show how the cards are decided:

Code: (https://github.com/superblocks/Pokercoin/blob/master/src/bitcoinrpc.cpp#L403)
//
// Get a Playing Card - version 0.0.1
//
std::string getcard( char c )
{
    switch( std::tolower(c) ) {
        case '1': return "Ace";
        case '2': return "2";
        case '3': return "3";
        case '4': return "4";
        case '5': return "5";
        case '6': return "6";
        case '7': return "7";
        case '8': return "8";
        case '9': return "9";
        case 'a': return "10";
        case 'b': return "Jack";
        case 'c': return "Queen";
        case 'd': return "King";
        default: case 'e': case 'f': case '0': return "Joker";
    }
}

//
// Get the Suit of a Playing Card - version 0.0.1
//
std::string getsuit( char c )
{
    switch( std::tolower(c) ) {
        default: return "ERROR";
        case '0': case '1': case '2': case '3': return "Clubs";
        case '4': case '5': case '6': case '7': return "Diamonds";
        case '8': case '9': case 'a': case 'b': return "Hearts";
        case 'c': case 'd': case 'e': case 'f': return "Spades";
    }
}

//
// Get a Hand of Playing Cards - version 0.0.1
//
std::string GetCards( std::string hash, int limit = 5 )
{
    if( hash.length() != 64 ) { return "ERROR: hash is not 64 chars long"; }
    std::string deck, check;
    int count = 0;
    for (int i = 0; i < hash.length(); i+=2) {
        check = hash.substr(i,2);
        if( check[0] == '0' || check[0] == 'e' || check[0] == 'f' )
            continue;
        deck.append( getcard(check[0]) ).append( " of " ).append( getsuit(check[1]) ).append( ", " );
        count++;
        if( count == limit )
            break;
    }
    if( count != limit )
        deck.append( "ERROR: not enough valid cards in the deck" );
    return deck;
}


//
// Get a Hand of Playing Cards - RPC call - version 0.0.1
//
Value getcards(const Array& params, bool fHelp)
{
    if (fHelp || params.size() != 1)
        throw runtime_error(
            "getcards \n"
            "Returns a hand of playing cards.");

    std::string strHash = params[0].get_str();

    return GetCards(strHash);
}

All very beta and  proof-of-concept now, but may be something that can be built upon for gaming Wink