Rock-paper-scissors: Difference between revisions

Line 185:
computer_play(record plays, record beats)
{
integer a, c, total;
text s;
 
total = r_q_integer(plays, ["rock")] + r_q_integer(plays, ["paper")] + plays["scissors"];
+ r_q_integer(plays, "scissors");
a = drand(total - 1);
r_firstfor (playss, sc in plays); {
do if (a < c) {
if (a < r_q_integer(plays, s)) {
break;
}
a -= plays[s]c;
}
} while (rsk_greater(plays, s, s));
 
return r_q_text(beats, [s)];
}
 
Line 210 ⟶ 208:
text s;
 
computer = human = 0;
human = 0;
 
f_affix(f, "/dev/.stdin");
 
r_put(beats, ["rock",] = "paper");
r_put(beats, ["paper",] = "scissors");
r_put(beats, ["scissors",] = "rock");
 
r_put(plays, ["rock",] = 1);
r_put(plays, ["paper",] = 1);
r_put(plays, ["scissors",] = 1);
 
while (1) {
o_text("Your choice [rock/paper/scissors]:\n");
if (f_line(f, .line(s) == -1) {
break;
}
 
if (!r_key(plays, .key(s)) {
o_text("Invalid choice, try again\n");
} else {
Line 238 ⟶ 235:
o_form("Human: ~, Computer: ~\n", s, c);
 
if (!compare(s, == c)) {
o_text("Draw\n");
} elif (!compare(c, == beats[s])) {
computer += 1;
o_text("Computer wins\n");
Line 248 ⟶ 245:
}
 
r_up(plays, .up(s);
 
o_form("Score: Human: ~, Computer: ~\n", human, computer);
Anonymous user