modal/examples/tictactoe.modal

45 lines
1.7 KiB
Plaintext
Raw Normal View History

2024-04-15 19:26:25 -04:00
?(?-) (This example demonstrates how to implement a 2-players game of Tic Tac Toe)
2024-04-11 20:01:48 -04:00
<> (-- ?x) ()
2024-04-14 20:33:42 -04:00
<> (READ ?~) (?~)
2024-04-11 20:01:48 -04:00
-- (Print)
2024-04-11 20:20:35 -04:00
<> (?: put-str) (?:)
<> ((?0 ?1 ?2) put-row) (?0 put-str | put-str ?1 put-str | put-str ?2 put-str \n put-str)
<> ((?a ?b ?c) display) (?a put-row ?b put-row ?c put-row \n put-str (?a ?b ?c))
2024-04-11 20:01:48 -04:00
-- (Validation)
<> (((?x ?x ?x) ?0 ?1) ?x run) (?x victory)
<> ((?0 (?x ?x ?x) ?1) ?x run) (?x victory)
<> ((?0 ?1 (?x ?x ?x)) ?x run) (?x victory)
<> (((?x ?0 ?1) (?x ?2 ?3) (?x ?4 ?5)) ?x run) (?x victory)
<> (((?0 ?x ?1) (?2 ?x ?3) (?4 ?x ?5)) ?x run) (?x victory)
<> (((?0 ?1 ?x) (?2 ?3 ?x) (?4 ?5 ?x)) ?x run) (?x victory)
<> (((?x ?0 ?1) (?2 ?x ?3) (?4 ?5 ?x)) ?x run) (?x victory)
2024-04-11 20:58:44 -04:00
<> (((?0 ?1 ?x) (?2 ?x ?3) (?x ?4 ?5)) ?x run) (?x victory)
2024-04-11 20:01:48 -04:00
-- (Game)
<> (((?0 ?1 ?2) ?a ?b) ?x 0 0 play) (((?x ?1 ?2) ?a ?b) display ?x run wait)
<> (((?0 ?1 ?2) ?a ?b) ?x 1 0 play) (((?0 ?x ?2) ?a ?b) display ?x run wait)
<> (((?0 ?1 ?2) ?a ?b) ?x 2 0 play) (((?0 ?1 ?x) ?a ?b) display ?x run wait)
<> ((?a (?0 ?1 ?2) ?b) ?x 0 1 play) ((?a (?x ?1 ?2) ?b) display ?x run wait)
<> ((?a (?0 ?1 ?2) ?b) ?x 1 1 play) ((?a (?0 ?x ?2) ?b) display ?x run wait)
<> ((?a (?0 ?1 ?2) ?b) ?x 2 1 play) ((?a (?0 ?1 ?x) ?b) display ?x run wait)
<> ((?a ?b (?0 ?1 ?2)) ?x 0 2 play) ((?a ?b (?x ?1 ?2)) display ?x run wait)
<> ((?a ?b (?0 ?1 ?2)) ?x 1 2 play) ((?a ?b (?0 ?x ?2)) display ?x run wait)
<> ((?a ?b (?0 ?1 ?2)) ?x 2 2 play) ((?a ?b (?0 ?1 ?x)) display ?x run wait)
-- (Play)
2024-04-14 20:33:42 -04:00
<> (ready) (display READ stdin play)
<> (?x run wait) (READ stdin play)
2024-04-11 20:20:35 -04:00
<> (?x victory) ((?x wins!\n) put-str)
2024-04-11 20:01:48 -04:00
-- (Interface)
2024-04-12 11:54:07 -04:00
((Input a move, like "X 0 1":\n) put-str)
2024-05-10 00:01:55 -04:00
((- - -) (- - -) (- - -)) ready