Sign in to follow this  
  • entries
    72
  • comments
    38
  • views
    22183

im writing in here

Sign in to follow this  

195 views

I have alot of the little bugs worked out of the game logic code. Some new stuff was added for a computer player AI with Basic Stratigy plus a High-Low count. I was going to add input so the player wasnt always a computer player, but I didnt really try too hard. I was busy cleaning up the rules logic, it was some times paying out on player busts. I still have a some-how-broken bool that is getting a true reading, when the last function set it to false. But oh well, here is a run that went better than any have with the current build.
Quote:
-- Begin Round: 10593 --
Count is: 5
Player bets $20
Dealer: D7 D10 Points: 17
Player: CJ D2 Points: 12
Player takes a card: S2 Points: 14
Player takes a card: H8 Points: 22
Player busted.
Player lost $20
Player Funds: $0
Game ended.
High Funds: $1687.5 (Round 6124)


Most runs only go 400-900 rounds, and have a high funds of about the same range.

I tried to upload it, but I get this:
Quote:
aspSmartUpload error '800a0006'

Overflow

/community/forums/mod/fileman/fileman.asp, line 298


I try again, and I get a different error. So Ill just post the new stuff in source.

#ifndef _TABLE_H_
#define _TABLE_H_

#include "Player.h"
#include "Deck.h"
#include "Hand.h"
#include "Card.h"

typedef struct TableRulesT
{
float minBet;
float maxBet;
unsigned int numDecks;
float Saturation;
} TableRules;

class Table
{
public:
Deck* TheCards;
Deck* TheBoot;

Player * Dealer;
vector Players;

TableRules Rules;

Table()
{
Dealer = new Player();
Dealer->name = "Dealer";
TheCards = new Deck();// (52);
TheBoot = new Deck();
SetRules();
TheCards->Generate(Rules.numDecks);
}
~Table()
{
delete Dealer;
delete TheCards;
delete TheBoot;
vector::iterator b = Players.begin();
vector::iterator e = Players.end();
for(;b != e; ++b)
delete *b;
}
Player* AddPlayer()
{
Player * p;
Players.push_back((p = new Player()));
string pnum;
string pname = "Player";
p->name = pname ;
p->funds = 300;
return p;
}
Player* GetPlayer(unsigned int i)
{
return Players[i - 1];
}
TableRules SetRules(float minBet = 5, float maxBet = 200,
unsigned int numDecks = 4, float sat = 0.35f)
{
Rules.minBet = minBet;
Rules.maxBet = maxBet;
Rules.numDecks = numDecks;
Rules.Saturation = sat;
return Rules;
}

bool BetsDown();
void Deal();
void ShowTable();
void DealerTurn();
void PlayersTurn();
void ScoreRound();
void CollectHands();
void AIBasicPlayer(Player * player);
};

#endif

#include "Table.h"

bool Table::BetsDown()
{
bool AllDown = true;
Player * p;
vector::iterator b = Players.begin();
vector::iterator e = Players.end();
for(;b != e; ++b)
{
p = *b;
if(p->active)
{
p->busted = false;
if(p->computer)
{
// setup computers Count based bet
if(TheCards->Count > 1)
{
cout << "Count is: " << TheCards->Count << endl;
float bet = (Rules.minBet * TheCards->Count);
if(bet > p->funds)
bet = p->funds;
p->bet = bet;
}
else
{
p->bet = Rules.minBet;
}
}
else
{
// input bet
}
if( (p->bet >= Rules.minBet) && (p->bet <= Rules.maxBet) )
{
if(p->bet > p->funds)
p->bet = p->funds;
if(!p->bet)
{
AllDown = false;
}
else
{
p->funds -= p->bet;
}
}
else
{
p->bet = 0;
p->active = false;
}
cout << p->name.c_str() << " bets $" << p->bet << endl;
}
}
return AllDown;
}

void Table::Deal()
{
if(TheCards->Cards.size() <= 12)
{
*TheCards = *TheCards + *TheBoot;
TheBoot->numCards = 0;
TheBoot->Cards.clear();
TheCards->Shuffle();
cout << "** Shuffled Deck **" << endl;
}
Dealer->hand.Hit(TheCards->Draw());
for(unsigned int i = 0;i < Players.size(); ++i)
{
Players->hand.Hit(TheCards->Draw());
Players->active = true;
Players->busted = false;
}
Dealer->hand.Hit(TheCards->Draw());
for(unsigned int i = 0;i < Players.size(); ++i)
{
Players->hand.Hit(TheCards->Draw());
}
}

