Skip to content

Commit

Permalink
Merge branch 'deck-options'
Browse files Browse the repository at this point in the history
  • Loading branch information
gdonald committed Aug 10, 2019
2 parents 200b0a0 + 23bb2f3 commit c92e4fa
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 33 deletions.
22 changes: 15 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,41 @@ Console Blackjack written in Perl6

### Get Perl6

[https://perl6.org/downloads/](https://perl6.org/downloads/)
#### [https://perl6.org/](https://perl6.org/)

Console Blackjack does not work with Perl5 ☹

### Install Blackjack with zef:

```
zef install Console::Blackjack
$ zef update
$ zef install Console::Blackjack
```

### Run

##### Start perl6 and run:
```
$ console-blackjack
```

#### or

```
perl6
$ perl6
perl6> use Console::Blackjack
perl6> Console::Blackjack::Game.new
```

##### Increase your terminal font size for a better view:
 
#### Increase your terminal font size for a better view:

![Blackjack](https://raw.githubusercontent.com/gdonald/Console-Blackjack/master/bj.png)

### Report Bugs

If you find any bugs or have other issues please [report them here](https://github.com/gdonald/Console-Blackjack/issues).
#### If you find any bugs or have other issues please [report them here](https://github.com/gdonald/Console-Blackjack/issues).

### License

Console-Blackjack is released under the [Artistic License 2.0](https://opensource.org/licenses/Artistic-2.0).
#### Console-Blackjack is released under the [Artistic License 2.0](https://opensource.org/licenses/Artistic-2.0).
6 changes: 6 additions & 0 deletions bin/console-blackjack
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!perl6

use v6.d;
use Console::Blackjack;

Console::Blackjack::Game.new;
105 changes: 94 additions & 11 deletions lib/Console/Blackjack.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,8 @@ class Game is export {
$c = self.read-one-char;

given $c {
when 'y' { $br = True;
self.insure-hand; }
when 'n' { $br = True;
self.no-insurance; }
when 'y' { $br = True; self.insure-hand; }
when 'n' { $br = True; self.no-insurance; }
default {
$br = True;
self.clear;
Expand Down Expand Up @@ -278,7 +276,7 @@ class Game is export {
}

method draw-player-bet-options {
say ' (D) Deal Hand (B) Change Bet (Q) Quit';
say ' (D) Deal Hand (B) Change Bet (O) Options (Q) Quit';

my Bool $br = False;
my Str $c;
Expand All @@ -287,12 +285,10 @@ class Game is export {
$c = self.read-one-char;

given $c {
when 'd' { $br = True;
self.deal-new-hand; }
when 'b' { $br = True;
self.get-new-bet; }
when 'q' { $br = True;
self.clear; }
when 'd' { $br = True; self.deal-new-hand; }
when 'b' { $br = True; self.get-new-bet; }
when 'o' { $br = True; self.game-options; }
when 'q' { $br = True; self.clear; }
default {
$br = True;
self.clear;
Expand All @@ -305,6 +301,93 @@ class Game is export {
}
}

method game-options {
self.clear;
self.draw-hands;

say ' (N) Number of Decks (T) Deck Type (B) Back';

my Bool $br = False;
my Str $c;

loop {
$c = self.read-one-char;

given $c {
when 'n' { $br = True; self.get-new-num-decks; }
when 't' { $br = True; self.get-new-deck-type; }
when 'b' {
$br = True;
self.clear;
self.draw-hands;
self.draw-player-bet-options;
}
default {
$br = True;
self.clear;
self.draw-hands;
self.game-options;
}
}

last if $br
}
}

method get-new-deck-type {
self.clear;
self.draw-hands;

say ' (1) Regular (2) Aces (3) Jacks (4) Aces & Jacks (5) Sevens (6) Eights';

my Bool $br = False;
my Str $c;

loop {
$c = self.read-one-char;

given $c {
when '1' { $br = True; self.shoe.new-regular; }
when '2' { $br = True; self.shoe.new-aces; }
when '3' { $br = True; self.shoe.new-jacks; }
when '4' { $br = True; self.shoe.new-aces-jacks; }
when '5' { $br = True; self.shoe.new-sevens; }
when '6' { $br = True; self.shoe.new-eights; }
default {
$br = True;
self.clear;
self.draw-hands;
self.get-new-deck-type;
}
}

if $br {
self.clear;
self.draw-hands;
self.draw-player-bet-options;
last;
}
}
}

method get-new-num-decks {
self.clear;
self.draw-hands;

my Str $opts = ' Number Of Decks: ';
$opts ~= $!num-decks;
$opts ~= "\n";
$opts ~= ' Enter New Number Of Decks: ';

my Int $tmp = prompt $opts;

$tmp = 1 if $tmp < 1;
$tmp = 8 if $tmp > 8;

$!num-decks = $tmp;
self.game-options;
}

method get-new-bet {
self.clear;
self.draw-hands;
Expand Down
2 changes: 1 addition & 1 deletion lib/Console/Blackjack/Card.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Card is export {
}

method is-ten(--> Bool) {
$!value > 9;
$!value > 8;
}

method draw(--> Str) {
Expand Down
12 changes: 4 additions & 8 deletions lib/Console/Blackjack/PlayerHand.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,10 @@ class PlayerHand is Hand is export {
$c = $!game.read-one-char;

given $c {
when 'h' { if self.can-hit() { $br = True;
self.hit; } }
when 's' { if self.can-stand() { $br = True;
self.stand; } }
when 'p' { if self.can-split() { $br = True;
$!game.split-current-hand; } }
when 'd' { if self.can-dbl() { $br = True;
self.dbl; } }
when 'h' { if self.can-hit() { $br = True; self.hit; } }
when 's' { if self.can-stand() { $br = True; self.stand; } }
when 'p' { if self.can-split() { $br = True; $!game.split-current-hand; } }
when 'd' { if self.can-dbl() { $br = True; self.dbl; } }
default {
$br = True;
$!game.clear;
Expand Down
13 changes: 7 additions & 6 deletions lib/Console/Blackjack/Shoe.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Shoe is export {

submethod BUILD(:$!num-decks) {
@!shuffle-specs = (80 => 1), (81 => 2), (82 => 3), (84 => 4), (86 => 5), (89 => 6), (92 => 7), (95 => 8);
self.new-regular;
self.shuffle;
}

Expand All @@ -34,37 +35,37 @@ class Shoe is export {
}

method shuffle {
# self.new-sevens;
# self.new-eights;
# self.new-aces;
# self.new-jacks;
# self.new-aces-jacks;
self.new-regular;
for 0..6 { @!cards = @!cards.pick: *; }
}

method new-aces-jacks {
self.new-irregular([0, 10]);
self.shuffle;
}

method new-jacks {
self.new-irregular([10]);
self.shuffle;
}

method new-aces {
self.new-irregular([0]);
self.shuffle;
}

method new-eights {
self.new-irregular([7]);
self.shuffle;
}

method new-sevens {
self.new-irregular([6]);
self.shuffle;
}

method new-regular {
self.new-irregular([0..12]);
self.shuffle;
}

method new-irregular(@values) {
Expand Down

0 comments on commit c92e4fa

Please sign in to comment.