

Link: http://codepad.org/ls6vBpu3 raw code | output | fork ]



Python , pasted on Jan 21:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 havepair = False havetrip = False havequad = False havefull = False haveflush = False haveroyal = False havestrait = False havetwopair = False straitflush = False handvalue = 0 enhandvalue = 0 strate = [] wins = 0 losses = 0 def strait ( x ): global havepair global havetrip global havequad global havefull global haveflush global haveroyal global havestrait global havetwopair global straitflush global strate haveflush = False if 'Hearts' in x [ 0 ] and 'Hearts' in x [ 1 ] and 'Hearts' in x [ 2 ] and 'Hearts' in x [ 3 ] and 'Hearts' in x [ 4 ]: haveflush = True elif 'Diamonds' in x [ 0 ] and 'Diamonds' in x [ 1 ] and 'Diamonds' in x [ 2 ] and 'Diamonds' in x [ 3 ] and 'Diamonds' in x [ 4 ]: haveflush = True elif 'Spades' in x [ 0 ] and 'Spades' in x [ 1 ] and 'Spades' in x [ 2 ] and 'Spades' in x [ 3 ] and 'Spades' in x [ 4 ]: haveflush = True elif 'Clubs' in x [ 0 ] and 'Clubs' in x [ 1 ] and 'Clubs' in x [ 2 ] and 'Clubs' in x [ 3 ] and 'Clubs' in x [ 4 ]: haveflush = True strate = [] havestrait = False val0 = x [ 0 ][ 0 ] val1 = x [ 1 ][ 0 ] val2 = x [ 2 ][ 0 ] val3 = x [ 3 ][ 0 ] val4 = x [ 4 ][ 0 ] vals = [ val0 , val1 , val2 , val3 , val4 ] vals . sort () if '2' in vals : strate . append ( 1 ) if '3' in vals : strate . append ( 2 ) if '4' in vals : strate . append ( 3 ) if '5' in vals : strate . append ( 4 ) if '6' in vals : strate . append ( 5 ) if '7' in vals : strate . append ( 6 ) if '8' in vals : strate . append ( 7 ) if '9' in vals : strate . append ( 8 ) if '1' in vals : strate . append ( 9 ) if 'J' in vals : strate . append ( 10 ) if 'Q' in vals : strate . append ( 11 ) if 'K' in vals : strate . append ( 12 ) if 'A' in vals : strate . append ( 13 ) if len ( strate ) == 5 : if strate [ 0 ] + 1 == strate [ 1 ] and strate [ 0 ] + 2 == strate [ 2 ] and strate [ 0 ] + 3 == strate [ 3 ] and strate [ 0 ] + 4 == strate [ 4 ]: havestrait = True if havepair == True or havetrip == True or havequad == True or havefull == True : havestrait = False if haveflush == True and havestrait == True : straitflush = True haveflush = False havestrait = False if straitflush == True and '1' in vals and 'J' in vals and 'Q' in vals and 'K' in vals and 'A' in vals : haveroyal = True straitflush = False havestrait = False def occurences ( x ): global havetwopair global havepair global havetrip global havequad global havefull havetwopair = False havepair = False havetrip = False havequad = False havefull = False val0 = x [ 0 ][ 0 ] val1 = x [ 1 ][ 0 ] val2 = x [ 2 ][ 0 ] val3 = x [ 3 ][ 0 ] val4 = x [ 4 ][ 0 ] vals = [ val0 , val1 , val2 , val3 , val4 ] count0 = vals . count ( val0 ) count1 = vals . count ( val1 ) count2 = vals . count ( val2 ) count3 = vals . count ( val3 ) count4 = vals . count ( val4 ) counts = [ count0 , count1 , count2 , count3 , count4 ] if count0 == 2 or count1 == 2 or count2 == 2 or count3 == 2 or count4 == 2 : havepair = True if count0 == 3 or count1 == 3 or count2 == 3 or count3 == 3 or count4 == 3 : havetrip = True if count0 == 4 or count1 == 4 or count2 == 4 or count3 == 4 or count4 == 4 : havequad = True if havepair == True and havetrip == True : havefull = True havepair = False havetrip = False if havepair == True and havetrip == False : if counts . count ( 2 ) == 4 : havetwopair = True havepair = False havetrip = False def tradein ( x ): newcard = random . choice ( values ) + ' of ' + random . choice ( suits ) while newcard in cards : newcard = random . choice ( values ) + ' of ' + random . choice ( suits ) if newcard not in cards : cards [ x ] = newcard money = 1000 numberhands = 0 while money > 0 : print "You have:" print money print "Dollars" handvalue = 0 enhandvalue = 0 import random suits = [ 'Hearts' , 'Spades' , 'Clubs' , 'Diamonds' ] values = [ '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , '10' , 'Jack' , 'Queen' , 'King' , 'Ace' ] sv1 = random . choice ( values ) + ' of ' + random . choice ( suits ) sv2 = random . choice ( values ) + ' of ' + random . choice ( suits ) if sv2 == sv1 : while sv2 == sv1 : sv2 = random . choice ( values ) + ' of ' + random . choice ( suits ) sv3 = random . choice ( values ) + ' of ' + random . choice ( suits ) if sv3 == sv1 or sv3 == sv2 : while sv3 == sv1 or sv3 == sv2 : sv3 = random . choice ( values ) + ' of ' + random . choice ( suits ) sv4 = random . choice ( values ) + ' of ' + random . choice ( suits ) if sv4 == sv3 or sv4 == sv2 or sv4 == sv1 : while sv4 == sv3 or sv4 == sv2 or sv4 == sv1 : sv4 = random . choice ( values ) + ' of ' + random . choice ( suits ) sv5 = random . choice ( values ) + ' of ' + random . choice ( suits ) if sv5 == sv4 or sv5 == sv3 or sv5 == sv2 or sv5 == sv1 : while sv5 == sv4 or sv5 == sv3 or sv5 == sv2 or sv5 == sv1 : sv5 = random . choice ( values ) + ' of ' + random . choice ( suits ) cards = [ sv1 , sv2 , sv3 , sv4 , sv5 ] print '0. ' + cards [ 0 ] print '1. ' + cards [ 1 ] print '2. ' + cards [ 2 ] print '3. ' + cards [ 3 ] print '4. ' + cards [ 4 ] bet = False gamble = money + 1 while gamble > money : gamble = int ( raw_input ( "How much to bet on this hand? " )) if gamble > money : print "You dont have enough money to bet that much!" else : print "You have just bet:" print gamble print "Dollars" swapc = False while swapc == False : swap = str ( raw_input ( "Trade in cards? Y - N: " )) if swap == 'n' : swapc = True elif swap == 'y' : tradedin = False while tradedin == False : trade = int ( raw_input ( "Number of cards to trade in? 1, 2, 3: " )) if trade == 1 : onecard = int ( raw_input ( "Which card? 0, 1, 2, 3, 4: " )) tradein ( onecard ) tradedin = True swapc = True elif trade == 2 : twocards = str ( raw_input ( "Enter the cards you want to trade in unseperated.

e.g. for cards 0 and 3 enter 03 or 30 0, 1, 2, 3, 4: " )) frst = int ( twocards [ 0 ]) scnd = int ( twocards [ 1 ]) tradein ( frst ) tradein ( scnd ) tradedin = True swapc = True elif trade == 3 : threecards = str ( raw_input ( "Enter the cards you want to trade in unseperated.

e.g. for cards 0 and 2 and 3 enter 023 or 230 etc...

0, 1, 2, 3, 4: " )) frst = int ( threecards [ 0 ]) scnd = int ( threecards [ 1 ]) thrd = int ( threecards [ 2 ]) tradein ( frst ) tradein ( scnd ) tradein ( thrd ) tradedin = True swapc = True else : print "Please enter the amount of cards you wish to trade in (up to 3)" else : print "Please enter either 'y' for yes or 'n' for no" print '

' print "Your hand is:" print '

' print cards [ 0 ] print cards [ 1 ] print cards [ 2 ] print cards [ 3 ] print cards [ 4 ] print '

' occurences ( cards ) strait ( cards ) val0 = cards [ 0 ][ 0 ] val1 = cards [ 1 ][ 0 ] val2 = cards [ 2 ][ 0 ] val3 = cards [ 3 ][ 0 ] val4 = cards [ 4 ][ 0 ] vals = [ val0 , val1 , val2 , val3 , val4 ] if havepair == True : print "You have a pair!" handvalue = 14 elif havetwopair == True : print "You have two pair!" handvalue = 15 elif havetrip == True : print "You have 3 of a kind!" handvalue = 16 elif havestrait == True : print "You have a straight!" handvalue = 17 elif haveflush == True : print "You have a flush!" handvalue = 18 elif havefull == True : print "You have a full house!" handvalue = 19 elif havequad == True : print "You have 4 of a kind!" handvalue = 20 elif straitflush == True : print "You have a straight flush!" handvalue = 21 elif haveroyal == True : print "You have a royal flush!" handvalue = 22 if havepair == False and havetrip == False and havequad == False and havefull == False and haveflush == False and haveroyal == False and havestrait == False and havetwopair == False and straitflush == False : if 'A' in vals : handvalue = 13 print "You have high card Ace" elif 'K' in vals : handvalue = 12 print "You have high card King" elif 'Q' in vals : handvalue = 11 print "You have high card Queen" elif 'J' in vals : handvalue = 10 print "You have high card Jack" elif '1' in vals : handvalue = 9 print "You have high card Ten" elif '9' in vals : handvalue = 8 print "You have high card Nine" elif '8' in vals : handvalue = 7 print "You have high card Eight" elif '7' in vals : handvalue = 6 print "You have high card Seven" elif '6' in vals : handvalue = 5 print "You have high card Six" elif '5' in vals : handvalue = 4 print "You have high card Five" elif '4' in vals : handvalue = 3 print "You have high card Four" elif '3' in vals : handvalue = 2 print "You have high card Three" elif '2' in vals : handvalue = 1 print "You have high card Two" print '

' en1 = random . choice ( values ) + ' of ' + random . choice ( suits ) if en1 in cards : while en1 in cards : en1 = random . choice ( values ) + ' of ' + random . choice ( suits ) en2 = random . choice ( values ) + ' of ' + random . choice ( suits ) if en2 == en1 or en2 in cards : while en2 == en1 or en2 in cards : en2 = random . choice ( values ) + ' of ' + random . choice ( suits ) en3 = random . choice ( values ) + ' of ' + random . choice ( suits ) if en3 == en1 or en3 == en2 or en2 in cards : while en3 == en1 or en3 == en2 or en2 in cards : en3 = random . choice ( values ) + ' of ' + random . choice ( suits ) en4 = random . choice ( values ) + ' of ' + random . choice ( suits ) if en4 == en3 or en4 == en2 or en4 == en1 or en2 in cards : while en4 == en3 or en4 == en2 or en4 == en1 or en2 in cards : en4 = random . choice ( values ) + ' of ' + random . choice ( suits ) en5 = random . choice ( values ) + ' of ' + random . choice ( suits ) if en5 == en4 or en5 == en3 or en5 == en2 or en5 == en1 or en2 in cards : while en5 == en4 or en5 == en3 or en5 == en2 or en5 == en1 or en2 in cards : en5 = random . choice ( values ) + ' of ' + random . choice ( suits ) encards = [ en1 , en2 , en3 , en4 , en5 ] print "You opponents hand is:" print '

' print encards [ 0 ] print encards [ 1 ] print encards [ 2 ] print encards [ 3 ] print encards [ 4 ] print '

' occurences ( encards ) strait ( encards ) enval0 = encards [ 0 ][ 0 ] enval1 = encards [ 1 ][ 0 ] enval2 = encards [ 2 ][ 0 ] enval3 = encards [ 3 ][ 0 ] enval4 = encards [ 4 ][ 0 ] envals = [ enval0 , enval1 , enval2 , enval3 , enval4 ] if havepair == True : print "Your opponent has a pair!" enhandvalue = 14 elif havetwopair == True : print "Your opponent has two pair!" enhandvalue = 15 elif havetrip == True : print "Your opponent has 3 of a kind!" enhandvalue = 16 elif havestrait == True : print "Your opponent has a straight!" enhandvalue = 17 elif haveflush == True : print "Your opponent has a flush!" enhandvalue = 18 elif havefull == True : print "Your opponent has a full house!" enhandvalue = 19 elif havequad == True : print "Your opponent has 4 of a kind!" enhandvalue = 20 elif straitflush == True : print "Your opponent has a straight flush!" enhandvalue = 21 elif haveroyal == True : print "Your opponent has a royal flush!" enhandvalue = 22 elif havepair == False and havetrip == False and havequad == False and havefull == False and haveflush == False and haveroyal == False and havestrait == False and havetwopair == False and straitflush == False : if 'A' in envals : enhandvalue = 13 print "Your opponent has high card Ace" elif 'K' in envals : enhandvalue = 12 print "Your opponent has high card King" elif 'Q' in envals : enhandvalue = 11 print "Your opponent has high card Queen" elif 'J' in envals : enhandvalue = 10 print "Your opponent has high card Jack" elif '1' in envals : enhandvalue = 9 print "Your opponent has high card Ten" elif '9' in envals : enhandvalue = 8 print "Your opponent has high card Nine" elif '8' in envals : enhandvalue = 7 print "Your opponent has high card Eight" elif '7' in envals : enhandvalue = 6 print "Your opponent has high card Seven" elif '6' in envals : enhandvalue = 5 print "Your opponent has high card Six" elif '5' in envals : enhandvalue = 4 print "Your opponent has high card Five" elif '4' in envals : enhandvalue = 3 print "Your opponent has high card Four" elif '3' in envals : enhandvalue = 2 print "Your opponent has high card Three" elif '2' in envals : enhandvalue = 1 print "Your opponent has high card Two" print '

' if handvalue > enhandvalue : print '

' print "You win!" wins = wins + 1 print '

' print "Wins:" print wins print "Losses:" print losses money = money + gamble print '

' print "You now have:" print money print "Dollars" elif handvalue < enhandvalue : print '

' print "You lose!" losses = losses + 1 print '

' print "Wins:" print wins print "Losses:" print losses money = money - gamble print '

' print "You now have:" print money print "Dollars" elif handvalue == enhandvalue : print "Draw" print '

' print "Wins:" print wins print "Losses:" print losses print '

' print "You now have:" print money print "Dollars" else : print 'Bug report: email Noodlesgc@gmail.com' numberhands = numberhands + 1 print '

' if money == 0 : strnumberhands = str ( numberhands ) lose = "You have successfully lost $1000 in " + strnumberhands + " hands. Happy? " str ( raw_input ( lose ))



Output: 1 2 3 4 5 6 7 8 9 10 11 12 You have: 1000 Dollars 0. Ace of Hearts 1. 6 of Hearts 2. Jack of Clubs 3. King of Spades 4. 9 of Spades How much to bet on this hand? Traceback (most recent call last): Line 174, in <module> gamble = int(raw_input("How much to bet on this hand? ")) EOFError