urbit/base/ape/octo/core.hook

146 lines
9.3 KiB
Plaintext
Raw Normal View History

2015-05-19 07:27:39 +03:00
:: :: ::
:::: /hook/core/acto/ape :: :: dependencies
:: :: ::
2015-05-21 02:54:49 +03:00
/? 310 :: arvo version
/- *sole, *octo :: structures
/+ sole, octo :: libraries
2015-05-19 07:27:39 +03:00
:: :: ::
:::: :: :: structures
!: :: ::
2015-05-08 20:56:30 +03:00
=> |% :: arvo structures
2015-05-21 08:37:14 +03:00
++ axle ,[eye=face bus=(unit ship) gam=game] :: agent state
2015-05-08 20:56:30 +03:00
++ card $% [%diff lime] :: update
[%quit ~] :: cancel
[%peer wire dock path] :: subscribe
2015-05-21 02:54:49 +03:00
[%poke wire dock pear] :: send move
[%pull wire dock ~] :: unsubscribe
2015-05-08 20:56:30 +03:00
== ::
++ face (pair (list ,@c) (map bone sole-share)) :: interface
++ lime $% [%sole-effect sole-effect] :: :sole update
2015-05-12 22:57:58 +03:00
[%octo-game game] :: :octo update
2015-05-08 20:56:30 +03:00
== ::
++ move (pair bone card) :: cause and action
2015-05-21 02:54:49 +03:00
++ pear ,[%octo-action action] :: outgoing move
-- ::
=> |% :: historical state
++ axon $%([%1 axle] [%0 axle-0]) ::
++ axle-0 ,[eye=face gam=game-0] ::
++ game-0 ,[who=? box=board boo=board] ::
2015-05-08 20:56:30 +03:00
-- ::
=> |% :: parsers
++ colm (cook |=(a=@ (sub a '1')) (shim '1' '3')) :: row or column
++ come ;~(plug colm ;~(pfix fas colm)) :: coordinate
2015-05-21 02:54:49 +03:00
++ comb (pick come ;~(pfix sig (punt fed:ag))) :: all command input
2015-05-08 20:56:30 +03:00
++ cope |=(? ?:(+< (stag %| (cold ~ sig)) comb)) :: with wait mode
-- ::
2015-05-21 08:37:14 +03:00
:: :: ::
:::: :: :: server
:: :: ::
2015-05-21 02:54:49 +03:00
|_ [hid=hide moz=(list move) [%1 axle]] :: per server
2015-05-08 20:56:30 +03:00
++ et ::
|_ [from say=sole-share] :: per console client
++ abet +>(q.eye (~(put by q.eye) ost say)) :: continue
++ amok +>(q.eye (~(del by q.eye) ost)) :: discontinue
++ beep (emit %bel ~) :: bad user
++ cusp (cope wait) :: parsing rule
++ delt |= cal=sole-change :: input line change
=^ cul say (remit:sole cal good) ::
?~ cul (park:abet(p.eye buf.say) | ~) ::
abet:beep:(emit det/u.cul) ::
++ emit |= fec=sole-effect ^+ +> :: send effect
+>(moz [[ost %diff %sole-effect fec] moz]) ::
++ emil |= fex=(list sole-effect) :: send effects
?~(fex +> $(fex t.fex, +> (emit i.fex))) ::
++ good |=((list ,@c) -:(rose (tufa +<) cusp)) :: valid input
2015-05-21 02:54:49 +03:00
++ here ~(. go [src gam]) :: game core
2015-05-08 20:56:30 +03:00
++ kick |= point :: move command
2015-05-21 02:54:49 +03:00
=^ dud gam ~(m at:here +<) ::
?. dud abet:beep =+ mus=res:here ::
2015-05-08 20:56:30 +03:00
(park:abet(gam ?^(mus *game gam)) %2 mus) ::
++ line =^ cal say (transmit:sole set/p.eye) :: update command
(emit %det cal) ::
++ make =+ dur=(rust (tufa p.eye) comb) ::
?~ dur abet:beep ::
=. + line(p.eye ~) ::
?-(+<.dur & (kick +>.dur), | (plan +>.dur)) ::
++ mean |=((unit tape) ?~(+< +> (emit txt/+<+))) :: optional message
++ play |= lev=?(%0 %1 %2) :: update by level
?-(lev %0 +>, %1 line, %2 line:show:prom) ::
++ plow |= [lev=?(%0 %1 %2) mus=(unit tape)] :: complete print
abet:(mean:(play lev) mus) ::
2015-05-12 22:57:58 +03:00
++ prom %^ emit %pro %& :- %octo :: update prompt
2015-05-20 02:08:35 +03:00
?: wait "(their turn) " ::
2015-05-08 20:56:30 +03:00
": {~[(icon who.gam)]} to move (row/col): " ::
2015-05-21 02:54:49 +03:00
++ plan |= mut=(unit serf) :: peer command
2015-05-08 20:56:30 +03:00
?~ mut ?~(but abet:beep stop:abet) ::
?^(but abet:beep (link:abet u.mut)) ::
2015-05-21 02:54:49 +03:00
++ rend (turn tab:here |=(tape txt/+<)) :: table print
2015-05-08 20:56:30 +03:00
++ show (emit %mor rend) :: update board
2015-05-21 02:54:49 +03:00
++ sole ~(. cs say) :: console core
2015-05-21 08:37:14 +03:00
++ wait =+(own:here &(?=(^ -) :: waiting turn
2015-05-08 20:56:30 +03:00
++ work |= act=sole-action :: console input
?:(?=(%det -.act) (delt +.act) make) ::
-- ::
++ abet [(flop moz) .(moz ~)] :: resolve core
2015-05-09 04:08:18 +03:00
++ dump |=(mov=move %_(+> moz [mov moz])) :: send move
2015-05-08 20:56:30 +03:00
++ dish |=(cad=card (dump 0 cad)) :: forward move
++ flet |=(from ~(. et +< (~(got by q.eye) ost))) :: in old client
++ fret |=(from ~(. et +< *sole-share)) :: in new client
2015-05-21 02:54:49 +03:00
++ like |=(a=ship |*(* [/octo [a %octo] +<])) :: to friend
++ link |= mot=serf %+ dish(but `[| mot]) %peer :: subscribe to friend
2015-05-20 02:22:25 +03:00
((like p.mot) /octo/net/[?:(q.mot %x %o)]) ::
2015-05-09 04:08:18 +03:00
++ pals %+ turn (pale hid (prix /sole)) |= sink :: per console
2015-05-08 20:56:30 +03:00
[[p=p.+< q=q.+<] r=(~(got by q.eye) p.+<)] ::
++ park |= [lev=?(%0 %1 %2) mus=(unit tape)] :: update all
=. +> ?:(=(%2 lev) push +>) ::
=+ pals ::
|- ^+ +>.^$ ?~ +< +>.^$ ::
$(+< t.+<, +>.^$ (~(plow et i.+<) lev mus)) ::
2015-05-12 22:57:58 +03:00
++ push =+ pey=(pale hid (prix /octo)) |- ^+ +> :: update friends
2015-05-08 20:56:30 +03:00
?~(pey +> $(pey t.pey, +> (sell p.i.pey))) ::
2015-05-12 22:57:58 +03:00
++ sell |=(ost=bone (dump ost %diff %octo-game gam)) :: update friend
2015-05-08 20:56:30 +03:00
++ stop (dish(but ~) pull/((like +>-.but) ~)) :: cancel subscribe
2015-05-21 02:54:49 +03:00
:: :: ::
:::: :: :: handlers
:: :: ::
++ coup-octo :: move acknowledge
|= [then saw=(unit tang)] =< abet ::
?~(saw +> (park %0 `"move failed")) ::
2015-05-12 22:57:58 +03:00
++ diff-octo-game :: friend update
2015-05-08 20:56:30 +03:00
|= [then gam=game] =< abet ::
?. &(?=([~ %& *] but) =(src p.q.u.but)) +> ::
?: =(^gam gam) +> ::
(park(gam gam) %2 ~) ::
++ peer-sole :: console subscribe
2015-05-19 07:27:39 +03:00
|= [from pax=path] =< abet ::
2015-05-08 20:56:30 +03:00
(plow:(fret +<-) %2 ~) ::
++ poke-sole-action :: console input
|= [from act=sole-action] =< abet ::
(work:(flet +<-) act) ::
2015-05-19 07:27:39 +03:00
++ poke-octo-move ::
|= [from wha=point] =< abet ::
2015-05-21 02:54:49 +03:00
=^ dud gam ~(m at:here wha) ::
?> dud =+ mus=res:here ::
2015-05-19 07:27:39 +03:00
(park(gam ?^(mus *game gam)) %2 mus) ::
2015-05-08 20:56:30 +03:00
++ prep |= [from old=(unit ,[(list move) axon])] :: initialize
=< abet ?~ old +> ::
=< (park %2 ~) ::
?- -.+>.old ::
%1 +>(+<+ u.old) ::
2015-05-21 02:55:46 +03:00
%0 %= +>(eye.+< eye.+>.old, gam.+< gam.+>.old)::
2015-05-08 20:56:30 +03:00
== ::
2015-05-12 22:57:58 +03:00
++ pull-octo ::
2015-05-14 04:13:13 +03:00
|= [from *] =< abet ::
2015-05-20 02:37:52 +03:00
(park(but ~) %2 `"dropped") ::
2015-05-08 20:56:30 +03:00
++ pull-sole :: disconnect console
|= [from *] =< abet ::
amok:(flet +<-) ::
2015-05-12 22:57:58 +03:00
++ quit-octo :: unlinked by friend
2015-05-08 20:56:30 +03:00
|=([then ~] abet:(park(but ~) %0 `"removed")) ::
2015-05-12 22:57:58 +03:00
++ reap-octo :: linked to friend
2015-05-08 20:56:30 +03:00
|= [then saw=(unit tang)] =< abet ::
?> ?=([~ %| *] but) ::
?^ saw (park:stop %0 `"fail to {<src>}") ::
2015-05-20 02:37:52 +03:00
(park(p.u.but %&) %0 `"link to {<src>}") ::
2015-05-08 20:56:30 +03:00
--