urbit/base/ape/octo/core.hook

203 lines
12 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
:: :: ::
2015-05-23 20:03:02 +03:00
:::: :: :: server
2015-05-19 07:27:39 +03:00
!: :: ::
2015-05-08 20:56:30 +03:00
=> |% :: arvo structures
2015-05-23 20:03:02 +03:00
++ axle ,[eye=face rem=(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
== ::
2015-05-26 05:15:08 +03:00
++ face (map bone sole-share) :: console state
2015-05-08 20:56:30 +03:00
++ lime $% [%sole-effect sole-effect] :: :sole update
2015-05-26 05:15:08 +03:00
[%octo-update (each game tape)] :: :octo update
2015-05-08 20:56:30 +03:00
== ::
++ move (pair bone card) :: cause and action
2015-05-23 20:03:02 +03:00
++ pear ,[%octo-move point] :: outgoing move
2015-05-21 02:54:49 +03:00
-- ::
=> |% :: 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-23 20:03:02 +03:00
|_ [hid=hide moz=(list move) %1 axle] :: per agent
2015-05-26 05:15:08 +03:00
++ ce :: per client
|_ from ::
:: :: ::
:::: :: :: boilerplate
:: :: ::
++ abet [(flop moz) +>(moz ~)] :: resolve core
2015-05-26 07:00:34 +03:00
++ dish |=(cad=card %_(+> moz [[ost cad] moz])) :: request
++ echo |= [pre=path fun=$+(_. _+>)] :: broadcast
2015-05-26 05:15:08 +03:00
=+ [all=(pale hid (prix pre)) los=+>+<] ::
|- ^+ +>.^$ ?~ all +>.^$(+< los) ::
=> .(ost p.i.all, src p.q.i.all) ::
$(all t.all, +>.^$ (fun +>.^$)) ::
2015-05-26 07:00:34 +03:00
++ emit |=(lime (dish %diff +<)) :: publish
2015-05-26 05:15:08 +03:00
:: :: ::
2015-05-26 07:00:34 +03:00
:::: :: :: server logic
2015-05-26 05:15:08 +03:00
:: :: ::
++ fail ?:(soul (fect %bel ~) ~|(%invalid-move !!)) :: user error
2015-05-26 07:00:34 +03:00
++ fect |=(sole-effect (emit %sole-effect +<)) :: update console
++ fact |=((each game tape) (emit %octo-update +<)) :: update partner
2015-05-26 05:15:08 +03:00
++ flap |= [net=$+(_. _+>) con=$+(_. _+>)] :: update all
2015-05-26 07:00:34 +03:00
=. +> (echo /octo net) (echo /sole con) ::
2015-05-23 20:03:02 +03:00
++ here ~(. go src gam) :: game core
2015-05-26 05:15:08 +03:00
++ kick |= a=point :: try move
=^ dud gam ~(m at:here a) ::
?.(dud fail ?~(rem kind (send a))) ::
++ kind =+ res:here :: move result
?~(- wild (word:wild(gam new:here) ->)) ::
++ plan |= (unit ship) :: link/unlink
?~ +< wild:stop(gam *game) ::
?^(rem fail (link u.+<)) ::
++ plot |= (each point (unit ship)) :: apply command
?-(+<- & (kick +<+), | (plan +<+)) ::
++ like |=(ship |*(* [/octo [+>+< %octo] +<])) :: message to friend
++ link |= ship :: subscribe to friend
(dish(rem `+<) peer/((like +<) /octo)) ::
++ lose ?^(rem . tame(gam out:here)) :: lost subscriber
++ meet ?^(rem . tame(gam inn:here)) :: gained subscriber
2015-05-26 07:00:34 +03:00
++ prom (fect %pro %& %octo stat) :: update prompt
++ rend (turn `wall`tab:here |=(tape txt/+<)) :: table print
++ sawn lose(eye (~(del by eye) ost)) :: console unsubscribe
++ seen meet(eye (~(put by eye) ost *sole-share)) :: console subscribe
++ send |= a=point ::
(dish poke/((like +.rem) %octo-move +<)) ::
++ show (fect %mor rend) :: update board
++ soul =(%sole -:q:(~(got by sup.hid) ost)) :: is console
++ stat ^- tape =+ ike=~[(icon who.gam)] :: status line
%- zing :~ ::
?~(rem "" "@{(scow %p u.rem)}") ::
?~(aud.gam "" vew:here) ::
?: !ept:here " ({ike}'s turn) " ::
": {ike} (row/col): " ::
== ::
2015-05-26 05:15:08 +03:00
++ stop ?~(rem . (dish pull/((like +.rem) ~))) ::
2015-05-26 07:00:34 +03:00
++ tame %+ flap |=(_. (fact:+< &/gam)) :: mild update
|=(_. prom:+<) ::
++ wild %+ flap |=(_. (fact:+< &/gam)) :: full update
|=(_. prom:show:+<) ::
2015-05-26 05:15:08 +03:00
++ word |= txt=tape %+ flap :: game message
|=(_+> (fact:+< |/txt)) ::
|=(_+> (fect:+< txt/txt)) ::
:: :: ::
2015-05-26 07:00:34 +03:00
:::: :: :: console UI
2015-05-26 05:15:08 +03:00
:: :: ::
2015-05-26 07:00:34 +03:00
++ work :: conslle action
|= act=sole-action ::
=+ say=(~(got by eye) ost) ::
|^ ?:(?=(%det -.act) (delt +.act) dive) ::
++ abet ..work(eye (~(put by eye) ost say)) :: resolve
2015-05-26 05:15:08 +03:00
++ cusp (cope !ept:here) :: parsing rule
2015-05-26 07:00:34 +03:00
++ delt |= cal=sole-change :: edit command line
=^ cul say (~(remit cs say) cal good) ::
?~(cul abet fail:(fect det/u.cul)) ::
++ dive =+ (rust (tufa buf.say) (punt comb)) :: apply command line
?~(- fail ?~(-> show (plot:wipe ->+))) ::
++ good |=((list ,@c) -:(rose (tufa +<) cusp)) :: validate input
++ wipe =^ cal say (~(transmit cs say) set/~) :: clear line
(fect:abet %det cal) ::
2015-05-26 05:15:08 +03:00
-- ::
:: :: ::
2015-05-26 07:00:34 +03:00
:::: :: :: arvo handlers
2015-05-26 05:15:08 +03:00
:: :: ::
++ reap-octo :: linked to friend
2015-05-26 07:00:34 +03:00
|= [* saw=(unit)] ::
?~ saw (word "linked to {<src>}") ::
(word(rem ~) "blocked by {<src>}") ::
:: ::
2015-05-26 05:15:08 +03:00
++ coup-octo :: move acknowledge
2015-05-26 07:00:34 +03:00
|= [* saw=(unit)] ::
?~(saw +> (word "move failed")) ::
:: ::
2015-05-26 05:15:08 +03:00
++ diff-octo-game :: friend update
2015-05-26 07:00:34 +03:00
|= [way=wire gam=game] ::
?: =(^gam gam) +> ::
wild(gam gam) ::
:: ::
2015-05-26 05:15:08 +03:00
++ peer-octo-net :: urbit peer
2015-05-26 07:00:34 +03:00
|= pax=path ::
tame:meet ::
:: ::
2015-05-26 05:15:08 +03:00
++ peer-sole :: console subscribe
2015-05-26 07:00:34 +03:00
|= pax=path ::
prom:show:seen ::
:: ::
2015-05-26 05:15:08 +03:00
++ poke-sole-action :: console input
2015-05-26 07:00:34 +03:00
|= act=sole-action ::
(work act) ::
:: ::
2015-05-26 05:15:08 +03:00
++ poke-octo-move ::
2015-05-26 07:00:34 +03:00
|= point ::
(kick +<) ::
:: ::
++ prep ::
|= [old=(unit ,[(list move) axon])] :: initialize
+>
::
2015-05-26 05:15:08 +03:00
++ pull-octo :: unsubscribe
2015-05-26 07:00:34 +03:00
|= pax=path ::
^+ +>
lose ::
::
2015-05-26 05:15:08 +03:00
++ pull-sole :: disconnect console
2015-05-26 07:00:34 +03:00
|= pax=path ::
^+ +>
sawn
::
2015-05-26 05:15:08 +03:00
++ quit-octo :: unlinked by friend
2015-05-26 07:00:34 +03:00
|= way=wire
^+ +>
?~(rem +> (link +.rem)) ::
2015-05-08 20:56:30 +03:00
-- ::
2015-05-21 02:54:49 +03:00
:: :: ::
:::: :: :: handlers
:: :: ::
++ coup-octo :: move acknowledge
2015-05-26 05:15:08 +03:00
|= [then saw=(unit tang)] ::
abet:(~(coup-octo ce ost src) way saw) ::
2015-05-12 22:57:58 +03:00
++ diff-octo-game :: friend update
2015-05-26 05:15:08 +03:00
|= [then gam=game] ::
abet:(~(diff-octo-game ce ost src) way gam) ::
2015-05-23 20:03:02 +03:00
++ peer-octo-net :: urbit peer
2015-05-26 05:15:08 +03:00
|= [from path] ::
abet:(~(peer-octo-net ce +<-) +<+) ::
2015-05-08 20:56:30 +03:00
++ peer-sole :: console subscribe
2015-05-26 05:15:08 +03:00
|= [from path] ::
abet:(~(peer-sole ce +<-) +<+) ::
2015-05-08 20:56:30 +03:00
++ poke-sole-action :: console input
2015-05-26 05:15:08 +03:00
|= [from sole-action] ::
abet:(~(poke-sole-action ce +<-) +<+) ::
2015-05-19 07:27:39 +03:00
++ poke-octo-move ::
2015-05-26 05:15:08 +03:00
|= [from point] ::
abet:(~(poke-octo-move ce +<-) +<+) ::
++ prep |= [from (unit ,[(list move) axon])] :: initialize
abet:(~(prep ce +<-) +<+) ::
2015-05-23 20:03:02 +03:00
++ pull-octo :: unsubscribe
2015-05-26 05:15:08 +03:00
|= [from path] ::
abet:(~(pull-octo ce +<-) +<+) ::
2015-05-08 20:56:30 +03:00
++ pull-sole :: disconnect console
2015-05-26 05:15:08 +03:00
|= [from path] ::
abet:(~(pull-sole ce +<-) +<+) ::
2015-05-12 22:57:58 +03:00
++ quit-octo :: unlinked by friend
2015-05-26 05:15:08 +03:00
|= then ::
abet:(~(quit-octo ce ost src) way) ::
2015-05-12 22:57:58 +03:00
++ reap-octo :: linked to friend
2015-05-26 05:15:08 +03:00
|= [then saw=(unit tang)] ::
abet:(~(reap-octo ce ost src) way saw) ::
2015-05-08 20:56:30 +03:00
--