Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > C/C++ программирование > Общие вопросы C/C++
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 15.09.2010, 15:04   #1
yugik
Пользователь
 
Аватар для yugik
 
Регистрация: 04.01.2010
Сообщений: 23
По умолчанию Некорректно работает проверка в покере

Очень жду советов и найденных ошибок, заранее спасибо.

Код:
#include <iostream>
#include <string>
#include <time.h>
#include <vector>

using namespace std;

class Card
{
	int rank;
	int suit;
public:
	Card ()
	{
		rank = 0;
		suit = 0;
	}
	Card (int r, int s)
	{
		rank = r;
		suit = s;
	}
	int getRank ()
	{
		return rank;
	}
	int getSuit ()
	{
		return suit;
	}
	void viewCard ()
	{
		if (rank<=8)
			cout << rank+2;
		else 
			switch (rank)
		{
			case 9:
				cout << "J";
				break;
			case 10:
				cout << "Q";
				break;
			case 11:
				cout << "K";
				break;
			case 12:
				cout << "A";
				break;

		}
		cout << (char)suit;
	}

};

class Deck
{
	vector <Card> cards;

public:
	Deck ()
	{
		for (int i=0;i<13;i++)
		{
			for (int j=3;j<7;j++)
			{
				cards.push_back(Card(i,j));
			}
		}
	}
	Card getCard ()
	{
		srand (time(NULL));
		int pos = rand()%cards.size();
		Card temp = cards.at(pos);
		cards.erase(cards.begin()+pos);
		return temp;
	}
};

class Hand: public Deck, public Card
{
	
public:
	Card on_hand[5];
	Hand ()
	{
		for (int i=0;i<5;i++)
		{
			on_hand[i] = getCard();
		}
	}
	void changeCards ()
	{
		int n, c, temp;
		int change [5] = {-1,-1,-1,-1,-1};
		cout << "\nPlease specify count of cards, which you wants to change: ";
		cin>>n;
		if (n==5)
		{
			for (int i=0;i<5;i++)
			{
				on_hand[i] = getCard();
			}
		}
		else 
		{
			cout << "\nPlease choose cards which should be changed (1-5)\n:";
		for (int i=0;i<n;i++)
		{
			temp = -1;
			cin>>temp;
			change [i] = temp-1;
		}

		srand(time(NULL));

			for (int i=0; i<n; i++)
			{
				on_hand[change[i]] = getCard();
			}
		}
	}
	void DisplayHand ()
	{
		for (int i=0;i<5;i++)
		{
			on_hand[i].viewCard();
			cout << "\t";
		}
		cout << "\n\n";
		for (int i=0;i<5;i++)
		{
			cout << i+1 << "\t";
		}
	}

};
class Prize: public Hand
{
	int Money;
	int bet;
	int *Combinations;
	/*
	0 - Pair
	1 - 2 Pairs
	2 - Three f a Kind
	3 - Street
	4 - Flash
	5 - Full House
	6 - Four of a Kind
	7 - Street Flash
	*/

public:
	Prize ()
	{
		bet = 0;
		Money = 300;
		Combinations = new int [8];
		for (int i=0;i<8;i++)
		{
			Combinations[i]=0;
		}
	}
	void checkCombinations ()
	{
		bool check [5] = {0,0,0,0,0};
		int a;
		//Check on Pairs, 2Pairs, 3ofKind, 4ofKind
		for (int i=0;i<5;i++)
		{
			for (int j=i+1;j<5;j++)
			{
				a=0;
				if (check[i]!=1)
				{
					if (on_hand[i].getRank()==on_hand[j].getRank())
					{
						a++;
						check[j]=1;
					}
				}
				else
					break;
			}
			check[i]=1;
			switch (a)
			{
			case 1:
				Combinations[0]++;
				break;
			case 2:
				Combinations[2]+=1;
				break;
			case 3:
				Combinations[6]+=1;
				break;
			default:
				break;
			}
		}
		//Check on Flash
		if (on_hand[0].getSuit()==on_hand[1].getSuit()==on_hand[2].getSuit()==on_hand[3].getSuit()==on_hand[4].getSuit())
			Combinations[4]+=1;

		//Check on Full House
		if (Combinations[0]>0 && Combinations[2]>0)
		{
			Combinations[5]+=1;
		}
		//Check 2pairs
		if (Combinations[0]>1)
			Combinations[1]+=1;


	}
	void setBet (int x)
	{
		bet = x;
	}
	int getMoney ()
	{
		return Money;
	}
	void getPrize ()
	{
		if (Combinations[7]==1)
		{
			cout << "\nYou have a Street Flash. You won "<< 100+bet <<"$\n";
			Money+=(100+bet);

		} 
		else if (Combinations[6]==1)
		{
			cout << "\nYou have Four of a kind. You won "<<60+bet<<"$\n";
			Money+=(60+bet);

		} 
		if (Combinations[5]==1)
		{
			cout << "\nYou have a Full House. You won "<<50+bet<<"$\n";
			Money+=(50+bet);

		} 
		else if (Combinations[4]==1)
		{
			cout << "\nYou have a Flash. You won "<<25+bet<<"$\n";
			Money+=(25+bet);

		}
		if (Combinations[3]==1)
		{
			cout << "\nYou have a Street. You won "<<20+bet<<"$\n";
			Money+=(20+bet);

		} 
		else if (Combinations[2]==1)
		{
			cout << "\nYou have Three of a Kind. You won "<<15+bet<<"$\n";
			Money+=(15+bet);

		}
		if (Combinations[1]==1)
		{
			cout << "\nYou have Two Pairs. You won "<<10+bet<<"$\n";
			Money+=(10+bet);

		} 
		else if (Combinations[0]==1)
		{
			cout << "\nYou have a one Pair. You won "<<5+bet<<"$\n";
			Money+=(5+bet);

		}
		else
		{
			cout << "\nThere is no one matched combinations.\n";
			Money-=bet;
		}
	}

};

