Open Side Menu Go to the Top
Register
Found a code on pastebin titled "Poker Hands" - What is it? Found a code on pastebin titled "Poker Hands" - What is it?

07-12-2015 , 11:51 PM
So I was literally just randomly clicking new pastebin posts, because sometimes I stumble across interesting things, when I found this.

Anyone know what it is doing?

Code:
/**
 * Tittle:      10315 - Poker Hands
 * Author:      Cheng-Shih, Wong
 * Date:        2015/06/17
 */
 
// include files
#include <bits/stdc++.h>
 
using namespace std;
 
// definitions
#define FOR(i,a,b) for( int i=(a),_n=(b); i<=_n; ++i )
#define clr(x,v) memset( x, v, sizeof(x) )
 
class Card {
public:
        char suit;
        int val;
 
        Card( char _v='1', char _s='1' ) {
                val = toVal(_v);
                suit = _s;
        }
 
        bool get( void ) {
                char ts[10];
                if( scanf( "%s", ts )!=1 ) return false;
                val = toVal(ts[0]);
                suit = ts[1];
                return true;
        }
 
        int toVal( char _val ) {
                switch( _val ) {
                case '2': return 1;
                case '3': return 2;
                case '4': return 3;
                case '5': return 4;
                case '6': return 5;
                case '7': return 6;
                case '8': return 7;
                case '9': return 8;
                case 'T': return 9;
                case 'J': return 10;
                case 'Q': return 11;
                case 'K': return 12;
                case 'A': return 13;
                }
        }
 
        const bool operator<( const Card &op ) const {
                return val<op.val;
        }
};
 
typedef map<char,int> MCI;
typedef map<int,int> MII;
typedef pair<char,int> PCI;
typedef pair<int,int> PII;
 
// declarations
Card cards[15];
 
// functions
PII cardValue( Card *card )
{
        bool flush = true;
        bool straight = true;
        int four = 0;
        int three = 0;
        int pair = 0;
        int pr[2];
        MCI suit;
        MII val;
        PII ret = PII(0,0);
 
        sort( card, card+5 );
 
        FOR( i, 0, 3 )
                if( card[i].val+1 != card[i+1].val )
                        straight = false;
 
        FOR( i, 0, 4 ) {
                suit[card[i].suit]++;
                val[card[i].val]++;
        }
       
        if( suit.size()!=1 )
                flush = false;
 
        for( PII p : val ) {
                if( p.second==4 ) four = p.first;
                else if( p.second==3 ) three = p.first;
                else if( p.second==2 ) pr[pair++] = p.first;
        }
 
        if( pair==2 && pr[0]<pr[1] )
                swap( pr[0], pr[1] );
 
        int base = 1;
        int allCards = 0;
        FOR( i, 0, 4 ) {
                allCards += base*card[i].val;
                base *= 100;
        }
 
        if( straight && flush ) {
                ret.first = 8;
                ret.second = card[4].val;
        } else if( four ) {
                ret.first = 7;
                ret.second = four;
        } else if( three && pair ) {
                ret.first = 6;
                ret.second = three;
        } else if( flush ) {
                ret.first = 5;
                ret.second = allCards;
        } else if( straight ) {
                ret.first = 4;
                ret.second = card[4].val;
        } else if( three ) {
                ret.first = 3;
                ret.second = three;
        } else if( pair==2 ) {
                ret.first = 2;
                ret.second = pr[0]*10000+pr[1]*100;
                for( PII p : val ) if( p.second==1 )
                        ret.second += p.first;
        } else if( pair==1 ) {
                ret.first = 1;
                ret.second = pr[0]*1000000;
                base = 10000;
                for( int i=4; i>=0; --i ) if( val[card[i].val]==1 ) {
                        ret.second += base*card[i].val;
                        base /= 100;
                }
        } else {
                ret.first = 0;
                ret.second = allCards;
        }
       
        return ret;
}
 
void solve( void )
{
        PII white, black;
        black = cardValue(cards+1);
        white = cardValue(cards+6);
 
        if( black > white ) puts("Black wins.");
        else if( black < white ) puts("White wins.");
        else puts("Tie.");
}
 
// main function
int main( void )
{
       
        // input
        while( cards[1].get() ) {
                FOR( i, 2, 10 )
                        cards[i].get();
 
                solve();
        }
       
        return 0;
}
Found a code on pastebin titled &quot;Poker Hands&quot; - What is it? Quote
07-13-2015 , 12:04 AM
It simulates a poker hand between players and says who wins or if there is a tie.
Found a code on pastebin titled &quot;Poker Hands&quot; - What is it? Quote
07-13-2015 , 01:46 AM
This looks like pokerstars source code. How did you get this?!? I would take this post down and contact pokerstars and paste bin immediately. Having this code online is a huge security risk to players.
Found a code on pastebin titled &quot;Poker Hands&quot; - What is it? Quote
07-13-2015 , 01:51 AM
lol
Found a code on pastebin titled &quot;Poker Hands&quot; - What is it? Quote
07-13-2015 , 12:02 PM
Are you able to run the code?

What part of it do you find confusing?
Found a code on pastebin titled &quot;Poker Hands&quot; - What is it? Quote

      
m