Skip to content

Instantly share code, notes, and snippets.

@RichardTMiles
Created June 28, 2018 04:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RichardTMiles/c2301108724f3ecf67cd38a5e4f02b39 to your computer and use it in GitHub Desktop.
Save RichardTMiles/c2301108724f3ecf67cd38a5e4f02b39 to your computer and use it in GitHub Desktop.
<?php
/**
* Created by IntelliJ IDEA.
* User: Richard Miles
* Date: 6/27/2018
* Time: 4:05 PM
*
* A 6-Deck blackjack card counting game
*
* 2-6 is +1
* 10-A is -1
*
* Whats the count?
*/
$deck = [
'a', '2', '3', '4', '5', '6',
'7', '8', '9', '10', 'j', 'q', 'k',
];
$deck = array_merge($deck,$deck,$deck,$deck);
$deck = array_merge($deck,$deck,$deck,$deck,$deck,$deck);
$count = 0;
STDIN;
do {
$key = random_int(0,count($deck) - 1);
print $key . ') '. $deck[$key] . PHP_EOL;
switch ($deck[$key]){
case '2':
case '3':
case '4':
case '5':
case '6':
$count++;
break;
case '10':
case 'j':
case 'q':
case 'k':
case 'a':
$count--;
break;
default:
break;
}
$guess = readline('Whats the count?');
if ((string)$guess === (string) $count){
print 'You\'re a god! The count is ' . $count . PHP_EOL;
} else {
print 'You suck! The count is ' . $count . PHP_EOL;
}
unset($deck[$key]);
}while (count($deck));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment