Anonymous user
Playing cards: Difference between revisions
Updated second D entry
(add scala) |
(Updated second D entry) |
||
Line 883:
5 of Spades</pre>
===More Refined Version===
<lang d>import std.stdio, std.random, std.algorithm, std.string, std.
struct Card {
static immutable suits =
static immutable pips = "Ace 2 3 4 5 6 7 8 9 10 J Q K".split
enum nPack = suits.length * pips.length;
static bool rankAceTop = true;
string toString() pure const {
return format("%3s of %-7s", pips[pip], suits[suit])
.rightJustify(15);
}
Line 926:
if (initShuffle)
cards.randomShuffle
}
Line 956:
Deck showDeck() {
return this;
}
Deck shuffle() {
cards.randomShuffle
return this;
}
Deck sortDeck() {
cards.sort!q{a > b}
return this;
}
override string toString() pure const {
return format("%(%(%s%)\n%)",
}
}
Line 982:
auto host = new Deck(false, 1);
writeln("Host");
host.shuffle
while (host.length > 0)
Line 991:
foreach (immutable i, g; guests) {
writefln("Player #%d", i + 1);
g.sortDeck
}
}</lang>
|