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.
<langsyntaxhighlight Mathematicalang="mathematica">ranks = {"Ace", "Two", "Three", "Four", "Five", "Six", "Seven",
"Eight", "Nine", "Ten", "Jack", "Queen", "King"};
suits = {"Clubs", "Diamonds", "Hearts", "Spades"};
Line 22 ⟶ 23:
playerTurn = True;
While[player != {} || opp != {} || deck != {},
If[player == {}, drawCards[deck1, playerdeck, 1player]];
If[opp == {}, drawCards[deck1, oppdeck, 1opp]];
If[playerTurn,
ModuleIf[{choiceplayer == {},
ChoiceDialogDialogInput[
DialogNotebook[{TextCell["Go fish! You gained a card.",
"Your opponent has " <> IntegerString[oppBooks] <>
"You books,have andno youcards haveand "the <>deck IntegerString[playerBooks]is <>empty!",
FontFamily -> "Arial"], DefaultButton[]}]];,
" books and these cards: " <>
Module[{choice =
StringRiffle[cardName /@ SortBy[player, #[[1]] + #[[2]]/10 &],
ChoiceDialog[
", "] <> "\nWhich rank will you call?",
ranks[[#]] ->"Your #opponent &has /@" Range<> IntegerString[13oppBooks]]}, <>
"Your opponentbooks, and you hashave " <> IntegerString[oppBooksplayerBooks] <>
If[MemberQ[opp, {choice, _}],
" books and these cards: " <>
player = Join[player, Cases[opp, {choice, _}]];
StringRiffle[cardName /@ SortBy[player, #[[1]] + #[[2]]/10 &],
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, _}]];
playerTurn = False]],
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 = TrueFalse]]]; {player, playerBooks} =
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!"]];</langsyntaxhighlight>
9,485

edits