Go Fish/Aime: Difference between revisions

m
Fixed syntax highlighting.
(Created page with "{{collection|Go Fish}} The AI will randomly ask a rank known to be in the human's hand (a card in the AI's hand that the human has asked for before and the AI hasn't asked for...")
 
m (Fixed syntax highlighting.)
 
(2 intermediate revisions by one other user not shown)
Line 1:
{{collection|Go Fish}}
The AI will randomly ask a rank known to be in the human's hand (a card in the AI's hand that the human has asked for before and the AI hasn't asked for before). If there are no known ranks, the AI will ask for the lowest rank it has (the strategy has the virtue of not giving away the player's hand).
<langsyntaxhighlight lang="aime">void
shuffle(list l)
{
integer ic, je;
 
for (, c in b_draft("SHDC")) {
i = 4;
character for (, e in b_draft("A23456789TJQK", j))); {
while (i) {
l.p_text(drand(~l), data().append(e).append(c));
i -= 1;
i = 4; }
j = 13;
while (j) {
j -= 1;
l_p_text(l, drand(l_length(l)),
insert(cut("SHDC", i, 1), 0,
character("A23456789TJQK", j)));
}
}
}
Line 29 ⟶ 23:
i = 0;
s = pick;
while (r_greaterrsk_greater(p, s, s)) {
if (character(s, [0)] == character(pick, [0)]) {
i += 1;
} else {
break;
j -= 1; }
}
}
 
if (i == 4) {
books += 1;
while (i) {
i -= 1;
r_greater rsk_greater(p, pick, s);
r_delete(p, p.delete(s);
i -= 1; }
}
 
if (!r_size(~p)) {
deal(deck, name, p, books);
}
}
}
}
Line 54 ⟶ 48:
deal(list deck, text name, record p, integer &p_books)
{
if (l_length(~deck)) {
text s;
 
lf_e_text(s, deck);
o_text o_form("dealing /w8/", name);
if (!compare(name, "player")) {
o_space(8 - length(name));
o_text o_(": ", s);
o_text(name);
}
if (!compare(name, "player")) {
o_space o_text(1"\n");
o_text( p[s)] = 0;
check_book(deck, name, p, delete(s, 1), p_books);
}
o_text("\n");
r_p_integer(p, s, 0);
check_book(deck, name, p, delete(s, 1), p_books);
}
}
Line 76 ⟶ 67:
text s;
 
o_texto_form("~: /w2/ books", player, books);
o_text(": ");
o_winteger(2, books);
o_text(" books,");
 
if (!compare(player, "P")) {
while for (is in p) {
r_first(p, s);
o_(" ", s);
do {
o_space(1); }
o_text(s);
} while (r_greater(p, s, s));
} else {
call_n(~p, o_text, " **");
integer i;
 
i = r_size(p);
while (i) {
i -= 1;
o_text(" **");
}
}
 
Line 105 ⟶ 85:
integer h;
 
h = r_greaterrsk_greater(p, s, d);
if (h) {
if (character(s, [0)] != character(d, [0)]) {
h = 0;
} else {
r_delete(p, p.delete(d);
}
}
}
 
Line 125 ⟶ 105:
 
while (1) {
o_text("your pick?\n");
f_line(input, pick);
if (length~pick != 1 || place("A23456789TJQK", pick[0]) !== -1) {
o_text("bad books,choice\n");
|| index("A23456789TJQK", character(pick, 0)) == -1) {
} else {
o_text("bad choice\n");
r_greater rsk_greater(u, pick, s);
} else {
if (s[0] != pick[0]) {
r_greater(u, pick, s);
if (character(s, 0) != character o_("you don't have any ", pick, 0)"s\n") {;
} else {
o_plan("you don't have any ", pick, "s\n");
} else { break;
}
break;
}
}
}
 
r_a_integer(asked, .a_integer(pick, 0);
 
t = draw(e, pick, s);
if (!t) {
o_plan o_("computer has no ", pick, "s\n");
deal(deck, "player", u, u_books);
} else {
do {
r_p_integer(u, u[s,] = 0);
} while (draw(e, pick, s));
if (!r_size(~e)) {
deal(deck, "computer", e, c_books);
}
}
 
check_book(deck, "player", u, pick, u_books);
}
 
Line 166 ⟶ 145:
text s;
 
iffor (r_first(asked, s) in asked) {
text t;
do {
text t;
 
if (r_greaterrsk_greater(c, s, t)) {
if (character(s, [0)] == character(t, [0)]) {
l.append(s);
lb_p_text(l, s);
}
}
}
} while (r_greater(asked, s, s));
}
 
if (l_length(~l)) {
pick = l_q_text(l, [drand(l_length(~l) - 1))];
}
}
Line 190 ⟶ 167:
text pick, s;
 
r_first(e, .first(pick);
# seemingly dumb choice: ask the first book
pick = delete(pick, 1);
# refine choice to something the user has asked for
mull(e, asked, pick);
o_plano_("computer asks ", pick, "s\n");
t = !draw(u, pick, s);
r_resign(asked, .resign(pick);
if (t) {
deal(deck, "computer", e, c_books);
} else {
do {
r_p_integer(e, e[s,] = 0);
} while (draw(u, pick, s));
if (!r_size(~u)) {
deal(deck, "player", u, u_books);
}
}
 
check_book(deck, "computer", e, pick, c_books);
}
 
Line 226 ⟶ 203:
u_turn = 1;
 
f_affix(in, "/dev/.stdin");
 
shuffle(deck).shuffle;
 
i = 9;
while (i) {
deal(deck, "player", u, u_books);
deal(deck, "computer", e, c_books);
i -= 1;
}
 
while (c_books + u_books != 13) {
show("C", c_books, e);
show("P", u_books, u);
if (u_turn) {
u_turn = user(deck, e, c_books, u, u_books, ai, in);
} else {
u_turn = fnet(deck, e, c_books, u, u_books, ai);
}
}
}
 
o_plano_("Computer has ", c_books, " books.\n");
o_plano_("Player has ", u_books, " books.\n");
o_plan(__holdo_(c_books < u_books, ? "Player", : "Computer"), " wins.\n");
 
return 0;
}
</syntaxhighlight>
</lang>
9,476

edits