Skip to content

Instantly share code, notes, and snippets.

@danielcristofani
Last active December 3, 2020 13:50
Show Gist options
  • Save danielcristofani/6513ac24d6b5855dc5ed2d63c379221b to your computer and use it in GitHub Desktop.
Save danielcristofani/6513ac24d6b5855dc5ed2d63c379221b to your computer and use it in GitHub Desktop.
Tic-tac-toe player
--->--->>>>->->->>>>>-->>>>>>>>>>>>>>>>>>+>>++++++++++[ initialization
<<++[ output board
--<+<<+<<+>>>>[
>[<->>+++>>[-]<<<+[<++>>+>>-<<<--]]+>+++++[>>++++++++++<<-]
>>-.[-]>>+[<<<<+>>+>>-]<<<<<<[>+<-]<<
]++++++++++.[-]>++
]-->>[-->[-]>]<<[ if game not over
>>--[ while stack isn't empty
-[
-[ fn 0: get move from user
-----[>+>+++++++<<+]-->>-.----->,[<->-]<[[<]+[->>]<-]<[<<,[-]]>>>>
]>
]<[ fn 1: initial assessment of position for win or draw
>-[+<+++]+<+++[+[---->]+<<<<<<[>>]<[-]]
>[<+[---->]++[<]<[>]>[[>]+>+++++++++<<-[<]]]>[>>>>]
]<[ fn 2: check different moves to evaluate nonterminal position
-[[>+>+<<-]>[<+>-]++>+>>]<[<<++[-->>[-]]>[[-]>[<<+>>-]>]]
]<[ fn 3: check if move is blocked (nonempty space)
[[<<]-[>>]<+<-]>[-<+]<<[<<]-<[>[+>>]>[>]>[-]]
>[[+>>]<-->>[>]+>>>]
]<[ fn 4: return value to previous 2
-[
--[+<<<<--[+>[-]>[<<+>+>-]<<[>>+<<-]]++[>]]
<<[>+>+<<-]>--[<+>-]++>>>
]<[<<<[-]+++>[-]>[<+>>>+<<-]+>>>]
]<[ fn 5: place or withdraw move
+[[<]<<[<<]-<->>+>[>>]>[>]<-]<[<]<<+<++[[>+<-]++<[<<->>+]<++]<
b m t l \ c r /
<<<<<< +> > >+> > >+[
<<< ->+>+>+[
<<<<<<< +>->+> > >->->+[
<<<<< ->+>+> >+>+[
<<<< ->->+>->+[
<<<<<<<<+>-> >+> > >->+>+[
<<<<< -> >+> >->+[
<<<< +>->+> >+]]]]]]]
+++[[>+<-]<+++]--->>[[<->-]<+++>>]++[[<->-]>>]>[>]
]<
]
]<
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment