A little help would be a big help..

Hi Guys an Gals :wink:

I’ve never posted here so i hope ya’ll don’t think i’m too cheeky just coming by and asking for help :-[

I’m not a beginner to php but i’m not advanced either… and during the course of writing the following script it is throwing out undesirable results and i’m not sure how to fix it without breaking it (if that makes any sense)

I have made a game of pontoon/21 and it works like this:
you click to play, then click either twist or stick… blah blah blah…
however, when either you bust or stick, my hand kicks in which i have automated (well trying)
my hand is drawn and will continually draw another card until one of the following parameters are met:
i exceed 21: bust
i draw 5 cards: max allowed
i get 21 (or anything between 18>21)

You can see a copy of the script in action here :http://www.redscouse.com/cards/index.php
Note: the game uses sessions, and to aid with debugging i have printed the sessions at the bottom of the screen…
all works well until i draw my second card.
if you look at the sessions it seems to draw the second card and add the value but not show the card?
so it often says i’ve bust and it shows 15 (for example)…
and i it really has got me stumped because i’m not sure how to make it right without crashing the rest of the script? :frowning:

session are laid out as follows:
‘my_CardL’
‘my_CardR’
‘my_Card1’
‘my_Card2’
‘my_Card3’
these represent my cards.
If you change the prefix to ‘yr_’ the similar sessions are available for ‘your cards’
‘my_tValue’ holds the value of the first two cards when the game begins and the new card value is added to it as we play. (same is true for ‘yr_tValue’)

the session RsGo is simply called to let the script know the game has started…

I hope you understood all that ;D here’s the segments of code i believe are causing the problem…

[sup]
/*
this class will create my hand (player 2 = automated)
*/
class MyHand extends NewCard
{
public function deal($x=2)
{
$startingHand = $this->hand($x);
$_SESSION[‘my_RsGo’] = true;
$_SESSION[‘my_CardL’] = $startingHand[0][0]; // card one
$_SESSION[‘my_CardR’] = $startingHand[0][1]; // card two
$_SESSION[‘my_Value’] = $startingHand[1]; // hand value
$_SESSION[‘my_tValue’] = $_SESSION[‘my_Value’]; // total value
$this->bustOrPlay($_SESSION[‘my_tValue’]);
}

private function bustOrPlay($tl)
{
	if($tl >= 22)
	{
		echo '<p>I have Bust!</p>';
	}
	elseif($tl == 21)
	{
		echo '<p>I have 21!</p>';
	}
	elseif( ($tl > 18) && $tl < 21)
	{
		echo '<p>I\'ll stick..</p>';
	}
	else
	{
		$this->autoTwist();
	}
}

public function autoTwist()
{
	if(isset($_SESSION['my_Twist1']))
	{
		//echo '<p>twist 1 set</p>';
		$_SESSION['my_Twist2'] = true;
	}
	elseif(isset($_SESSION['my_Twist2']))
	{
		//echo '<p>twist 2 set</p>';
		$_SESSION['my_Twist3'] = true;
	}
	else
	{
		//echo '<p>no twist set</p>';
		$_SESSION['my_Twist1'] = true;
	}
	$this->autoCards();
}

public function autoCards()
{
	if(isset($_SESSION['my_RsGo']))
	{
		if(isset($_SESSION['myTwist3']))
		{
			$myCard = new NewCard;
			$myCard = $this->addCard();
			$_SESSION['my_Card3']  = $myCard['nCard'];        // card one
			$_SESSION['my_Value3'] = $myCard['nVal'];         // card value
			$_SESSION['my_tValue'] += $_SESSION['my_Value3']; // total value
			$this->bustOrPlay($_SESSION['my_tValue']);
		}
		elseif(isset($_SESSION['myTwist2']))
		{
			$myCard = new NewCard;
			$myCard = $this->addCard();
			$_SESSION['my_Card2']  = $myCard['nCard'];        // card one
			$_SESSION['my_Value2'] = $myCard['nVal'];         // card value
			$_SESSION['my_tValue'] += $_SESSION['my_Value2']; // total value
			$this->bustOrPlay($_SESSION['my_tValue']);
		}
		elseif(isset($_SESSION['my_Twist1']))
		{
			$myCard = new NewCard;
			$myCard = $this->addCard();
			$_SESSION['my_Card1']  = $myCard['nCard'];        // card one
			$_SESSION['my_Value1'] = $myCard['nVal'];         // card value
			$_SESSION['my_tValue'] += $_SESSION['my_Value1']; // total value
			$this->bustOrPlay($_SESSION['my_tValue']);
		}
		else
		{
			$this->bustOrPlay($_SESSION['my_tValue']);
		}
	}
	else
	{
		//$this->deal();
	}
}

}
[/sup]

[sub]
/*
Cards shown here
*/

/* Your cards */
print(’

’);
echo $_SESSION[‘yr_CardL’];
echo $_SESSION[‘yr_CardR’];
echo $_SESSION[‘yr_Card1’];
echo $_SESSION[‘yr_Card2’];
echo $_SESSION[‘yr_Card3’];
echo ‘

You have: ’ . $_SESSION[‘yr_tValue’] . ‘

’;
print(’’);

/* my cards */
if(isset($_SESSION[‘my_RsGo’]))
{
echo “<hr align=“left” width=“25%” />”;
// Player header
print(‘

Player 2 (Me)

’);
print(’

’);
echo $_SESSION[‘my_CardL’];
echo $_SESSION[‘my_CardR’];
echo $_SESSION[‘my_Card1’];
echo $_SESSION[‘my_Card2’];
echo $_SESSION[‘my_Card3’];
echo ‘

I have: ’ . $_SESSION[‘my_tValue’] . ‘

’;
print(’’);
}
[/sub]

As you can see from the code, i call the bustOrPlay function which checks my value then calls autoTwist function, this decides which ‘twist’ we are on and sets the session. then runs autoCards function which draws a new card should it be required…

If you play the game on my site, you will see that if it hits a parameter within 2/3 cards it works fine, just when 4th and 5th card are involved the problem seems to arise.

Thanks in advance for any help offered, i hope i gave enough info for you to understand what i meant :slight_smile:

Red…

hi guys…

I figured out the problem it seems it was a typo!!
[sup] if(isset($_SESSION[‘myTwist3’]))[/sup]
[sup] if(isset($_SESSION[‘myTwist2’]))[/sup]
should of read:
[sup] if(isset($_SESSION[‘my_Twist3’]))[/sup] notice the hyphen!!
[sup] if(isset($_SESSION[‘my_Twist2’]))[/sup] notice the hyphen!!

was as simple as that!!

thanks anyway guys…

i’m moving onwards with the game now :slight_smile:

well guys and gals…

game is finished:
http://www.redscouse.com/cards/index.php
there’s a few things i’d like to add in (like the cards turning over rather than just appearing but i’m not sure how to make that happen without flash and i’m afraid i know next to nothing about flash :’( )

…just thought i’d pop back and update,

see ya’ll soon :smiley:

Red.

Sponsor our Newsletter | Privacy Policy | Terms of Service