b49p23tivg

tic tac toe on a line

Apr 8th, 2020
281
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Note 'ttt f.'
  2.  
  3. ((4 19$'computer victoriousspoils to the humancat''s game         unfinished         ') {~ (1 i.~ ([: ; 1 1 1 e.L:_1 (8 3$0 3 6 1 4 7 2 5 8 6 4 2 0 1 2 3 4 5 6 7 8 0 4 8) e.L:_1 [: <@I. 'XO' (="0 1) 9&{.) , 'abcdefghiXjX'&(1 -.@:e. =&:(9&{.)) , 'q' = 10&{)`(11&{ = 'XO' #~ [: ; 1 1 1 e.L:_1 (8 3$0 3 6 1 4 7 2 5 8 6 4 2 0 1 2 3 4 5 6 7 8 0 4 8) e.L:_1 [: <@I. 'XO' (="0 1) 9&{.)@.(1 e. [: ; 1 1 1 e.L:_1 (8 3$0 3 6 1 4 7 2 5 8 6 4 2 0 1 2 3 4 5 6 7 8 0 4 8) e.L:_1 [: <@I. 'XO' (="0 1) 9&{.))@:((9}~ ('XO' {~ 'X' = 9&{))@:(([ (0 0 $ 1!:2&2)) ([: (];.0~ (1 1 ,: _2 + $)) [: ": 3 3 $ [: ;/ 9&{.))@:(0&(turn@]`((i. choice)@])`]})^:(-.@:('q' = 10&{)))@:([ (0 0 $ 1!:2&2))@:(10}~ ({~ ?@#)@:('XO' -.~ 9&{.)`([: 32.&(23 b.)&.:(a.&i.) [: {. 'z' ,~ 1!:1@1:)@.(9&{ = 11&{))^:(0 = 4 > 1 i.~ ([: ; 1 1 1 e.L:_1 (8 3$0 3 6 1 4 7 2 5 8 6 4 2 0 1 2 3 4 5 6 7 8 0 4 8) e.L:_1 [: <@I. 'XO' (="0 1) 9&{.) , 'abcdefghiXjX'&(1 -.@:e. =&:(9&{.)) , 'q' = 10&{)^:_)@:((([ (0 0 $ 1!:2&2)) ([: (];.0~ (1 1 ,: _2 + $)) [: ": 3 3 $ [: ;/ 9&{.))@:('abcdefghiXjX' 11}~ 'OX' {~ 'x' = [: 32.&(23 b.)&.:(a.&i.) [: {. 'x' ,~ [: , ":))
  4.  
  5. )
  6.  
  7. ttt=: report@:play@:setup   NB. the game  use:  ttt X   or   ttt O
  8.  
  9.  
  10. NB. define non-verbs
  11.  
  12.  Until=: 2 :'u^:(0=v)^:_'
  13.  If=: ^:
  14.  
  15.  CONFIGURATION=: 'abcdefghiXjX'
  16.  
  17.  'TURN CHOICE HUMAN'=: (i. 3) + CONFIGURATION i.'X'
  18.  
  19.  board=: TURN&{.
  20.  turn=: TURN&{    NB. whose turn it is
  21.  choice=: CHOICE&{    NB. choice
  22.  human=:HUMAN&{   NB. human mark, X or O
  23.  'X O'=: 'xo'
  24.  
  25.  diagonal=: (<0 1)&|:
  26.  WINNER=: ((|:,diagonal@:|.),(,diagonal))i.,~3  NB. indexes of winning combinations
  27.  
  28.  RESPONSE=: ];._2'computer victorious;spoils to the human;cat''s game;unfinished;'
  29.  
  30.  
  31.  
  32. debug=: [ echo
  33.  
  34.  
  35.  
  36. setup=: display@:(CONFIGURATION HUMAN}~ 'OX' {~ 'x' = [: lc [: {. 'x' ,~ [: , ":)
  37.  
  38.   display=: debug ([: trim [: ": 3 3 $ [: ;/ board)
  39.  
  40.     trim=: ];.0~ (1 1 ,: _2 + $)
  41.  
  42.   lc=: (2^5)&bit_or&.:(a.&i.)  NB. sufficient lower case
  43.  
  44.     bit_or=: 2b10111 b.
  45.  
  46. play=: next@:display@:move@:debug@:choose Until done
  47.  
  48.   next=: TURN}~ 'XO'{~'X'=turn
  49.  
  50.   move=: 0&(turn@]`((i. choice)@])`]})If(-.@:quit)
  51.  
  52.   choose=: CHOICE}~ ai`kbd@.(turn = human)
  53.  
  54.     kbd=: ([: lc [: {. 'z' ,~ 1!:1@1:)
  55.  
  56.     ai=: ({~ ?@#)@:('XO'-.~board)
  57.  
  58.  
  59.   done=: 4 > outcome
  60.  
  61.     outcome=: 1 i.~ victor , cats , quit
  62.  
  63.       victor=: [: ; 1 1 1 e.L:_1 WINNER e.L:_1 [: <@I. 'XO' ="0 1 board
  64.  
  65.       cats=: CONFIGURATION&(1 -.@:e. =&:board)
  66.  
  67.       quit=: 'q' = choice
  68.  
  69.  
  70. report=: RESPONSE {~ outcome`(human = 'XO' #~ victor)@.(1 e.victor)
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×