Latest stuff hand-merged from %behn.

This commit is contained in:
C. Guy Yarvin 2015-05-08 10:56:30 -07:00
parent ceb79e045f
commit b0eac3721a
4 changed files with 291 additions and 116 deletions

View File

@ -1,11 +1,11 @@
:: :: ::
:::: /hook/core/acto/ape :: ::
:: :: ::
:: ::::::::::::::: build
:::: /hook/core/acto/ape :: :: ::
:: :::::::::::::::
/- *sole :: structures
/+ sole :: libraries
:: ::
:::: ::
!: ::
:: ::::::::::::::: logic
:::: :: :: ::
!: :::::::::::::::
=> |% :: board logic
++ board ,@ :: one-player bitfield
++ point ,[x=@ y=@] :: coordinate
@ -19,104 +19,87 @@
-- ::
-- ::
=> |% :: game logic
++ game ,[tun=? box=board boo=board] :: game state
++ game ,[%0 who=? box=board boo=board] :: game state
++ go :: game core
|_ game ::
++ pro ": {?:(tun "X" "O")} to move (x/y): " :: prompt
++ say |= point :: point value
?: (~(get bo box) +<) 'X'
?: (~(get bo boo) +<) 'O' '.'
::
++ mov :: move at
|= point
^- [bean game]
?: |((~(get bo box) +<) (~(get bo boo) +<))
[| +>+<]
:- & ?: tun
+>+<(tun |, box (~(set bo box) +<))
+>+<(tun &, boo (~(set bo boo) +<))
::
++ res ^- (unit tape) :: result
?: ~(win bo box) `"X wins!"
?: ~(win bo boo) `"O wins!"
?: =(511 (con boo box)) `"X and O tied." ~
::
++ ray :: render row
|= y=@ ^- tape
:~ (add y '1')
' ' (say y 0)
' ' (say y 1)
' ' (say y 2)
==
++ red ~["+ 1 2 3" (ray 0) (ray 1) (ray 2)] :: render board
--
--
=> |% :: arvo tools
++ card ,[%diff %sole-effect sole-effect] ::
++ move (pair bone card)
++ room (pair sole-share game)
--
|_ $: hid=hide :: system state
hoc=(map bone room)
==
++ yo
|_ [[ost=bone moz=(list move)] rom=room]
++ abet :: resolve
^- (quip move +>)
[(flop moz) +>(hoc (~(put by hoc) ost rom))]
::
++ emit :: produce move
|= fec=sole-effect
^+ +>
+>(moz [[ost %diff %sole-effect fec] moz])
::
++ emil :: emit multiple
|= fex=(list sole-effect)
?~(fex +> $(fex t.fex, +> (emit i.fex)))
::
++ show :: update ui
%+ emil [%pro & %toe ~(pro go q.rom)]
(turn ~(red go q.rom) |=(a=tape [%txt a]))
::
++ wipe :: clear input line
=^ cal p.rom (~(transmit cs p.rom) [%set ~])
(emit %det cal)
::
++ numb (cook |=(a=@ (sub a '1')) (shim '1' '3')) :: row/column
++ come ;~(plug numb ;~(pfix fas numb)) :: command
++ at |_ point :: point core
++ g +>+< :: game
++ k !|(x o) :: ok move
++ m ?.(k [| g] [& g:t:?:(who y p)]) :: move
++ o (~(get bo boo) +<) :: old at o
++ p .(boo (~(set bo boo) +<)) :: play at o
++ t .(who !who) :: take turn
++ v ?:(x 'X' ?:(o 'O' '.')) :: view
++ x (~(get bo box) +<) :: old at x
++ y .(box (~(set bo box) +<)) :: play at x
-- ::
++ pro ": {?:(who "X" "O")}'s move (row/col): " :: prompt
++ res ?: ~(win bo box) `"X wins!" :: result
?: ~(win bo boo) `"O wins!" ::
?: =(511 (con boo box)) `"tie :-(" ~ ::
++ row |= y=@ :~ (add y '1') :: print row
' ' ~(v at y 0) ::
' ' ~(v at y 1) ::
' ' ~(v at y 2) ::
== ::
++ tab ^- (list tape) :: print game
~["+ 1 2 3" (row 0) (row 1) (row 2)] ::
-- ::
-- ::
:: ::::::::::::::: agent
:::: :: :: ::
:: :::::::::::::::
=> |% :: arvo structures
++ card ,[%diff %sole-effect sole-effect] :: action
++ move (pair bone card) :: operation
++ face (pair (list ,@c) (map bone sole-share)) :: interface
++ axle ,[%0 eye=face gay=game] :: agent state
-- ::
|_ [hid=hide moz=(list move) axle] :: agent core
++ et :: client core
|_ [from say=sole-share] ::
++ abet +>(q.eye (~(put by q.eye) ost say)) :: continue
++ amok +>(q.eye (~(del by q.eye) ost)) :: discontinue
++ numb (cook |=(a=@ (sub a '1')) (shim '1' '3')) :: parse row/column
++ come ;~(plug numb ;~(pfix fas numb)) :: parse command
++ good |=(a=(list ,@c) -:(rose (tufa a) come)) :: validate
++ work ::
|= act=sole-action
^+ +>
?- -.act
%det
=^ cul p.rom (~(remit cs p.rom) +.act good)
?~(cul +>.$ (emit ~[%mor bel/~ det/u.cul]))
::
%ret
=+ dur=(rust (tufa buf.p.rom) come)
?~ dur (emit %bel ~)
=^ dud q.rom (~(mov go q.rom) u.dur)
?. dud (emit %bel ~)
=+ rus=~(res go q.rom)
=< show
?~ rus wipe
wipe:(emit(q.rom *game) %txt u.rus)
==
--
++ peer-sole :: console-subscribe
|= [from pax=path]
^- (quip move +>)
?> =(src our.hid)
abet:~(show yo [ost ~] *room)
::
++ poke-sole-action :: console command
|= [from act=sole-action]
^- (quip move +>)
?> =(src our.hid)
abet:(~(work yo [ost ~] (~(got by hoc) ost)) act)
::
++ pull :: stop subscription
|= then
[~ +>(hoc (~(del by hoc) ost))]
++ sole ~(. cs say) :: console core
++ 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))) ::
++ line =^ cal say (transmit:sole set/p.eye) :: update input line
(emit %det cal) ::
++ show (emil (turn ~(tab go gay) |=(tape txt/+<))) :: update board
++ view (emit:line:show %pro %& acto/~(pro go gay)) :: full view update
++ more |= [ful=? mus=(unit tape)] =< abet :: all updates
=. +> ?:(ful view line) ::
?~(mus +> (emit %txt u.mus)) ::
++ delt |= cal=sole-change :: input line change
=^ cul say (remit:sole cal good) ::
?~ cul (park:abet(p.eye buf.say) | ~) ::
abet:(emit ~[%mor det/u.cul bel/~]) ::
++ make =+ dur=(rust (tufa p.eye) come) ::
?~ dur abet:(emit bel/~) ::
=^ dud gay ~(m ~(at go gay) u.dur) ::
?. dud abet:(emit bel/~) ::
=+ mus=~(res go gay) %. [& mus] ::
park:abet(p.eye ~, gay ?^(mus *game gay)) ::
++ work |= act=sole-action :: console input
?:(?=(%det -.act) (delt +.act) make) ::
-- ::
++ abet [(flop moz) .(moz ~)] ::
++ pals %+ turn (~(tap by sup.hid)) :: list clients
|= [a=bone b=ship c=path] ::
[[p=a q=b] r=(~(got by q.eye) a)] ::
++ park |= [ful=? mus=(unit tape)] ::
=+ pals |- ^+ +>.^$ :: update clients
?~ +< +>.^$ ::
$(+< t.+<, +>.^$ (~(more et i.+<) ful mus)) ::
++ flet |=(from ~(. et +< (~(got by q.eye) ost))) :: existing peer
++ fret |=(from ~(. et +< *sole-share)) :: new peer
++ peer-sole |=([from *] abet:abet:view:(fret +<-)) :: connect
++ pull-sole |=([from *] abet:amok:(flet +<-)) :: disconnect
++ poke-sole-action :: console input
|=([from act=sole-action] abet:(work:(flet +<-) act)) ::
--

