Advertising (This ad goes away for registered users. You can Login or Register)

Black Friday Sale: Playstation Plus 1 Year subscription is $39.99 (33% off) on Amazon and other retailers, while supplies last.

Need help with a C++ project UPDATED!

Programming on your favorite platform, for your favorite platform? Post here
Locked
TheGuardian
Posts: 22
Joined: Sat Oct 29, 2011 4:25 am

Need help with a C++ project UPDATED!

Post by TheGuardian » Sat Sep 29, 2012 1:00 pm

Hello everyone.

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;
}
I also uploaded the whole thing in mediafire in case someone wants to see what actuall goes on, I uploaded a ZIP and a RAR file, you just need to download one.

[/color]
http://www.mediafire.com/?88cs2zmvfs54bs8 This is the RAR file

http://www.mediafire.com/?nmo83hmkxgh2os2 This is the ZIP file

Thank You!
Advertising

User avatar
StaticCodex
Posts: 34
Joined: Tue Aug 13, 2013 7:54 pm

Re: Need help with a C++ project UPDATED!

Post by StaticCodex » Tue Aug 13, 2013 8:35 pm

When implementing someone else's project even as reference make sure you import the very same external libraries that they have used if anything. Thats one of the biggest mistakes made.

Good luck :D
Advertising
Instagram
2.02 TN-V / 1.67 ARK PS Vita | XBMC 150GB XBOX1 | FreeMCBoot PS2 | 6.60 PSPGO 32GB | R4 16gb NDSL

User avatar
codestation
Big Beholder
Posts: 1660
Joined: Wed Jan 19, 2011 3:45 pm
Location: /dev/negi

Re: Need help with a C++ project UPDATED!

Post by codestation » Tue Aug 13, 2013 9:18 pm

This thread is almost a year old and don't have replies, i don't think is gonna revive any time soon...

Locked....... until OP comes back again, if ever....
Plugin list
Working on: QPSNProxy, QCMA - Open source content manager for the PS Vita
Playing: Error: ENOTIME
Repositories: github, google code
Just feel the code..

Locked

Return to “Programming”