Acme-Mahjong-Rule-CC
view release on metacpan or search on metacpan
lib/Acme/Mahjong/Rule/CC.pm view on Meta::CPAN
package Acme::Mahjong::Rule::CC;
use 5.008008;
use strict;
use warnings;
use Carp;
require Exporter;
our @ISA = qw(Exporter);
# Items to export into callers namespace by default. Note: do not export
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.
# This allows declaration use Acme::Mahjong::Rule::CC ':all';
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
# will save memory.
our %EXPORT_TAGS = (
'all' => [ qw(
mahjong_table
dealer
nondealer
draw
) ],
'tables' =>[qw(
dealer
nondealer
draw
)] );
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
our @EXPORT = qw(
);
our $VERSION = '0.22';
sub mahjong_table{
my $ans = 7;
while($ans!=0 && $ans!=1 && $ans!=2){
print("0.Nondealer , 1.Dealer, or 2.Draw : ");
$ans=<STDIN>;
}
my @subs = (\&nondealer, \&dealer, \&draw);
my @players = (qw/dealer player2 player3 player4/);
$players[0]='winner' if ($ans != 2);
$players[1]='dealer' if ($ans == 0);
my @points;
foreach $a(@players){
print("$a : ");
my $pts =<STDIN>;
push @points,$pts;
}
print "===========================\n";
foreach (&{$subs[$ans]}(@points)){
my $p = shift @players;
print "$p : $_\n";
}
}
sub nondealer{
croak "Wrong number of arguments, needs 4.\n" unless (@_==4);
my @score;
my($w, $deal, $l2 , $l3)=@_;
$score[0]=$w*4;
$score[1]=4*$deal-(2*$w+2*$l2+2*$l3);
$score[2]=3*$l2-($w+2*$deal+$l3);
$score[3]=3*$l3-($w+2*$deal+$l2);
@score;
}
sub dealer{
croak "Wrong number of arguments, needs 4.\n" unless (@_==4);
( run in 2.413 seconds using v1.01-cache-2.11-cpan-302cb4679cc )