Пример #1
0
int main(int argc, const char * argv[])
{

    using namespace cs52;
    using namespace std;
    
    Dealer d;
    d.shuffleDeck();
    
    Hand h;  // by default, just two cards in a hand
	//Hand h = Hand(3); // three cards in a hand
    h.buildHand();
    cout << "INITIAL HAND" << endl;
    cout << h << endl;
    h.replaceWorstCard();
    cout << "BETTER HAND" << endl;
    cout << h << endl;
    

    FiveCardHand five;  // by default, five cards in a hand
    five.buildHand();
    cout << "INITIAL HAND" << endl;
    cout << five << endl;
	
    five.replaceWorstCard();
    cout << "BETTER HAND" << endl;
    cout << five << endl;
 
    
    return 0;
}
Пример #2
0
void Blackjack::initialDeal(Player & player, Dealer & dealer)
{
    player.hit(deck.deal()); // Deal two cards to the player(s)
    player.hit(deck.deal());
    dealer.hit(deck.deal()); // Deal two cards to the dealer
    dealer.hit(deck.deal());
    dealer.hideCard();       // Hide dealer's card
}
Пример #3
0
void dealerPlay(Deck* deck, BlackJackHand* hand) {
    Dealer* dealer = new Dealer();
    dealer->dealHand(hand);
    while (dealer->hitOrStay()) {
        hand->printCardsValue();
        std::cout << "hit" << std::endl;
        dealer->add(deck->draw());
    }
    hand->printCardsValue();
    hand->printStatus();
}
Пример #4
0
int main()
{
  srand(time(NULL));
  Dealer dealer;

  dealer.shuffle();


  dealer.show_list();
  dealer.is_empty();

  return 0;
}
Пример #5
0
//  'main' test driver for card and dealer classes
int main() {


    // empty deck
    deque<Card> cards;

    // add the hearts...
    for(short v=1; v<=13; v++) {
        Card c(v,Card::HEARTS);
        cards.push_back(c);
    }
    // add the spades...
    for(short v=1; v<=13; v++) {
        Card c(v,Card::SPADES);
        cards.push_back(c);
    }
    // add the diamonds...
    for(short v=1; v<=13; v++) {
        Card c(v,Card::DIAMONDS);
        cards.push_back(c);
    }
    // add the clubs...
    for(short v=1; v<=13; v++) {
        Card c(v,Card::CLUBS);
        cards.push_back(c);
    }

    // create the dealer, give him the cards
    Dealer* dealer = new Dealer(cards);

    for(int i=0; i < 53 ; i ++) {
        try {

            printf("shuffling...\n");
            dealer->shuffle();

            printf("current deck state: (%d cards left)\n",dealer->deck_size());
            dealer->show_cards();

            Card c = dealer->deal_one_card();
            printf("Dealt card: %d,%c \n",c.getValue(),Card::enum2string(c.getSuit()));
        }
        catch (char const* e) {
            printf("%s\n\n", e);
        }
    }

    delete dealer;
    return 0;
}
Пример #6
0
int main()
{
	cout
		<< "\t\t____    ____       _        ____   ____    ____  \n"
		<< "\t\t`MM'    `MM'      dM.      6MMMMb\  `MM'    `MM'  \n"
		<< "\t\t MM      MM      ,MMb     6M'    `  MM      MM   \n"
		<< "\t\t MM      MM      d'YM.    MM        MM      MM   \n"
		<< "\t\t MM      MM     ,P `Mb    YM.       MM      MM   \n"
		<< "\t\t MMMMMMMMMM     d'  YM.    YMMMMb   MMMMMMMMMM   \n"
		<< "\t\t MM      MM    ,P   `Mb        `Mb  MM      MM   \n"
		<< "\t\t MM      MM    d'    YM.        MM  MM      MM   \n"
		<< "\t\t MM      MM   ,MMMMMMMMb        MM  MM      MM   \n"
		<< "\t\t MM      MM   d'      YM. L    ,M9  MM      MM   \n"
		<< "\t\t_MM_    _MM__dM_     _dMM_MYMMMM9  _MM_    _MM_  \n";
                                                                                                                      

	HashEvaluator* H = new HashEvaluator;

	cout << "\n\n";
	int HandNum = 1;
	while (true)
	{
		Dealer* D = new TexasDealer(5);
		vector<const Card*> Cards;

		for (unsigned i = 0; i < 5; ++i)
		{
			const Card*  c = D->deal();
			Cards.push_back(c);
		}

		cout << "Hand " << HandNum << ":";

		for (vector<const Card*>::iterator c_it = Cards.begin(); c_it != Cards.end(); ++c_it)
		{
			cout << " " << (*c_it)->ToString() ;
		}

		unsigned hash = H->GetHash(Cards);
		unsigned value = H->GetValue(hash);
		string  name = H->GetName(hash,Cards);

		cout << "--> Hash#: " << hash << setw(5) << right << " Rank:" << value << " Name: " << name << endl;
		cin.get();
		++HandNum;
		delete D;
	}
	
	return 0;
}
Пример #7
0
void Blackjack::startTurn(Player & player, Dealer & dealer)
{
	deck.initialize();
    deck.shuffle(); // Shuffle the deck
    initialDeal(player, dealer);
    cout << dealer.getName() << " is showing:" << endl;
    dealer.printCurrentHand();
    cout << player.getName() << " is showing:" << endl;
    player.printCurrentHand();
    wager = player.getWager();
    player.turn(deck);  // Give player a turn
    dealer.revealCard(); // Reveal dealer's card
    findWinner(player, dealer);
    cout << "\tTotal " << player.getName() << " wins: " << playerWins;
    cout << " ($" << player.getMoney() << ")" << endl;
    cout << "\tTotal " << dealer.getName() << " wins: " << dealerWins << endl;
    cout << "\nPress enter to continue." << endl;
    player.resetHand();
    dealer.resetHand();
    cin.get();   // Pause console output until next user input
}
Пример #8
0
void Blackjack::findWinner(Player & player, Dealer & dealer)
{
    if(player.isBust()) // Check to see if player busted during their turn
    {
        cout << "\n***** [ " << player.getName() << " busted ] *****" << endl;
        player.printCurrentHand();
    }
    else
    {
        dealer.turn(deck, player.getCurrentScore());
    }
    cout << dealer.getName() << " has:" << endl;
    dealer.printCurrentHand();
    /* Find winner and print the results on stdout, remember house wins on a tie */
    if((player.getCurrentScore() > dealer.getCurrentScore() || dealer.isBust()) && !player.isBust())
    {
        cout << player.getName() << " has won the game!" << endl;
        player.giveMoney(wager);
        playerWins++;
    }
    else
    {
        cout << dealer.getName() << " has won the game!" << endl;
        player.takeMoney(wager);
        dealerWins++;
    }
}
int main(){
	AdvancedPlayer player;
	Dealer *dealer = new Dealer();

	Deck deck;

	Hand myHand(25);
	myHand.addCard("AC");
	myHand.addCard("AH");

	player.addHand(myHand);

	Hand dealerHand(-1);
	dealerHand.addCard("6S"); //upcard
	dealerHand.addCard("TC"); 
	dealer->addHand(dealerHand);

	//player.play(deck, upCard); // not quite right 6S in deck ACAS
	player.evaluateHands(dealer, deck);


	return 0;
}
Пример #10
0
/*
void Dealer::placeOrder(Order * order)
{
	Dealer *pDealer = getDealerFor(order->getContract());
	if(pDealer) pDealer->placeOrder(order);
}

void Dealer::cancelOrder(Order * order)
{
	Dealer *pDealer = getDealerFor(order->getContract());
	if(pDealer) pDealer->cancelOrder(order);
}
*/
void Dealer::cancel(Order * order)
{
	TRACE_LOG("Cancel Order: %s ", order->getId().c_str());
	Dealer * d = Dealer::getDealerFor(order->getContract());
	d->cancelOrder(order);
}
Пример #11
0
	int Count(Dealer& d){return d.Count();}
Пример #12
0
void BlackJack::GameLoop(){
		
	    GameStates::instance().SetState(GAME_MENU);
		currentGlobalState = GameStates::instance().GetState();

		//Fill the Deck of Cards and Shuffle it
		DeckOfCards::instance().FillDeckOfCards();
	    DeckOfCards::instance().ShuffleDeckOfCards();	

	    Dealer dealer;
		Player player;
		player.SetState(new Idle());
		dealer.SetState(new Idle());

		//Background 
		SDL_Surface *gameTable = SDL_LoadBMP("BlackjackTable.bmp");
		SDL_Surface *screenSurface = SDL_GetWindowSurface( screen );
		SDL_Rect source; 

		source.x = 0;
		source.y = 0;
		source.w = gameTable->w;
		source.h = gameTable->h;

		SDL_Rect destination;

		destination.x = 0;
		destination.y = 0;
		destination.w  = 1280;
		destination.h = 720;

		SDL_Rect textLocation;
		textLocation.x = 300;
		textLocation.y = 720/2;
		textLocation.w = 0;
		textLocation.h = 0;

		
	//Temporary storage for totals
			int dTempTotal = 0;
			int pTempTotal = 0;


	while(gameRunning){

			/*First, Check if Game State has changed since last iteration,
			  if yes, bypass new Game State to Actor game states handler,
			  if not - do not pass it to object, but check if state is not MENU,
			  otherwise - handle input for games menu.*/
			int newGlobalState = GameStates::instance().GetState();
			
			if (newGlobalState != currentGlobalState){
				currentGlobalState = newGlobalState;

				switch (currentGlobalState){

				case GAME_MENU:

					player.SetState(new Idle());
					dealer.SetState(new Idle());
					break;
				
				case GAME_START:

					dealer.SetState(new DealTheCardsState());
					player.SetState(new DealTheCardsState());
					
					break;
				case PLAYERS_TURN:

					dealer.SetState(new Idle());
					player.SetState(new TakeHit(player.GetID()));

					break;
				case DEALERS_TURN:

					player.SetState(new Idle());
					dealer.SetState(new TakeHit(dealer.GetID()));
					break;
				
				/*In COUNTING_CARDS game state, game checks Actors for their totals on hands
				and choses the correct state for each Actor*/
				case COUNTING_CARDS:

					//Update totals 
					 dTempTotal = dealer.GetTotalOnHand();
					 pTempTotal = player.GetTotalOnHand();

					 //DEBUG OUTPUT
					 std::cout<<"Dealer's total: "<<dTempTotal<<std::endl;
					 std::cout<<"Player's total: "<<pTempTotal<<std::endl;

					 //Compare totals of Player and Dealer (if they are not busted)
					 if (player.IsBusted() == false && dealer.IsBusted() == false){
						 //Check their totals
						 if(pTempTotal == dTempTotal){
							 player.SetState(new Push(player.GetID()));
							 dealer.SetState(new Push(dealer.GetID()));
						 }
						 else if (pTempTotal > dTempTotal){
							 player.SetState(new Winner(player.GetID()));
							 dealer.SetState(new Busted(dealer.GetID()));
							
						 }
						 else if (pTempTotal < dTempTotal){
							 player.SetState(new Busted(player.GetID()));
							 dealer.SetState(new Winner(dealer.GetID()));
							
						 }
					 }
					 //Check the case of Player is busted and Dealer is not
					 else if (player.IsBusted() == true && dealer.IsBusted() == false){
						     player.SetState(new Busted(player.GetID()));
							 dealer.SetState(new Winner(dealer.GetID()));
							
					 }
					 //The same but checking if Dealer is busted
					 else if (player.IsBusted() == false && dealer.IsBusted() == true){
						     player.SetState(new Winner(player.GetID()));
							 dealer.SetState(new Busted(dealer.GetID()));
							
					 }
					 //The case then both are busted (has more than 21) 
					 else if (player.IsBusted() == true && dealer.IsBusted() == true){
						     player.SetState(new Busted(player.GetID()));
							 dealer.SetState(new Busted(dealer.GetID()));
							
					 }


					//reset Actor flags
					 player.SetBusted(false);
					 dealer.SetBusted(false);

					//Reset temp totals and return game to the MENU state
					pTempTotal = 0;
					dTempTotal = 0;


					while(inputSubSystem.ReturnKeyCode() != SDLK_ESCAPE){
						//Wait until ESCAPE is pressed
					}

					//Refill deck of cards and reshuffle it
					DeckOfCards::instance().ResetDeck();
					DeckOfCards::instance().ShuffleDeckOfCards();	

					GameStates::instance().SetState(GAME_MENU);
					break;
				}

			}
			else if (newGlobalState == currentGlobalState){

				if (currentGlobalState == GAME_MENU){
						HandleInput();
				}

			}
			//Print out if game is in undefined state 
			else{std::cout<<"UNDEF SWITCH GAME STATE"<<std::endl;}

		

			//Call Update method for each Actor - see Actor.h for Update() desciption
			dealer.Update();
			player.Update();


			SDL_BlitSurface(gameTable, &source, screenSurface, &destination);

			graphicsLayoutSystem.DrawDealerCards(dealer.ReturnCards(), screenSurface);
			graphicsLayoutSystem.DrawPlayerCards(player.ReturnCards(), screenSurface);



		if (GameStates::instance().GetState() == GAME_MENU) {
				SDL_BlitSurface(textSurface[MENU_NOTIFICATION], &source, screenSurface, &textLocation);		
		}
		if (GameStates::instance().GetState() == PLAYERS_TURN){
				SDL_BlitSurface(textSurface[PLAYERS_TURN_NOTIFICATION], &source, screenSurface, &textLocation);
		}
		if (GameStates::instance().GetState() == DEALERS_TURN){
				SDL_BlitSurface(textSurface[DEALERS_TURN_NOTIFICATION], &source, screenSurface, &textLocation);
		}
			

		if (GameStates::instance().GetState() == COUNTING_CARDS){
			SDL_BlitSurface(textSurface[PUSH_NOTIF], &source, screenSurface, &textLocation);
		}
			



			if (GameStates::instance().GetState() == GAME_START || GameStates::instance().GetState() == PLAYERS_TURN){
				graphicsLayoutSystem.DrawBackCard(screenSurface);
			}

			  //Update the surface
			SDL_UpdateWindowSurface( screen );

		}

		 //Deallocate surface
		SDL_FreeSurface( screenSurface );
		screenSurface = NULL;

		SDL_FreeSurface(gameTable );
		gameTable = NULL;

    //Destroy window
		SDL_DestroyWindow( screen );
		screen = NULL;

    //Quit SDL subsystems
    SDL_Quit();
}