Ejemplo n.º 1
0
def simulateOld(myHand, boardCards, numBoardCards, numSimulations):
    wins = 0
    if (numBoardCards == 3 or numBoardCards == 4):
        for x in xrange(numSimulations):
            cardSet = set(boardCards)
            for card in myHand:
                cardSet.add(card)
            newCards = PP.generateHand(9 - numBoardCards, cardSet)
            slicePoint = 5 - numBoardCards
            fakeBoard = boardCards + newCards[0:slicePoint]
            fakeOpponent = newCards[slicePoint:]
            myBest = PP.findBestHand(myHand, fakeBoard)
            opponentBest = PP.findBestHand(fakeOpponent, fakeBoard)
            if PP.isBetterHand(myBest[0], opponentBest[0]) == 1: wins += 1
        winPercentage = 1.0 * wins / numSimulations
        return winPercentage

    if (numBoardCards == 5):
        myBest = PP.findBestHand(myHand, boardCards)
        for x in xrange(0, numSimulations):
            cardSet = set(boardCards)
            for card in myHand:
                cardSet.add(card)
            fakeOpponent = PP.generateHand(4, cardSet)
            opponentBest = PP.findBestHand(fakeOpponent, boardCards)
            if PP.isBetterHand(myBest[0], opponentBest[0]) == 1: wins += 1
        winPercentage = 1.0 * wins / numSimulations
        return winPercentage
Ejemplo n.º 2
0
def simulateOld(myHand, boardCards, numBoardCards, numSimulations):
    wins = 0
    if (numBoardCards == 3 or numBoardCards == 4):
        for x in xrange(numSimulations):
            cardSet = set(boardCards)
            for card in myHand: cardSet.add(card)
            newCards = PP.generateHand(9-numBoardCards, cardSet)
            slicePoint = 5 - numBoardCards
            fakeBoard = boardCards + newCards[0:slicePoint]
            fakeOpponent = newCards[slicePoint:]
            myBest = PP.findBestHand(myHand, fakeBoard)
            opponentBest = PP.findBestHand(fakeOpponent, fakeBoard)
            if PP.isBetterHand(myBest[0], opponentBest[0]) == 1 : wins+=1
        winPercentage = 1.0*wins/numSimulations
        return winPercentage

    if(numBoardCards == 5):
        myBest = PP.findBestHand(myHand, boardCards)
        for x in xrange(0,numSimulations):
            cardSet = set(boardCards)
            for card in myHand: cardSet.add(card)
            fakeOpponent = PP.generateHand(4, cardSet)
            opponentBest = PP.findBestHand(fakeOpponent, boardCards)
            if PP.isBetterHand(myBest[0], opponentBest[0]) == 1 : wins+=1
        winPercentage = 1.0*wins/numSimulations
        return winPercentage
Ejemplo n.º 3
0
def createEvalCSV():
	allCards = []
	for num in xrange(2,15):
		for suit in ['c','d','h','s']:
			allCards.append((num, suit))
	translationDict = loadTranslationDict()
	allHands = combinations(allCards,5)

	handFile = open('handFile.csv', 'wt')
	writer = csv.writer(handFile)
	for hand in allHands:
		hand = sorted(hand, key= lambda x: (x[0], x[1]), reverse = True)
		handValue = PP.findHandValue(hand)
		handString = ''
		for card in hand:
			key = str(card[0]) + card[1]
			handString += translationDict[key]
		handValueString = ''
		for num in handValue:
			if num < 10: addHand = "0" + str(num)
			else: addHand = str(num)
			handValueString += addHand
		writer.writerow((handString , handValueString))
	handfile.close()
	return 0
Ejemplo n.º 4
0
def createEvalCSV():
	allCards = []
	for num in xrange(2,15):
		for suit in ['c','d','h','s']:
			allCards.append((num, suit))
	translationDict = loadTranslationDict()
	allHands = combinations(allCards,5)

	handFile = open('handFile.csv', 'wt')
	writer = csv.writer(handFile)
	for hand in allHands:
		hand = sorted(hand, key= lambda x: (x[0], x[1]), reverse = True)
		handValue = PP.findHandValue(hand)
		handString = ''
		for card in hand:
			key = str(card[0]) + card[1]
			handString += translationDict[key]
		handValueString = ''
		for num in handValue:
			if num < 10: addHand = "0" + str(num)
			else: addHand = str(num)
			handValueString += addHand
		writer.writerow((handString , handValueString))
	handfile.close()
	return 0
