PHP Blackjack

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

zebrax
Forum Newbie
Posts: 16
Joined: Sat Sep 14, 2002 11:39 pm

PHP Blackjack

Post by zebrax »

I was looking around the net and noticed there where hardly any PHP blackjack projects.
I thought it would be a perfect opportunity to learn object orientation. So the results are http://blackjack.ordze.com OO PHP blackjack
This is my first time playing around with classes. Have a look and let me know what you think. I still have to add a few things (split and double down functions) and clean up the code a bit. But I think it is working order.

zebrax
Last edited by zebrax on Sun Sep 15, 2002 12:06 am, edited 1 time in total.
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

Link doesn't work.
Image Image
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

The title works but the actual page doesn't show...

I say it's not good :wink:
dusty
Forum Contributor
Posts: 122
Joined: Sun Apr 28, 2002 9:52 pm
Location: Portsmouth, VA

Post by dusty »

it just counted the dealers had of 3,j,a,8,6 as 18.
also isnt it only blackjack when you get 21 in the first 2 cards (ace and a ten card)? it said blackjack when i took a hit and got 21.
zebrax
Forum Newbie
Posts: 16
Joined: Sat Sep 14, 2002 11:39 pm

Post by zebrax »

dusty wrote:it just counted the dealers had of 3,j,a,8,6 as 18.
also isnt it only blackjack when you get 21 in the first 2 cards (ace and a ten card)? it said blackjack when i took a hit and got 21.
Thanks I figured out why the dealer had 3,j,a,8,6 as 18
if happens when there is an ace. Here was my old code.

Code: Select all

function HandValue()
// determine the numeric value of the player's hand
{
	$ace=0;
	$total = 0;
	for ($i = 0; $i < $this->numCards; $i++)
	&#123;
	      $v=$this->hand&#1111;$i]->Getval();
		
		if ($v <= 10)
			$total += $v;
		else if ($v <= 13)  	// it's a face card
			$total += 10;
		else &#123; 					// it's an ace
			$total += 11;
			$ace=1;&#125;
	if($ace==1)&#123;
	      if($total>21)&#123;$total-=10;&#125;
	      &#125;
	&#125;
	
		return $total;
&#125;
when an ace shows up it kept taking off 10. Here us the updated code

Code: Select all

function HandValue()
// determine the numeric value of the player's hand
&#123;
	$total = 0;
	for ($i = 0; $i < $this->numCards; $i++)
	&#123;
		$ace=0;
		$v=$this->hand&#1111;$i]->Getval();
		if ($v <= 10)
			$total += $v;
		else if ($v <= 13)  	// it's a face card
			$total += 10;
		else &#123; 					// it's an ace
			$total += 11;
			$ace=1;&#125;
	if($ace==1)
	    &#123;if($total>21)&#123;$total-=10;&#125;
	     &#125;
	&#125;
	
	
	return $total;
&#125;
I didn't have $ace=0; inside the loop.
Thanks
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

That's really nice, kind of slow, not sure if thats the coding or the server. I might make some card games, looks fun.
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

I like it! It's reall cool :D
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Post by JPlush76 »

leaving my fortune up to a php random number generator? that sounds scary :)
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

It's actually very random, and the distrobution of cards is even (trust me, we have done tests).

So as far as randomness is concerned, PHP does it very well. :D
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Post by JPlush76 »

I actually played once on the old blackjack.com's flash site I won $80 and they actually paid it right onto my credit card.

I like the real cards and all the hotties running around the casino :)
Coco
Forum Contributor
Posts: 339
Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:

Post by Coco »

dealer wins on a draw...
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

the dealer is supposed to win
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Post by JPlush76 »

dealer isn't supposed to win if its even, its a push
Coco
Forum Contributor
Posts: 339
Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:

Post by Coco »

jason i know :) thats what i was trying to say...
(and i just got an avatar from you with REALLY hairy arms 8O )

but clearly from what jim says it depends on the rule set and the tightness of the casino :)
Post Reply