Anonymous user
Go Fish/Mathematica: Difference between revisions
Fixed Mathematica + Description
(Added Mathematica) |
(Fixed Mathematica + Description) |
||
Line 1:
{{collection|Go Fish}}
The AI simply picks the rank that it has the most of.
<lang Mathematica>ranks = {"Ace", "Two", "Three", "Four", "Five", "Six", "Seven",
"Eight", "Nine", "Ten", "Jack", "Queen", "King"};
Line 22 ⟶ 23:
playerTurn = True;
While[player != {} || opp != {} || deck != {},
If[player == {}, drawCards[
If[opp == {}, drawCards[
If[playerTurn,
"Your opponent has " <> IntegerString[oppBooks] <> ▼
"You
" books and these cards: " <> ▼
Module[{choice =
StringRiffle[cardName /@ SortBy[player, #[[1]] + #[[2]]/10 &], ▼
ChoiceDialog[
", "] <> "\nWhich rank will you call?", ▼
If[MemberQ[opp, {choice, _}], ▼
▲ " books and these cards: " <>
player = Join[player, Cases[opp, {choice, _}]]; ▼
opp = DeleteCases[opp, {choice, _}], drawCards[1, deck, player]; ▼
▲ ", "] <> "\nWhich rank will you call?",
DialogInput[▼
ranks[[#]] -> # & /@ Union[First /@ player]]},
▲ DialogNotebook[{TextCell["Go fish! You gained a card.",
▲ If[MemberQ[opp, {choice, _}],
▲ FontFamily -> "Arial"], DefaultButton[]}]];
▲ player = Join[player, Cases[opp, {choice, _}]];
▲ opp = DeleteCases[opp, {choice, _}], drawCards[1, deck, player];
Module[{choice = Commonest[First /@ opp, 1][[1]]}, ▼
▲ DialogInput[
If[MemberQ[player, {choice, _}], ▼
DialogNotebook[{TextCell["Go fish! You gained a card.",
opp = Join[opp, Cases[player, {choice, _}]]; ▼
FontFamily -> "Arial"], DefaultButton[]}]];
player = DeleteCases[player, {choice, _}], ▼
playerTurn =
If[opp != {},
▲ Module[{choice = Commonest[First /@ opp, 1][[1]]},
▲ If[MemberQ[player, {choice, _}],
▲ opp = Join[opp, Cases[player, {choice, _}]];
▲ player = DeleteCases[player, {choice, _}],
playerTurn = True]]]]; {player, playerBooks} =
fixHand[player, playerBooks]; {opp, oppBooks} =
fixHand[opp, oppBooks]]; MessageDialog[
|