Go Fish/Mathematica: Difference between revisions
m
Fixed syntax highlighting.
(Added Mathematica) |
m (Fixed syntax highlighting.) |
||
(One intermediate revision by one other user not shown) | |||
Line 1:
{{collection|Go Fish}}
The AI simply picks the rank that it has the most of.
<
"Eight", "Nine", "Ten", "Jack", "Queen", "King"};
suits = {"Clubs", "Diamonds", "Hearts", "Spades"};
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[
Line 51 ⟶ 58:
playerBooks > oppBooks,
"You win with " <> IntegerString[playerBooks] <> " books!", True,
"Tie!"]];</
|