in reply to Re: Freecell Dealer
in thread Freecell Dealer
I don't see any reason to get rid of those cool unicode chars. The first output was the original, and for some reason, it doesn't look like it's on top of another character like it does in the terminal, but I definitely saw a problem with legibility on the terminal. The second output is with your new line 17. The ultimate output is with the unicode chars stuffed back into the qw list, and it displays fine for me. Followed by source listing:
$ ./1.fc.pl
Hand 11982
♥A ♠A ♥4 ♣A ♦2 ♠6 ♠T ♠J
♦3 ♥3 ♠Q ♣Q ♠8 ♥7 ♦A ♠K
♦K ♥6 ♠5 ♦4 ♥9 ♥J ♠9 ♣3
♣J ♦5 ♣5 ♣8 ♦9 ♦T ♥K ♣7
♣6 ♣2 ♥T ♥Q ♦6 ♣T ♠4 ♠7
♦J ♦7 ♥8 ♣9 ♥2 ♦Q ♣4 ♥5
♣K ♦8 ♠2 ♠3
$ ./1.fc.pl
Hand 11982
AH AS 4H AC 2D 6S TS JS
3D 3H QS QC 8S 7H AD KS
KD 6H 5S 4D 9H JH 9S 3C
JC 5D 5C 8C 9D TD KH 7C
6C 2C TH QH 6D TC 4S 7S
JD 7D 8H 9C 2H QD 4C 5H
KC 8D 2S 3S
$ ./1.fc.pl
Hand 11982
A♥ A♠ 4♥ A♣ 2♦ 6♠ T♠ J♠
3♦ 3♥ Q♠ Q♣ 8♠ 7♥ A♦ K♠
K♦ 6♥ 5♠ 4♦ 9♥ J♥ 9♠ 3♣
J♣ 5♦ 5♣ 8♣ 9♦ T♦ K♥ 7♣
6♣ 2♣ T♥ Q♥ 6♦ T♣ 4♠ 7♠
J♦ 7♦ 8♥ 9♣ 2♥ Q♦ 4♣ 5♥
K♣ 8♦ 2♠ 3♠
$ cat 1.fc.pl
#!/usr/bin/perl
use strict;
use warnings;
use utf8;
sub deal {
my $s = shift;
my $rnd = sub {
return (($s = ($s * 214013 + 2531011) & 0x7fffffff) >> 16 );
};
my @d;
for my $b (split "", "A23456789TJQK") {
push @d, map("$b$_", qw/♣ ♦ ♥ ♠/); # newest with unicode chars
}
for my $idx (reverse 0 .. $#d) {
my $r = $rnd->() % ($idx + 1);
@d$r, $idx = @d$idx, $r;
}
return reverse @d;
}
my $hand_idx = shift(@ARGV) // 11_982;
my $cards = deal($hand_idx);
my $num_cards_in_height = 8;
my $string = '';
while (@$cards)
{
$string .= join(' ', splice(@$cards, 0, 8)) . "\n";
}
binmode STDOUT, ':encoding(utf-8)';
print "Hand $hand_idx\n";
print $string;
$
I think the bigger criticism at this time is that there doesn't seem to be a stochastic component. Maybe space out the columns a bit, so the eye can track them down....
|
|---|