urbit/lib/oct1.hoon

43 lines
2.7 KiB
Plaintext
Raw Normal View History

2015-05-28 06:17:09 +03:00
:: :: ::
2015-06-10 21:08:49 +03:00
:::: /hoon/oct1/lib :::::: dependencies
2015-05-28 06:17:09 +03:00
:: :: ::
/? 310 :: arvo version
2015-05-30 01:24:34 +03:00
/- *oct1 :: structures
2015-05-28 06:17:09 +03:00
:: :: ::
2015-06-10 21:08:49 +03:00
:::: :::::: semantics
2015-05-28 06:17:09 +03:00
!: :: ::
2015-06-04 23:47:49 +03:00
|% ::
2015-06-03 00:31:29 +03:00
++ icon |=(? ?:(+< 'X' 'O')) :: display at
2015-05-28 06:17:09 +03:00
++ bo :: per board
|_ bud=board ::
++ bit |=(@ =(1 (cut 0 [+< 1] bud))) :: moved at address
++ get |=(point (bit (off +<))) :: 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 :: play from
2015-05-31 10:19:35 +03:00
|_ game ::
2015-05-28 06:17:09 +03:00
++ at |_ point :: per point
2015-05-31 10:19:35 +03:00
++ g +>+< :: game
++ k !|(x o) :: legal move
2015-05-28 06:17:09 +03:00
++ m ?.(k [| g] [& g:t:?:(who y p)]) :: move
++ o (~(get bo boo) +<) :: old at o
2015-05-31 10:19:35 +03:00
++ p .(boo (~(set bo boo) +<)) :: play at o
2015-05-28 06:17:09 +03:00
++ t .(who !who) :: take turn
++ v ?:(x (icon &) ?:(o (icon |) '.')) :: view
++ x (~(get bo box) +<) :: old at x
2015-05-31 10:19:35 +03:00
++ y .(box (~(set bo box) +<)) :: play at x
2015-05-28 06:17:09 +03:00
-- ::
2015-05-31 10:19:35 +03:00
++ new +<(boo 0, box 0, who &) :: reset game
2015-05-28 06:17:09 +03:00
++ res ?. |(~(win bo box) ~(win bo boo)) :: possible result
?: =(511 (con boo box)) ::
2015-05-31 10:19:35 +03:00
`"tie :-(" ~ `"{<~[(icon who)]>} wins" ::
2015-05-28 06:17:09 +03:00
++ row |= y=@ :- (add y '1') %- zing :: print row
(turn (gulf 0 3) |=(@ ~[' ' ~(v at y +<)])) ::
++ tab ~["+ 1 2 3" (row 0) (row 1) (row 2)] :: print table
2015-05-31 10:19:35 +03:00
++ voy ": {<~[(icon who)]>} (row/col): " :: print prompt
2015-05-29 11:36:23 +03:00
--
2015-05-28 06:17:09 +03:00
--