Ejemplo n.º 5
0
def simulate(myHand, boardCards, numBoardCards, numSimulations):
    if (numBoardCards == 3):
        wins = 0
        for x in range(0, numSimulations):
            cardSet = set(boardCards)
            for card in myHand:
                cardSet.add(card)
            newCards = []
            for i in range(0, 6):
                card = PP.pickRandomCard(cardSet)
                cardSet.add(card)
                newCards.append(card)
            fakeBoard = boardCards + newCards[0:2]
            fakeOpponent = newCards[2:]
            myBest = PP.findBestHand(myHand, fakeBoard)
            opponentBest = PP.findBestHand(fakeOpponent, fakeBoard)
            if PP.isBetterHand(myBest[0], opponentBest[0]) == 1: wins += 1
        winPercentage = 1.0 * wins / numSimulations
        return winPercentage

    if (numBoardCards == 4):
        wins = 0
        for x in range(0, numSimulations):
            cardSet = set(boardCards)
            for card in myHand:
                cardSet.add(card)
            newCards = []
            for i in range(0, 5):
                card = PP.pickRandomCard(cardSet)
                cardSet.add(card)
                newCards.append(card)
            fakeBoard = boardCards + newCards[0:1]
            fakeOpponent = newCards[1:]
            myBest = PP.findBestHand(myHand, fakeBoard)
            opponentBest = PP.findBestHand(fakeOpponent, fakeBoard)
            if PP.isBetterHand(myBest[0], opponentBest[0]) == 1: wins += 1
        winPercentage = 1.0 * wins / numSimulations
        return winPercentage

    if (numBoardCards == 5):
        wins = 0
        myBest = PP.findBestHand(myHand, boardCards)
        for x in range(0, numSimulations):
            cardSet = set(boardCards)
            for card in myHand:
                cardSet.add(card)
            fakeOpponent = []
            for i in range(0, 4):
                card = PP.pickRandomCard(cardSet)
                cardSet.add(card)
                fakeOpponent.append(card)
            opponentBest = PP.findBestHand(fakeOpponent, boardCards)
            if PP.isBetterHand(myBest[0], opponentBest[0]) == 1: wins += 1
        winPercentage = 1.0 * wins / numSimulations
        return winPercentage
Ejemplo n.º 6
0
'''
f = open('data.csv', 'w')

for x in range(0, 2000):
	myHand = PP.generateTestHand(4)
	boardCards = PP.generateTestHand(3)
	bestHandRank = PP.findBestHand(myHand, boardCards)
	simulationRank = Simulation.simulate(myHand, boardCards, 3, 100)
	print "BestHandRank: ",bestHandRank[0][0]," SimulationRank: ",simulationRank
	f.write(str(bestHandRank[0][0]*10 + (bestHandRank[0][1]/1.4))+","+str(simulationRank)+"\n")

f.close()

'''
myHand = list()
boardCards = list()
for x in range(0, 1000):
	myHand.append(PP.generateTestHand(4))
	boardCards.append(PP.generateTestHand(3))

startTime = time.time()
print startTime

for x in range(0,1000):
	bestHandRank = PP.findBestHand(myHand[x], boardCards[x])
	#simulationRank = Simulation.simulate(myHand[x], boardCards[x], 3, 100)
endTime = time.time()

print endTime
print endTime - startTime
Ejemplo n.º 7
0
def simulate(myHand, boardCards, numBoardCards, numSimulations):
    if(numBoardCards == 3):
        wins = 0
        for x in range(0,numSimulations):
            cardSet = set(boardCards)
            for card in myHand: cardSet.add(card)
            newCards = []
            for i in range(0,6):
                card = PP.pickRandomCard(cardSet)
                cardSet.add(card)
                newCards.append(card)
            fakeBoard = boardCards + newCards[0:2]
            fakeOpponent = newCards[2:]
            myBest = PP.findBestHand(myHand, fakeBoard)
            opponentBest = PP.findBestHand(fakeOpponent, fakeBoard)
            if PP.isBetterHand(myBest[0], opponentBest[0]) == 1 : wins+=1
        winPercentage = 1.0*wins/numSimulations
        return winPercentage

    if(numBoardCards == 4):
        wins = 0
        for x in range(0,numSimulations):
            cardSet = set(boardCards)
            for card in myHand: cardSet.add(card)
            newCards = []
            for i in range(0,5):
                card = PP.pickRandomCard(cardSet)
                cardSet.add(card)
                newCards.append(card)
            fakeBoard = boardCards + newCards[0:1]
            fakeOpponent = newCards[1:]
            myBest = PP.findBestHand(myHand, fakeBoard)
            opponentBest = PP.findBestHand(fakeOpponent, fakeBoard)
            if PP.isBetterHand(myBest[0], opponentBest[0]) == 1 : wins+=1
        winPercentage = 1.0*wins/numSimulations
        return winPercentage

    if(numBoardCards == 5):
        wins = 0
        myBest = PP.findBestHand(myHand, boardCards)
        for x in range(0,numSimulations):
            cardSet = set(boardCards)
            for card in myHand: cardSet.add(card)
            fakeOpponent = []
            for i in range(0,4):
                card = PP.pickRandomCard(cardSet)
                cardSet.add(card)
                fakeOpponent.append(card)
            opponentBest = PP.findBestHand(fakeOpponent, boardCards)
            if PP.isBetterHand(myBest[0], opponentBest[0]) == 1 : wins+=1
        winPercentage = 1.0*wins/numSimulations
        return winPercentage
'''
f = open('data.csv', 'w')

for x in range(0, 2000):
	myHand = PP.generateTestHand(4)
	boardCards = PP.generateTestHand(3)
	bestHandRank = PP.findBestHand(myHand, boardCards)
	simulationRank = Simulation.simulate(myHand, boardCards, 3, 100)
	print "BestHandRank: ",bestHandRank[0][0]," SimulationRank: ",simulationRank
	f.write(str(bestHandRank[0][0]*10 + (bestHandRank[0][1]/1.4))+","+str(simulationRank)+"\n")

f.close()

'''
myHand = list()
boardCards = list()
for x in range(0, 1000):
    myHand.append(PP.generateTestHand(4))
    boardCards.append(PP.generateTestHand(3))

startTime = time.time()
print startTime

for x in range(0, 1000):
    bestHandRank = PP.findBestHand(myHand[x], boardCards[x])
    #simulationRank = Simulation.simulate(myHand[x], boardCards[x], 3, 100)
endTime = time.time()

print endTime
print endTime - startTime