void Table::ShowTable()
{
cout << "Dealer: ";
Dealer->RevealCards();
for(unsigned int i=0;i < Players.size(); ++i)
{
cout << Players->name.c_str() << ": ";
Players->RevealCards();
}
}

void Table::DealerTurn()
{
while(Dealer->Points() < 17)
{
cout << "Dealer takes a card.." << endl;
Dealer->hand.Hit(TheCards->Draw());
Dealer->RevealCards();
}

}

void Table::PlayersTurn()
{
vector::iterator b = Players.begin();
vector::iterator e = Players.end();
Player * p;
while(b != e)
{
p = *b;
if(p->active)
{
if(p->computer)
{
AIBasicPlayer(p);
}
else
{
// input player
}
if(p->busted == true)
{
*TheBoot = *TheBoot + p->hand.GiveBack();
}
}
++b;
}
}

void Table::ScoreRound()
{
unsigned int pnts;
unsigned int dpnt = Dealer->Points();
float income;
vector::iterator b = Players.begin();
vector::iterator e = Players.end();
Player * p;
for(;b != e; ++b)
{
p = *b;
pnts = p->Points();
if( p->busted )
{
cout << p->name.c_str() << " lost $" << p->bet << endl;
}
else if( (pnts < 22 && pnts > dpnt) || dpnt > 21)
{
cout << p->name.c_str() << " wins $";
if(pnts == 21 && p->hand.Cards.size() == 2)
{
income = p->bet + (p->bet * 1.5f);
p->funds += income;
}
else
{
income = (p->bet * 2);
p->funds += income;
}
cout << (income - p->bet) << endl;
}
else if( pnts == dpnt )
{
cout << p->name.c_str() << " pushed." << endl;
income = p->bet;
p->funds += income;

}
else
{
cout << p->name.c_str() << " lost $" << p->bet << endl;
}
p->bet = 0;
cout << p->name.c_str() << " Funds: $" << p->funds << endl;

}
}

void Table::CollectHands()
{
Deck in;
in = in + Dealer->hand.GiveBack();
vector::iterator b = Players.begin();
vector::iterator e = Players.end();
Player * p;
for(;b != e; ++b)
{
p = *b;
if(p->active && (p->busted == false) )
in = in + p->hand.GiveBack();
}
*TheBoot = *TheBoot + in;
}

void Table::AIBasicPlayer(Player * player)
{
Card dupc = Dealer->hand.Cards[1];
bool thinking = true;
player->busted = false;
while(thinking)
{
/*
if(TheCards->Count > 4)
{
thinking = false;
cout << player->name.c_str() << " stands." << endl;
break;
}
*/

if(player->Points() == 21 && player->hand.numCards == 2)
{
cout << player->name.c_str() << " blackjack!" << endl;
thinking = false;
break;
}
switch(dupc.Point())
{
case 0x03:
case 0x04:
case 0x05:
case 0x06:
{
if(player->Points() <= 11)
{
Card C = player->hand.Hit(TheCards->Draw());
cout << player->name.c_str() << " takes a card: ";
DisplaySV(C.value); cout << "Points: " << player->Points() << endl;
// hit card
}
else
{
thinking = false;
cout << player->name.c_str() << " stands." << endl;
// stand
}
break;
}
case 0x07:
case 0x08:
case 0x09:
case 0x0A:
//case 0x0B:
//case 0x0C:
//case 0x0D:
case 0x01:
{
if( player->Points() <= 16 )
{
Card C = player->hand.Hit(TheCards->Draw());
cout << player->name.c_str() << " takes a card: ";
DisplaySV(C.value); cout << "Points: " << player->Points() << endl;
// hit
}
else
{
thinking = false;
cout << player->name.c_str() << " stands." << endl;
// stand
}
break;
}
default:
thinking = false;
cout << player->name.c_str() << " stands." << endl;
// stand
break;
}
//****
// check for busted
//****
if(player->Points() > 21)
{
cout << player->name.c_str() << " busted." << endl;
thinking = false;
player->busted = true;
}
}
}


It's in progress still in places.
Sign in to follow this  


1 Comment


Recommended Comments

Try using FTP instead of the file manager. Since you are GDNet+ you can just FTP to members.gamedev.net with your gamedev.net username and password.

---
Michael Tanczos

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now