I am working in a poker project simulator in C++. I am using Visual Studio 2010. So far everything has been ok, but now I am stuck with the evaluator files.
I built the files and everything was ready to go (or I thought so) but I am having problems trying to apply the evaluator I did.
I got some help from someone who had a evaluator scaffold (it is included in the files) but still having trouble trying to implement it n my project.
Would anyone help with this? I am uploading the files and the code I have so far.
The poker scaffold folder is contains sample files that are NOT part of my poker project. I was using them a references, but even with that I got stuck. Also Will you please include an explanation of what I was missing? In other words. I want my game to let me know when someone wins and loses and things like that.
Just make something clear, I am looking for help in another forum as well. I did so I could broaden my chances of finding an answer. I am planning to upload the finished product once I figure out how to solve the problems I have.
Thank You!
I tried to upload the files for direct download, but the forum won't let me, so I created at account in mediafire in order to make them available.
http://www.mediafire.com/?paup07ucsvg9e9p
I apologize I guess I was not clear enough with my request, that is why I am redoing the whole thing.
OK, I am building this poker evaluator program, it is almost finished and compiles and everything, but I got a problem.
Whenever the players get pairs it won't compare the them and will always result in a tie even though someone it isn't a tie. I don't know what I am missing.
The lines in bold are what I believe where the problem is.
Code: Select all
#include <algorithm>
#include "evaluator.h"
Evaluator::Evaluator(void)
{
}
Evaluator::~Evaluator(void)
{
}
SortedEvaluator::SortedEvaluator(void)
{
}
SortedEvaluator::~SortedEvaluator(void)
{
}
inline std::string SortedEvaluator::ToString(std::vector<const Card*> hand)
{
std::sort(hand.begin(), hand.end(), compare);
cout << "\t";
for(vector<const Card*>::const_iterator it = hand.begin(); it != hand.end(); ++it)
{
cout << (*it) -> ToString() << " ";
}
return " ";
}
bool lessThan(const Card* c1, const Card* c2)
{
if(c1 -> GetPip() < c2 -> GetPip())
{
return true;
}
else
{
return false;
}
}
inline int SortedEvaluator::compareHands(std::vector<const Card*> hand1, std::vector<const Card*> hand2)
{
//std::sort(hand1.begin(), hand1.end(), compare);
//std::sort(hand2.begin(), hand2.end(), compare);
/*
//Royal Flush
if((isFlush(hand1) && isStraight(hand1)) && (isFlush(hand2) && isStraight(hand2)))
{
return compKick(hand1, hand2);
}
*/
//Straight Flush
if((isFlush(hand1) && isStraight(hand1)) && (isFlush(hand2) && isStraight(hand2)))
{
return compKick(hand1, hand2);
}
else if((isFlush(hand1) && isStraight(hand1)) && (isFlush(hand2) && isStraight(hand2)) == false )
{
return 1;
}
else if((isFlush(hand1) && isStraight(hand1)) == false && (isFlush(hand2) && isStraight(hand2)))
{
return -1;
}
//Four of a Kind
else if(isQuad(hand1) && isQuad(hand2))
{
return compQuad(hand1, hand2);
}
else if(isQuad(hand1) && isQuad(hand2) == false)
{
return 1;
}
else if(isQuad(hand1) == false && isQuad(hand2))
{
return -1;
}
//Full House
else if(isFullHouse(hand1) && isFullHouse(hand2))
{
return compFHouse(hand1, hand2);
}
else if(isFullHouse(hand1) && isFullHouse(hand2) == false)
{
return 1;
}
else if(isFullHouse(hand1) == false && isFullHouse(hand2))
{
return -1;
}
//Flush
else if(isFlush(hand1) && isFlush(hand2))
{
return compFlush(hand1, hand2);
}
else if(isFlush(hand1) && isFlush(hand2) == false)
{
return 1;
}
else if(isFlush(hand1) == false && isFlush(hand2))
{
return -1;
}
//Straight
else if(isStraight(hand1) && isStraight(hand2))
{
return compStraight(hand1, hand2);
}
else if(isStraight(hand1) && isStraight(hand2) == false)
{
return 1;
}
else if(isStraight(hand1) == false && isStraight(hand2))
{
return -1;
}
//Trips
else if(isTrips(hand1) && isTrips(hand2))
{
return compTrips(hand1, hand2);
}
else if(isTrips(hand1) && isTrips(hand2) == false)
{
return 1;
}
else if(isTrips(hand1) == false && isTrips(hand2))
{
return -1;
}
//Two Pairs
else if(isTPair(hand1) && isTPair(hand2))
{
return compTPair(hand1, hand2);
}
else if(isTPair(hand1) && isTPair(hand2) == false)
{
return 1;
}
else if(isTPair(hand1) == false && isTPair(hand2))
{
return -1;
}
//Pair
else if(isPair(hand1) && isPair(hand2))
{
return compPair(hand1, hand2);
}
else if(isPair(hand1) && isPair(hand2) == false)
{
return 1;
}
else if(isPair(hand1) == false && isPair(hand2))
{
return -1;
}
else
{
compKick(hand1, hand2);
}
return 0;
}
bool SortedEvaluator::isFlush(const vector<const Card*>& hand)
{
return (hand[0] -> GetSuit() == hand[1] -> GetSuit() && hand[1] -> GetSuit() == hand[2] -> GetSuit() &&
hand[2] -> GetSuit() == hand[3] -> GetSuit() && hand[3] -> GetSuit() == hand[4] -> GetSuit());
}
bool SortedEvaluator::isStraight(const vector<const Card*>& hand)
{
if(hand[0] -> GetPip() == Card::_2 && hand[1] -> GetPip() == Card::_3 &&
hand[2] -> GetPip() == Card::_4 && hand[3] -> GetPip() == Card::_5 &&
hand[4] -> GetPip() == Card::_A)
{
return true;
}
if(hand[0] -> GetSuit() + 1 == hand[1] -> GetSuit() && hand[1] -> GetSuit() + 1 == hand[2] -> GetSuit() &&
hand[2] -> GetSuit() + 1 == hand[3] -> GetSuit() && hand[3] -> GetSuit() + 1 == hand[4] -> GetSuit())
{
return true;
}
return false;
}
bool SortedEvaluator::isQuad(const vector<const Card*>& hand)
{
return(hand[0] -> GetSuit() == hand[3] -> GetSuit() || hand[1] -> GetSuit() == hand[4] -> GetSuit());
}
bool SortedEvaluator::isFullHouse(const vector<const Card*>& hand)
{
return((hand[0] -> GetPip() == hand[1] -> GetSuit() && hand[2] -> GetPip() == hand[4] -> GetPip()) ||
(hand[0] -> GetPip() == hand[2] -> GetSuit() && hand[3] -> GetPip() == hand[4] -> GetPip()));
}
bool SortedEvaluator::isTrips(const vector<const Card*>& hand)
{
return(hand[0] -> GetPip() == hand[2] -> GetPip() ||
hand[1] -> GetPip() == hand[3] -> GetPip() ||
hand[2] -> GetPip() == hand[4] -> GetPip());
}
[b]bool SortedEvaluator::isTPair(const vector<const Card*>& hand) //This is the code that does not want to work
{
cout << "isTPair is being called (This is what is not working";
return((hand[0] -> GetPip() == hand[1] -> GetPip() && hand[2] -> GetPip() == hand[3] -> GetPip()) ||
(hand[1] -> GetPip() == hand[2] -> GetPip() && hand[3] -> GetPip() == hand[4] -> GetPip()) ||
(hand[0] -> GetPip() == hand[1] -> GetPip() && hand[3] -> GetPip() == hand[4] -> GetPip()));
}
bool SortedEvaluator::isPair(const vector<const Card*>& hand) //This is the code that does not want to work
{
cout << "isPair is being called (This is what is not working)";
return((hand[0] -> GetPip() == hand[1] -> GetPip()) || (hand[2] -> GetPip() == hand[3] -> GetPip()) ||
(hand[1] -> GetPip() == hand[2] -> GetPip()) || (hand[3] -> GetPip() == hand[4] -> GetPip()));
}
[/b]
//Hand Comparisons
int SortedEvaluator::compHand(const vector<const Card*>& h1, const vector<const Card*>& h2)
{
bool s1 = isStraight(h1);
bool s2 = isStraight(h2);
bool f1 = isFlush(h1);
bool f2 = isFlush(h2);
bool sf1 = s1 && f1;
bool sf2 = s2 && f2;
if(sf1 == true && sf2 == true)
{
return compStraight(h1,h2);
}
return true;
}
int SortedEvaluator::compKick(const vector<const Card*>& h1, const vector<const Card*>& h2)
{
int ret = 0;
for(int i = h1.size() - 1; i >= 0; --i)
{
if(h1[i] -> GetPip() < h2[i] -> GetPip())
{
ret = -1;
return ret;
}
if(h1[i] -> GetPip() > h2[i] -> GetPip())
{
ret = 1;
return ret;
}
}
return ret;
}
int SortedEvaluator::compFlush(const vector<const Card*>& h1, const vector<const Card*>& h2)
{
return compKick(h1, h2);
}
int SortedEvaluator::compStraight(const vector<const Card*>& h1, const vector<const Card*>& h2)
{
int ret = 0;
bool wheel1 = h1[0] -> GetPip() == Card::_2 && h1[4] -> GetPip() == Card::_A;
bool wheel2 = h2[0] -> GetPip() == Card::_2 && h2[4] -> GetPip() == Card::_A;
if(wheel1 == true && wheel2 == true)
{
ret = 0;
return ret;
}
if(wheel1 == true)
{
ret = -1;
return ret;
}
if(wheel2 == true)
{
ret = 1;
return ret;
}
ret = compKick(h1, h2);
return ret;
}
int SortedEvaluator::compQuad(const vector<const Card*>& h1, const vector<const Card*>& h2)
{
int ret = 0;
if(h1[3] -> GetPip() > h2[3] -> GetPip())
{
ret = 1;
return ret;
}
if(h1[3] -> GetPip() < h2[3] -> GetPip())
{
ret = -1;
return ret;
}
if(h1[4] -> GetPip() > h2[4] -> GetPip())
{
ret = 1;
return ret;
}
if(h1[4] -> GetPip() > h2[4] -> GetPip())
{
ret = -1;
return ret;
}
ret = compKick(h1, h2);
return ret;
}
int SortedEvaluator::compFHouse(const vector<const Card*>& h1, const vector<const Card*>& h2)
{
return compQuad(h1, h2);
}
int SortedEvaluator::compTrips(const vector<const Card*>& h1, const vector<const Card*>& h2)
{
int ret = 0;
if(h1[2] -> GetPip() > h2[2] -> GetPip())
{
ret = 1;
return ret;
}
if(h1[2] -> GetPip() < h2[2] -> GetPip())
{
ret = -1;
return ret;
}
ret = compKick(h1, h2);
return ret;
}
int SortedEvaluator::compTPair(const vector<const Card*>& h1, const vector<const Card*>& h2)
{
int ret = 0;
if(h1[1] -> GetPip() > h2[1] -> GetPip())
{
ret = 1;
return ret;
}
if(h1[1] -> GetPip() < h2[1] -> GetPip())
{
ret = -1;
return ret;
}
if(h1[3] -> GetPip() > h2[3] -> GetPip())
{
ret = 1;
return ret;
}
if(h1[3] -> GetPip() < h2[3] -> GetPip())
{
ret = -1;
return ret;
}
ret = compKick(h1, h2);
return ret;
}
int SortedEvaluator::compPair(const vector<const Card*>& h1, const vector<const Card*>& h2)
{
int PipVal1 = h1[0] -> GetPip();
int PipVal2 = h2[0] -> GetPip();
int ret = 0;
for(int i = h1.size() - 1; i >= 0; --i)
{
if(PipVal1 == h1[i] -> GetPip())
{
break;
}
else
{
PipVal1 = h1[i] -> GetPip();
}
}
for(int i = h2.size() - 1; i >= 0; --i)
{
if(PipVal2 == h2[i] -> GetPip())
{
break;
}
else
{
PipVal1 = h2[i] -> GetPip();
}
}
if(PipVal1 > PipVal2)
{
ret = 1;
return ret;
}
if(PipVal1 < PipVal2)
{
ret = -1;
return ret;
}
ret = compKick(h1, h2);
return ret;
}
[/color]
http://www.mediafire.com/?88cs2zmvfs54bs8 This is the RAR file
http://www.mediafire.com/?nmo83hmkxgh2os2 This is the ZIP file
Thank You!
Advertising