Anonymous user
Rock-paper-scissors: Difference between revisions
Updated D code
(D version) |
(Updated D code) |
||
Line 432:
=={{header|D}}==
{{trans|Python}}
<lang d>import std.stdio, std.
enum string[] order = ["rock", "paper", "scissors"];
int[string] choiceFrequency; // mutable
immutable(string[string]) whatBeats;
nothrow pure static this() {
whatBeats = ["paper": "scissors",
"scissors": "rock",
Line 444:
}
string checkWinner(in string a, in string b) pure nothrow {
if (b == whatBeats[a])
return b;
Line 464:
while (true) {
write("Your choice: ");
if (humanChoice == "")
break;
if (humanChoice !
writeln("Wrong input: ", humanChoice);
continue;
}
write("Computer picked ", compChoice, ", ");
// Don't register the player choice until after
// the computer has made its choice.
choiceFrequency[humanChoice]++;
if (winner
writeln(winner, " wins!");
}
}</lang>
|