void main ()
{
	Card one;
	Deck myDeck;
	Hand player;
	Prize myPrize;
	int bet;

	cout << "\nYour money: " << myPrize.getMoney();
	cout << "\n\nEnter your bet: ";
	cin >> bet;
	myPrize.setBet(bet);
	cout << endl;
	player.DisplayHand();
	player.changeCards ();
	cout << endl;
	player.DisplayHand();
	myPrize.checkCombinations();
	myPrize.getPrize();
	cout << "\nYour money: " << myPrize.getMoney();
	system("pause");

}
yugik вне форума Ответить с цитированием
Старый 15.09.2010, 15:06   #2
yugik
Пользователь
 
Аватар для yugik
 
Регистрация: 04.01.2010
Сообщений: 23
По умолчанию

Вообщем описание проблемы:

1. При проверке дебаггером вижу что проверка комбинаций происходит
не в тех картах которые уже поменяны, а в картах первого расклада;
2. проверка комбинаций не всегда определяет правильные комбинации.
yugik вне форума Ответить с цитированием
Старый 17.09.2010, 14:06   #3
yugik
Пользователь
 
Аватар для yugik
 
Регистрация: 04.01.2010
Сообщений: 23
По умолчанию

Народ плиз! помогите найти причину почему запускаемая проверка, просматривает карты которые были выложены первыми а не те которые уже были заменены
yugik вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Некорректно работает программа Dimakat Помощь студентам 2 07.09.2010 14:54
некорректно работает WaitForMultipleObjects bazilior Общие вопросы C/C++ 2 17.04.2010 20:15
Некорректно работает запрос Arkuz БД в Delphi 9 20.08.2009 07:04
Некорректно работает запрос zulu80 БД в Delphi 10 16.02.2009 13:35
IdHTTP1 некорректно работает nike-p Работа с сетью в Delphi 9 23.07.2008 23:13