In [16]:
import deuces as de
import copy as cp
from deuces import Card
from deuces import Evaluator
from random import sample
import ctypes
import ctypes.util
import sys
from subprocess import call
import time
import numpy as np
import pickle
import random


evaluator = Evaluator()
deck_fresh = de.Deck()

player1_hand = deck_fresh.draw(2)
board = deck_fresh.draw(4)
iters = 100
win_not_discard = np.zeros([iters,1])
win_discard_one = np.zeros([iters,1])
win_discard_zero = np.zeros([iters,1])

np.random.seed(1)
start_time = time.time()

for i in range(0,iters):
    cards_in_play = cp.copy(board)
    cards_in_play.extend(player1_hand)
    sim_board = cp.copy(board)
    draw_deck = list(set(deck_fresh.cards)-set(cards_in_play))
    rest_of_cards_ix = sample(range(0, len(draw_deck)-1), 5-len(sim_board)+3 )
    sim_board.extend([draw_deck[j] for j in rest_of_cards_ix[3:]])
    villan_hand = [draw_deck[j] for j in rest_of_cards_ix[1:3]]
    
    hand_new_one = [draw_deck[rest_of_cards_ix[0]],player1_hand[1]]
    hand_new_zero = [player1_hand[0],draw_deck[rest_of_cards_ix[0]]]
    v_rank = evaluator.evaluate(sim_board,villan_hand)
    win_discard_zero[i] = evaluator.evaluate(sim_board, hand_new_one) < v_rank # win when discarding the first card
    win_discard_one[i] =1# evaluator.evaluate(sim_board, hand_new_zero) < v_rank # win when discarding the second card
    win_not_discard[i] =1# evaluator.evaluate(sim_board,player1_hand) < v_rank
    
print( "%s iterations --- %s seconds ---" % (iters , (time.time() - start_time)))
print ( "win perc. from discarding first card %s" % np.mean(win_discard_zero))
print ( "win perc. from discarding second card %s" % np.mean(win_discard_one))
print ("win perc. from not drawing %s" % np.mean(win_not_discard))
Card.print_pretty_cards(player1_hand) 

Card.print_pretty_cards(board)


100 iterations --- 0.0171830654144 seconds ---
win perc. from discarding first card 0.49
win perc. from discarding second card 0.38
win perc. from not drawing 0.26
  [ 6 ♦ ] , [ K ♣ ]  
  [ 3 ❤ ] , [ 7 ♣ ] , [ Q ♦ ] , [ 9 ♦ ]  

In [2]:
deck_fresh = de.Deck()

player1_hand = deck_fresh.draw(2)
board = deck_fresh.draw(4)

In [9]:
board = ['Qh', 'Kh']
cards_in_play = [Card.new(j) for j in board]

In [13]:
hand_new_one


Out[13]:
[134224677, 8406803]

In [11]:
print(Card.new('Kh'))


134228773

In [ ]: