Skip to content

Instantly share code, notes, and snippets.

@kijuky
Created February 23, 2020 09:08
Show Gist options
  • Save kijuky/36b5bfd7338539f98cbc800df3188626 to your computer and use it in GitHub Desktop.
Save kijuky/36b5bfd7338539f98cbc800df3188626 to your computer and use it in GitHub Desktop.
ババ抜き
#
# ババ抜き
#
#
# カードが引かれたかどうかを表す配列。
# 1 なら引かれていない。0 なら引かれている。
my @card = (1, 1, 1, 1, 1, 1);
#
# ババを決定。
srand();
my $baba = int(rand(6));
# print("ババは $baba\n");
#
# メインルーチン。
my $while_loop = 0;
my $draw = -1;
while($while_loop < 6) {
print("残っているカード :");
for ($i = 0; $i < 6; $i++) {
if (@card[$i] == 1) {
print("$i ");
}
}
print("\n");
print("カードを一枚引いてください : ");
$draw = <STDIN>;
print("\n");
if (@card[$draw] == 0) {
print("そのカードは既に引いています\n");
print("別のカードを指定してください\n");
} elsif ($draw == $baba) {
print("残念。そのカードはババでした\n");
last;
} else {
print("…。ババではありませんでした\n");
@card[$draw] = 0;
$while_loop++;
}
print("\n");
}
if ($while_loop == 6) {
print("おめでとうございます。あなたの勝ちです");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment