Go Fish/J: Difference between revisions

m
Fixed syntax highlighting.
(Created page with "{{collection|Go Fish}} The essential portion of the program is a gerund of verbs action0`action1`...`actionn, one for each state of the game. Agenda @. drives ...")
 
m (Fixed syntax highlighting.)
 
(3 intermediate revisions by one other user not shown)
Line 8:
next state. Thus verb go's guts are
 
<langsyntaxhighlight Jlang="j"> setup
g`e`r`u`n`d @. extract_state ^: non_terminal ^: _ choose_1st_player
cleanup
</syntaxhighlight>
</lang>
 
Instruct <syntaxhighlight lang J="j">go fish</langsyntaxhighlight> to play.
 
 
The code uses the cards as recommended and fullfills fulfills the AI requirement
requirement in a minimal fashion. If J hands over its last card to the opponent J
the opponent J chooses to not draw a card.
 
 
Line 25:
unused verbs of the gerund.
 
<syntaxhighlight lang="cpp">
J CAPITAL, opponent lower.
 
Line 31 ⟶ 32:
end: no more fish in pond.
 
<lang C++>
book -> fill ->
end
Line 63:
0be supply 0bf
0bf dumb 0b4
</syntaxhighlight>
</lang>
 
Here is fish.ijs which includes some test code to demonstrate and of course test some of its verbs.
 
<syntaxhighlight lang="j">
<lang J>
load'~user/playingcards.ijs'
coinsert'rcpc'
Line 260:
pc=:newDeck''
shuffle__pc''
'HAND hand'=: 2 dealCards__pc 9 NB. deal two hands of fivenine cards
'BOOKS books' =: 0 NB. initialize the score
book `fill `end `draw `BOOK `ask `RESPOND`FISH `SUPPLY `FILL `ASK `respond`Fish `DRAW `supply `dumb @. ] ^: (0b2&~:) ^: _ (0b4*?2){0b0 0b4
 
BOOK book''
if. fail =. books 13&~:@+ BOOKS do.
Line 275 ⟶ 274:
write books score BOOKS
)
</syntaxhighlight>
</lang>
 
Sample
<syntaxhighlight lang="j">
<lang J>
 
go load'~user/fish.ijs'
Line 300 ⟶ 299:
You hold A♦ 4♣ 5♥ 5♠ 6♠ 7♣ 10♣ J♣ J♥ K♦
Your request please? a23456789tjqk
</syntaxhighlight>
</lang>
9,477

edits