Go Fish/Mathematica: Difference between revisions
Content added Content deleted
(Added Mathematica) |
(Fixed Mathematica + Description) |
||
Line 1: | Line 1: | ||
{{collection|Go Fish}} |
{{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", |
<lang Mathematica>ranks = {"Ace", "Two", "Three", "Four", "Five", "Six", "Seven", |
||
"Eight", "Nine", "Ten", "Jack", "Queen", "King"}; |
"Eight", "Nine", "Ten", "Jack", "Queen", "King"}; |
||
Line 22: | Line 23: | ||
playerTurn = True; |
playerTurn = True; |
||
While[player != {} || opp != {} || deck != {}, |
While[player != {} || opp != {} || deck != {}, |
||
If[player == {}, drawCards[ |
If[player == {}, drawCards[1, deck, player]]; |
||
If[opp == {}, drawCards[ |
If[opp == {}, drawCards[1, deck, opp]]; |
||
If[playerTurn, |
If[playerTurn, |
||
If[player == {}, |
|||
DialogInput[ |
|||
⚫ | |||
⚫ | |||
" |
"You have no cards and the deck is empty!", |
||
⚫ | |||
⚫ | |||
Module[{choice = |
|||
⚫ | |||
ChoiceDialog[ |
|||
⚫ | |||
"Your opponent has " <> IntegerString[oppBooks] <> |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
ranks[[#]] -> # & /@ Union[First /@ player]]}, |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
playerTurn = False]], |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
DialogNotebook[{TextCell["Go fish! You gained a card.", |
|||
⚫ | |||
FontFamily -> "Arial"], DefaultButton[]}]]; |
|||
⚫ | |||
playerTurn = |
playerTurn = False]]], |
||
If[opp != {}, |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
playerTurn = True]]]]; {player, playerBooks} = |
|||
fixHand[player, playerBooks]; {opp, oppBooks} = |
fixHand[player, playerBooks]; {opp, oppBooks} = |
||
fixHand[opp, oppBooks]]; MessageDialog[ |
fixHand[opp, oppBooks]]; MessageDialog[ |