shrub/lib/womb.hoon

411 lines
15 KiB
Plaintext
Raw Normal View History

2016-04-08 20:08:05 +03:00
:: :: ::
:::: /hoon/womb/lib :: ::
:: :: ::
/? 310 :: version
/+ talk
:: :: ::
:::: :: ::
:: :: ::
|%
2016-04-12 22:02:59 +03:00
++ foil :: ship allocation map
2016-04-08 20:08:05 +03:00
|* mold :: entry mold
2016-04-13 01:42:49 +03:00
$: min/@u :: minimum entry
ctr/@u :: next allocated
und/(set @u) :: free under counter
ove/(set @u) :: alloc over counter
max/@u :: maximum entry
box/(map @u +<) :: entries
2016-04-08 20:08:05 +03:00
== ::
-- ::
2016-04-12 22:02:59 +03:00
:: $: min/@p
:: mid/@p
:: max/@p
:: box/(map @p (each mail ))
:: ==
:: |%
:: ++ ships (list {min/@p mid/@p max/@p ish/(map @p state)})
:: ++ state ?($given $split {$~ mail})
:: ++
2016-04-08 20:08:05 +03:00
|% ::
++ managed :: managed plot
|* mold ::
2016-04-12 22:02:59 +03:00
%- unit :: unsplit
2016-04-08 20:08:05 +03:00
%+ each +< :: subdivided
mail :: delivered
:: ::
2016-04-12 22:02:59 +03:00
++ divided
|* (managed)
?- +<
$~ ~
{$~ $| *} ~
{$~ $& *} (some p.u.+<)
==
::
++ moon (managed _!!) :: undivided moon
::
2016-04-08 20:08:05 +03:00
++ planet :: subdivided planet
(managed (lone (foil moon))) ::
:: ::
++ star :: subdivided star
(managed (pair (foil moon) (foil planet))) ::
:: ::
++ galaxy :: subdivided galaxy
(managed (trel (foil moon) (foil planet) (foil star)))::
:: ::
++ passcode @pG :: 64-bit passcode
++ mail @ta :: email address
++ balance :: invitation balance
$: planets/@ud :: planet count
stars/@ud :: star count
owner/mail :: owner's email
history/(list mail) :: transfer history
== ::
++ client :: per email
$: sta/@ud :: unused star refs
has/(set @p) :: planets owned
== ::
2016-04-13 00:07:02 +03:00
++ property :: subdivided plots
$: galaxies/(map @p galaxy) :: galaxy
planets/(map @p planet) :: star
stars/(map @p star) :: planet
2016-04-08 20:08:05 +03:00
== ::
++ invite ::
$: who/mail :: who to send to
pla/@ud :: planets to send
sta/@ud :: stars to send
wel/welcome :: welcome message
== ::
++ welcome :: welcome message
$: intro/tape :: in invite email
hello/tape :: as talk message
== ::
++ reference :: affiliate credit
(unit (each @p mail)) :: ship or email
-- ::
:: :: ::
:::: :: ::
:: :: ::
|%
++ womb-part {$womb $0 womb-pith} :: womb state
++ womb-pith :: womb content
$: boss/(unit @p) :: outside master
bureau/(map passcode balance) :: active invitations
2016-04-13 00:07:02 +03:00
office/property :: properties managed
2016-04-08 20:08:05 +03:00
hotel/(map mail client) :: everyone we know
== ::
-- ::
:: :: ::
:::: :: ::
:: :: ::
|% :: arvo structures
++ card ::
$% {$flog wire flog} ::
2016-04-12 22:02:59 +03:00
::{$wait $~}
:: {$poke
{$next p/ring} :: update private key
{$tick p/@pG q/@p} :: save ticket
2016-04-08 20:08:05 +03:00
== ::
++ move (pair bone card) :: user-level move
--
2016-04-12 22:02:59 +03:00
|%
++ murn-by
|* {a/(map) b/$-(* (unit))}
^- ?~(a !! (map _p.n.a _(need (b q.n.a))))
%- malt
%+ murn (~(tap by a))
?~ a $~
|= _c=n.a ^- (unit _[p.n.a (need (b q.n.a))])
=+ d=(b q.c)
?~(d ~ (some [p.c u.d]))
::
++ unsplit
|= a/(map ship (managed)) ^- (list {ship *})
%+ skim (~(tap by a))
|=({@ a/(managed)} ?=($~ a))
::
++ issuing
|* a/(map ship (managed))
2016-04-13 01:42:49 +03:00
^- (list {ship _(need (divided *~(got by a)))})
(sort (~(tap by (murn-by a divided))) lor)
::
++ issuing-under
|* {a/bloq b/ship c/(map @u (managed))}
^- (list {ship _(need (divided *~(got by c)))})
%+ turn (sort (~(tap by (murn-by c divided))) lor)
|*(d/{@u *} [(rep a b -.d ~) +.d])
2016-04-12 22:02:59 +03:00
::
2016-04-13 00:54:50 +03:00
++ cursor (pair (unit ship) @u)
2016-04-13 01:59:26 +03:00
::
:: Create new foil of size
2016-04-13 00:54:50 +03:00
++ fo-init
2016-04-13 01:42:49 +03:00
|= a/bloq :: ^- (foil *)
[min=1 ctr=1 und=~ ove=~ max=(dec (bex (bex a))) box=~]
2016-04-13 00:54:50 +03:00
::
2016-04-12 22:02:59 +03:00
++ fo
|_ (foil)
++ get :: nth
2016-04-13 01:42:49 +03:00
|= a/@u ^- (pair (unit @u) @u)
2016-04-12 22:02:59 +03:00
?: (lth a ~(wyt in und))
=+ out=(snag a (sort (~(tap in und)) lth))
[(some out) 0]
=. a (sub a ~(wyt in und))
2016-04-13 01:42:49 +03:00
|- ^- {(unit @u) @u}
2016-04-12 22:02:59 +03:00
?: =(ctr +(max)) [~ a]
?: =(0 a) [(some ctr) a]
$(a (dec a), +<.get new)
::
2016-04-13 00:54:50 +03:00
+- fin +< :: abet
2016-04-12 22:02:59 +03:00
++ new :: alloc
?: =(ctr +(max)) +<
=. ctr +(ctr)
?. (~(has in ove) ctr) +<
new(ove (~(del in ove) ctr))
::
2016-04-13 00:54:50 +03:00
+- put
2016-04-13 01:42:49 +03:00
|* {a/@u b/*} ^+ fin :: b/_(~(got by box))
~| put+[a fin]
2016-04-13 00:54:50 +03:00
?> (fit a)
=; adj adj(box (~(put by box) a b))
?: (~(has in box) a) fin
?: =(ctr a) new
?: (lth a ctr)
?. (~(has in und) a) fin
fin(und (~(del in und) a))
?. =(a ctr:new) :: heuristic
fin(ove (~(put in ove) a))
=+ n=new(+< new)
n(und (~(put in und.n) ctr))
::
2016-04-13 01:42:49 +03:00
++ fit |=(a/@u &((lte min a) (lte a max))) :: in range
2016-04-12 22:02:59 +03:00
++ gud :: invariant
?& (fit(max +(max)) ctr)
(~(all in und) fit(max ctr))
(~(all in ove) fit(min ctr))
2016-04-13 01:42:49 +03:00
(~(all in box) |=({a/@u *} (fit a)))
2016-04-12 22:02:59 +03:00
|- ^- ?
?: =(min max) &
=- &(- $(min +(min)))
%+ gte 1 :: at most one of
;: add
?:(=(min ctr) 1 0)
?:((~(has in und) min) 1 0)
?:((~(has in ove) min) 1 0)
?:((~(has by box) min) 1 0)
==
==
--
--
2016-04-08 20:08:05 +03:00
:: :: ::
:::: :: ::
!: :: ::
|= {bowl womb-part} :: main womb work
|_ moz/(list move)
++ abet :: resolve
2016-04-13 00:07:02 +03:00
^- (quip move *womb-part)
[(flop moz) +>+<+]
2016-04-08 20:08:05 +03:00
::
++ emit |=(card %_(+> moz [[ost +<] moz])) :: return card
++ emil :: return cards
|= (list card)
^+ +>
?~(+< +> $(+< t.+<, +> (emit i.+<)))
::
2016-04-12 22:02:59 +03:00
::
2016-04-13 00:07:50 +03:00
++ take-n
|= {{index/@u count/@u} get/$-(@u cursor)}
2016-04-12 22:02:59 +03:00
^- (list ship)
2016-04-13 00:07:50 +03:00
?~ count ~
%+ biff p:(get index)
|= a/ship ^- (list ship)
[a ^$(index +(index), count (dec count))]
2016-04-12 22:02:59 +03:00
::
++ available
|= all/(map ship (managed)) ^- $-(@u cursor)
=+ pur=(sort (turn (unsplit all) head) lth)
=+ len=(lent pur)
|=(a/@u ?:((gte a len) [~ (sub a len)] [(some (snag a pur)) a]))
::
2016-04-13 00:07:50 +03:00
++ shop-galaxies (available galaxies.office)
2016-04-12 22:02:59 +03:00
::
:: Stars can be either whole or children of galaxies
++ shop-stars
2016-04-13 00:07:50 +03:00
|= nth/@u ^- cursor
2016-04-13 00:07:02 +03:00
=^ out nth %.(nth (available stars.office))
2016-04-12 22:02:59 +03:00
?^ out [out nth]
2016-04-13 00:07:02 +03:00
(shop-star nth (issuing galaxies.office))
2016-04-12 22:02:59 +03:00
::
2016-04-13 01:42:49 +03:00
++ prefix
|= {a/bloq b/@p {c/(unit @u) d/@u}} ^- cursor
?~ c [c d]
[(some (rep a b u.c ~)) d]
::
2016-04-13 01:59:36 +03:00
++ in-list
|* {a/(list) b/@u} ^+ [(snag *@ a) b]
=+ c=(lent a)
[(snag (mod b c) a) (div b c)]
::
2016-04-12 22:02:59 +03:00
++ shop-star
2016-04-13 01:42:49 +03:00
|= {nth/@u lax/(list {who/@p * * r/(foil star)})} ^- cursor
2016-04-13 01:59:36 +03:00
?: =(~ lax) [~ nth]
=^ sel nth (in-list lax nth)
(prefix 3 who.sel (~(get fo r.sel) nth))
2016-04-12 22:02:59 +03:00
::
++ shop-planets
|= nth/@u ^- cursor
2016-04-13 00:07:02 +03:00
=^ out nth %.(nth (available planets.office))
2016-04-12 22:02:59 +03:00
?^ out [out nth]
2016-04-13 00:07:02 +03:00
=^ out nth (shop-planet nth (issuing stars.office))
2016-04-12 22:02:59 +03:00
?^ out [out nth]
2016-04-13 00:07:02 +03:00
(shop-planet-gal nth (issuing galaxies.office))
2016-04-12 22:02:59 +03:00
::
++ shop-planet
2016-04-13 01:59:36 +03:00
|= {nth/@u sta/(list {who/@p * q/(foil planet)})} ^- cursor
?: =(~ sta) [~ nth]
=^ sel nth (in-list sta nth)
(prefix 4 who.sel (~(get fo q.sel) nth))
2016-04-12 22:02:59 +03:00
::
++ shop-planet-gal
2016-04-13 01:42:49 +03:00
|= {nth/@u lax/(list {who/@p * * r/(foil star)})} ^- cursor
2016-04-13 01:59:36 +03:00
?: =(~ lax) [~ nth]
=^ sel nth (in-list lax nth)
(shop-planet nth (issuing-under 3 who.sel box.r.sel))
2016-04-12 22:02:59 +03:00
::
++ peek-x-shop
|= tyl/path ^- (unit (unit {$ships (list @p)}))
=; res (some (some [%ships res]))
=+ ~|(bad-path+tyl (raid tyl typ=%tas nth=%ud ~))
2016-04-13 00:07:50 +03:00
:: =. nth (mul 3 nth)
?+ typ ~|(bad-type+typ !!)
$galaxy (take-n [nth 3] shop-galaxies)
$planet (take-n [nth 3] shop-planets)
$star (take-n [nth 3] shop-stars)
2016-04-12 22:02:59 +03:00
==
::
++ stats-ship
|= who/@p ^- (unit (unit (cask _!!)))
~
::
++ peek-x-stats
|= tyl/path
?^ tyl
(stats-ship ~|(bad-path+tyl (raid tyl who=%p ~)))
^- (unit (unit (cask _!!)))
~
::
++ peek-x-invite
|= tyl/path ^- (unit (unit {$womb-balance balance}))
=+ ~|(bad-path+tyl (raid tyl pas=%p ~))
%- some
%+ bind (~(get by bureau) pas)
|=(bal/balance [%womb-balance bal])
::
2016-04-08 20:08:05 +03:00
++ peek
|= {ren/@tas tyl/path}
2016-04-12 22:02:59 +03:00
:: ^- (unit (unit (pair mark *)))
?. =(ren %x) ~
?~ tyl ~
?+ -.tyl ~
:: /shop/planet/@ud (list @p) up to 3 planets
:: /shop/star/@ud (list @p) up to 3 stars
:: /shop/galaxy/@ud (list @p) up to 3 galaxies
$shop (peek-x-shop +.tyl)
2016-04-08 20:08:05 +03:00
:: /stats general stats dump
:: /stats/@p what we know about @p
2016-04-12 22:02:59 +03:00
$stats (peek-x-stats +.tyl)
:: /invite/passcode invitation status
$invite (peek-x-invite +.tyl)
==
2016-04-08 20:08:05 +03:00
::
++ poke-invite :: create invitation
|= {ref/reference inv/invite}
=< abet
?> |(=(our src) =([~ src] boss)) :: me or boss
.
::
++ poke-obey :: set/reset boss
|= who/(unit @p)
=< abet
?> =(our src) :: me only
.
::
++ poke-rekey :: extend will
2016-04-12 22:02:59 +03:00
|= $~
2016-04-08 20:08:05 +03:00
=< abet
?> |(=(our src) =([~ src] boss)) :: privileged
.
::
++ poke-report :: report will
|= {her/@p wyl/will} ::
=< abet
?> =(src src) :: self-authenticated
.
::
++ poke-claim :: claim plot, send ticket
|= {aut/@uvH her/@p} ::
=< abet
2016-04-12 22:02:59 +03:00
?> =(src src)
2016-04-08 20:08:05 +03:00
.
::
++ poke-release :: release to subdivide
|= {gal/@ud sta/@ud} ::
2016-04-13 00:54:50 +03:00
=< abet ^+ +>
2016-04-08 20:08:05 +03:00
?> =(our src) :: privileged
2016-04-13 00:54:50 +03:00
=. +>
?~ gal +>
=+ all=(take-n [0 gal] shop-galaxies)
?. (gth gal (lent all))
(roll all release-galaxy)
~|(too-few-galaxies+[want=gal has=(lent all)] !!)
^+ +>
?~ sta +>
=+ all=(take-n [0 sta] shop-stars)
~& got-stars+all
?. (gth sta (lent all))
(roll all release-star)
~|(too-few-stars+[want=sta has=(lent all)] !!)
::
++ release-galaxy
=+ [who=*@p res=.]
|. ^+ res
2016-04-13 01:42:49 +03:00
=+ new=(some %& (fo-init 5) (fo-init 4) (fo-init 3))
2016-04-13 00:54:50 +03:00
=+ gal=(~(got by galaxies.office.res) who)
?^ gal ~|(already-used+who !!)
res(galaxies.office (~(put by galaxies.office.res) who new))
::
++ release-star
=+ [who=*@p res=.]
|. ^+ res
~& release+who
2016-04-13 01:42:49 +03:00
=+ new=(some %& (fo-init 5) (fo-init 4))
2016-04-13 00:54:50 +03:00
?: (~(has by stars.office.res) who)
=+ sta=(~(got by stars.office.res) who)
?~ sta
res(stars.office (~(put by stars.office.res) who new))
~|(already-used+[who u.sta] !!)
=+ gal=(~(got by galaxies.office.res) (sein who))
=; lax/galaxy
res(galaxies.office (~(put by galaxies.office.res) (sein who) lax))
?. ?=({$~ $& *} gal)
~|(unavailable-galaxy+(sein who) !!)
%_ gal
r.p.u
=+ sta=r.p.u.gal ^+ sta
2016-04-13 01:42:49 +03:00
=+ ind=(rsh 3 1 who)
=+ ole=(~(get by box.sta) ind)
?~ ole (~(put fo sta) ind new)
?~ u.ole (~(put fo sta) ind new)
2016-04-13 00:54:50 +03:00
~|(already-used+[(sein who) who u.ole] !!)
==
2016-04-08 20:08:05 +03:00
::
++ poke-reinvite :: split invitation
|= $: aut/@uvH :: hash w/passcode
inv/invite :: further invite
==
?> =(src src) ::
=< abet
.
--