raku

My Raku Scripts Collection
git clone https://fab.ddns.me.uk/stagit/raku
Log | Files | Refs | README

commit 6a1e84ca8a55c63f8fb752708b3e9a590d97c173
parent 4bb1b82f8264a43d551f37e6f57f5359e8c44e2a
Author: masayoshi <masayoshi@example.com>
Date:   Mon, 23 Feb 2026 19:54:49 +0900

Upload

Diffstat:
Aoichokabu.raku | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 74 insertions(+), 0 deletions(-)

diff --git a/oichokabu.raku b/oichokabu.raku @@ -0,0 +1,73 @@ +#!/usr/bin/env raku + +# 1. 札の準備(1..10を4セット、確実に平らにする) +my @base = 1..10; +my @deck = (@base, @base, @base, @base).flat.pick(*); + +# 2. 点数計算(下一桁を返す) +sub get-kabustats(@hand) { + return @hand.sum % 10; +} +# 3. 特殊役(しっぴん・くっぴん)の判定 +sub check-special(@hand) { + my @sorted = @hand.sort; + # (1, 4) という「数字の組み合わせ」を厳密にチェックします + if @sorted[0] == 1 && @sorted[1] == 4 { return "Shippin" } + if @sorted[0] == 1 && @sorted[1] == 9 { return "Kuppin" } + return False; +} + +# --- ゲーム開始 --- +say "🇬🇧 Welcome to Oicho-Kabu on OpenBSD!"; +say "-" x 40; + +# 親と子に2枚ずつ配る +my @player = @deck.pop, @deck.pop; +my @dealer = @deck.pop, @deck.pop; + +# 親の特殊役チェック +if my $special = check-special(@dealer) { + say "Dealer's hand: {@dealer.join('-')}"; + say "🇬🇧 Oh no! Dealer got $special! You lose instantly."; + exit; +} + +# 4. プレイヤーの番 +loop { + my $score = get-kabustats(@player); + say "Your hand: {@player.join('-')} (Score: $score)"; + + # 3枚目を引くか選択(おいちょかぶは最大3枚) + if @player.elems < 3 { + my $choice = prompt "Do you want to draw a 3rd card? (y/n): "; + if $choice.lc.starts-with('y') { + @player.push: @deck.pop; + next; + } + } + last; +} + +# 5. 親(CPU)の番 +# 一般的に親は4以下なら引き、5以上なら勝負(スタンド)します +while get-kabustats(@dealer) < 5 && @dealer.elems < 3 { + @dealer.push: @deck.pop; +} + +# 6. 最終判定 +my $p-final = get-kabustats(@player); +my $d-final = get-kabustats(@dealer); + +say "-" x 40; +say "Your final: {@player.join('-')} (Score: $p-final)"; +say "Dealer final: {@dealer.join('-')} (Score: $d-final)"; + +if $p-final > $d-final { + say "🇬🇧 Brilliant! You win!"; +} +elsif $p-final < $d-final { + say "🇬🇧 Dreadful! Dealer wins."; +} +else { + say "🇬🇧 Honours even! (It's a push)."; +} +\ No newline at end of file