diff --git a/examples/tictactoe.modal b/examples/tictactoe.modal new file mode 100644 index 0000000..6234a9b --- /dev/null +++ b/examples/tictactoe.modal @@ -0,0 +1,44 @@ +-- (Tic Tac Toe) + +<> (-- ?x) () +<> (READ) (?~) + +-- (Print) + +<> (put-str ?:) (?:) +<> (put-row (?0 ?1 ?2)) (put-str ?0 put-str | put-str ?1 put-str | put-str ?2 put-str \n) +<> ((?a ?b ?c) display) (put-row ?a put-row ?b put-row ?c put-str \n (?a ?b ?c)) + +-- (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) +<> (((?0 ?1 ?x) (?2 ?1 ?3) (?x ?4 ?5)) ?x run) (?x victory) + +-- (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) + +<> (ready) (display READ play) +<> (?x run wait) (READ play) +<> (?x victory) (put-str (?x wins!\n)) + +-- (Interface) + +(put-str (Input a move, like "X 0 1":\n)) +((- - -) (- - -) (- - -)) ready