195
base/ape/octo/core.hook Normal file
View File

@ -0,0 +1,195 @@
:: :::::::::::::::
:::: /hook/core/octo/ape :: :: :: build
:: :::::::::::::::
/- *sole :: structures
/+ sole :: libraries
:: :::::::::::::::
:::: :: :: :: logic
!: :::::::::::::::
=> |% :: board logic
++ board ,@ :: one-player bitfield
++ point ,[x=@ y=@] :: coordinate
++ game ,[who=? box=board boo=board] :: game state
++ icon |=(? ?:(+< 'X' 'O')) :: display at
++ bo :: per board
|_ bud=board ::
++ get |=(point =(1 (cut 0 [(off +<) 1] bud))) :: get point
++ off |=(point (add x (mul 3 y))) :: bitfield address
++ set |=(point (con bud (bex (off +<)))) :: set point
++ win %- lien :_ |=(a=@ =(a (dis a bud))) :: test for win
(rip 4 0wl04h0.4A0Aw.4A00s.0e070) :: with bitmasks
-- ::
++ go :: per game
|_ game ::
++ at |_ point :: per point
++ g +>+< :: game
++ k !|(x o) :: ok move
++ m ?.(k [| g] [& g:t:?:(who y p)]) :: move
++ o (~(get bo boo) +<) :: old at o
++ p .(boo (~(set bo boo) +<)) :: play at o
++ t .(who !who) :: take turn
++ v ?:(x (icon &) ?:(o (icon |) '.')) :: view
++ x (~(get bo box) +<) :: old at x
++ y .(box (~(set bo box) +<)) :: play at x
-- ::
++ res ?: ~(win bo box) `"{~[(icon &)]} wins" :: result
?: ~(win bo boo) `"{~[(icon |)]} wins" ::
?: =(511 (con boo box)) `"tie :-(" ~ ::
++ row |= y=@ :~ (add y '1') :: print row
' ' ~(v at y 0) ::
' ' ~(v at y 1) ::
' ' ~(v at y 2) ::
== ::
++ tab ~["+ 1 2 3" (row 0) (row 1) (row 2)] :: print table
-- ::
-- ::
:: :::::::::::::::
:::: :: :: :: agent
:: :::::::::::::::
=> |% :: arvo structures
++ axle ,[%1 eye=face but=tube gam=game] :: agent state
++ axon $?(axle [%0 eye=face gam=game]) :: historical state
++ card $% [%diff lime] :: update
[%quit ~] :: cancel
[%peer wire dock path] :: subscribe
[%pull wire dock ~]
== ::
++ face (pair (list ,@c) (map bone sole-share)) :: interface
++ lime $% [%sole-effect sole-effect] :: :sole update
[%octo-game game] :: :octo update
== ::
++ move (pair bone card) :: cause and action
++ mote (pair ship ,?) :: remote binding
++ sink (trel bone ship path) :: promote
++ tube (unit (pair ,? mote)) :: alive, remote
-- ::
=> |% :: promote
++ pick
|* [a=_rule b=_rule]
;~ pose
(stag %& a)
(stag %| b)
==
++ punt
|* [a=_rule]
;~(pose (stag ~ a) (easy ~))
::
++ flag
|= [sic=@t non=@t]
;~(pose (cold %& (jest sic)) (cold %| (jest non)))
-- ::
=> |% :: parsers
++ colm (cook |=(a=@ (sub a '1')) (shim '1' '3')) :: row or column
++ come ;~(plug colm ;~(pfix fas colm)) :: coordinate
++ comb (pick come (punt ;~(pfix sig comp))) :: all command input
++ comp ;~(plug fed:ag ;~(pfix ace (flag %x %o))) :: login command
++ cope |=(? ?:(+< (stag %| (cold ~ sig)) comb)) :: with wait mode
-- ::
|_ [hid=hide moz=(list move) axle] :: per agent
++ 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
?< =(0 ost)
+>(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
++ kick |= point :: move command
=^ dud gam ~(m ~(at go gam) +<) ::
?. dud abet:beep =+ mus=~(res go gam) ::
(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) ::
++ prom %^ emit %pro %& :- %octo :: update prompt
?: wait "(xir turn) " ::
": {~[(icon who.gam)]} to move (row/col): " ::
++ plan |= mut=(unit mote) :: peer command
?~ mut ?~(but abet:beep stop:abet) ::
?^(but abet:beep (link:abet u.mut)) ::
++ rend (turn `wall`~(tab go gam) |=(tape txt/+<)) :: table print
++ show (emit %mor rend) :: update board
++ sole ~(. cs say) :: console library
++ wait &(?=(^ but) !=(q.q.u.but who.gam)) :: waiting turn
++ work |= act=sole-action :: console input
?:(?=(%det -.act) (delt +.act) make) ::
-- ::
++ abet [(flop moz) .(moz ~)] :: resolve core
++ dump %_(+> moz [mov moz]) :: send move
++ 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
++ like |=(xir=ship |*(* [/octo [xir %octo] +<])) :: to friend
++ link |= mot=mote %- dish(but `[| mot]) :: subscribe to friend
peer/((like p.mot) /octo/[?:(q.mot %x %o)]) ::
++ pale |=(f=$+(sink ?) (skim (~(tap by sup.hid)) f)) :: filter peers
++ pals %+ turn (pale (prix /sole)) |= sink :: per console
[[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)) ::
++ prix |= pax=path |= sink ^- ? :: filter gate
?~ pax & ?~ r.+< | ::
&(=(i.pax i.r.+<) $(pax t.pax, r.+< t.r.+<)) ::
++ push =+ pey=(pale (prix /octo)) |- ^+ +> :: update friends
?~(pey +> $(pey t.pey, +> (sell p.i.pey))) ::
++ sell |=(ost=bone (dump ost %diff %octo-game gam)) :: update friend
++ stop (dish(but ~) pull/((like +>-.but) ~)) :: cancel subscribe
:: :::::::::::::::
:::: :: :: :: hooks
:: :::::::::::::::
++ diff-octo-game :: friend update
|= [then gam=game] =< abet ::
?. &(?=([~ %& *] but) =(src p.q.u.but)) +> ::
?: =(^gam gam) +> ::
(park(gam gam) %2 ~) ::
++ peer-octo :: linked by friend
|= [from pax=path] =< abet ::
=+ who==(%x -.pax) ::
?^ but (park %2 ~) :: [~ %& !who src]
(park:(link src !who) %2 `"link by {<src>}") ::
++ peer-sole :: console subscribe
|= [from *] =< abet ::
(plow:(fret +<-) %2 ~) ::
++ poke-sole-action :: console input
|= [from act=sole-action] =< abet ::
(work:(flet +<-) act) ::
++ prep |= [from old=(unit ,[(list move) axon])] :: initialize
=< abet ?~ old +> ::
=< (park %2 ~) ::
?- -.+>.old ::
%1 +>(+<+ u.old) ::
%0 +>(eye.+< eye.+>.old, gam.+< gam.+>.old)::
== ::
++ pull-octo ::
|= [from ~] =< abet ::
(park(but ~) %0 `"dropped") ::
++ pull-sole :: disconnect console
|= [from *] =< abet ::
amok:(flet +<-) ::
++ quit-octo :: unlinked by friend
|=([then ~] abet:(park(but ~) %0 `"removed")) ::
++ reap-octo :: linked to friend
|= [then saw=(unit tang)] =< abet ::
?> ?=([~ %| *] but) ::
?^ saw (park:stop %0 `"fail to {<src>}") ::
(park(p.u.but %&) %0 `"link to {<src>}") ::
--

View File

@ -661,10 +661,11 @@
::
++ onto
|= [then saw=(each suss tang)]
:_ +> :_ ~
:_ +>
?- -.saw
%| [ost %flog ~ %crud `@tas`-.way `tang`p.saw]
%& [ost %flog ~ %text "<{<p.saw>}>"]
%| [[ost %flog ~ %crud `@tas`-.way `tang`p.saw] ~]
%& :: [ost %flog ~ %text "<{<p.saw>}>"]
~
==
::
++ pull

View File

@ -268,8 +268,8 @@
pup pup
hav hav
p.zam 1
q.zam [[~ 0] ~ ~]
r.zam [[0 ~] ~ ~]
q.zam [[[~ ~] 0] ~ ~]
r.zam [[0 [~ ~]] ~ ~]
==
==
::
@ -577,20 +577,16 @@
$(ded t.ded, +>.^$ ap-kill(ost i.ded))
?. ?=([%give %diff *] q.i.pyz)
$(pyz t.pyz)
=^ vad +> ap-fill
=^ vad +> ap-fill(ost p.i.pyz)
$(pyz t.pyz, ful ?:(vad ful (~(put in ful) p.i.pyz)))
::
++ ap-aver :: cute to move
|= cov=cute
^- move
=+ fuk=(~(get by r.zam) p.cov)
?~ fuk
~& [%ap-aver-fuk p.cov]
!!
:- (~(got by r.zam) p.cov)
?- -.q.cov
?(%slip %sick) !!
%give [%give %unto p.q.cov]
%give ?<(=(0 p.cov) [%give %unto p.q.cov])
%pass
:+ %pass `path`[%use dap p.q.cov]
?- -.q.q.cov
@ -673,10 +669,10 @@
++ ap-fill :: add to queue
^- [? _.]
=+ suy=(fall (~(get by qel.ged) ost) 0)
?: =(10 suy)
?: =(8 suy)
~& [%ap-fill-full [our dap] q.q.pry ost]
[%| +]
:: ~? !=(10 suy) [%ap-fill-add [[our dap] q.q.pry ost] +(suy)]
:: ~? !=(8 suy) [%ap-fill-add [[our dap] q.q.pry ost] +(suy)]
[%& +(qel.ged (~(put by qel.ged) ost +(suy)))]
::
++ ap-find :: general arm