fork download
  1. BlockClosure extend [ valueWithExit [ self value: [^self] ] ]
  2.  
  3. Integer extend [
  4. << x [ ^ self bitShift: x ]
  5. >> x [ ^ self bitShift: x negated ]
  6. ]
  7.  
  8. | readline player board pattern |
  9.  
  10. readline := [
  11. | ax a |
  12. ax := stdin nextLine. ax displayNl.
  13. a := 0.
  14. (ax ~= nil and: [ax size = 1]) ifTrue: [a := '123' indexOf: ax first].
  15. a
  16. ].
  17.  
  18. player := 0.
  19. board := 0.
  20. pattern := #(86016 1344 21 66576 16644 4161 65793 4368).
  21.  
  22. [:exit | [((board radix: 2) count: [:x | x = $1]) < 9] whileTrue: [
  23. | pnt point |
  24. ('[', player printString, ' turn]') displayNl.
  25.  
  26. 8 to: 0 by: -1 do: [:i |
  27. ('.ox' at: ((board >> (i * 2)) bitAnd: 2r11) + 1) display. "2r00 = $. / 2r01 = $o / 2r11 = $x"
  28. i \\ 3 = 0 ifTrue: ['' displayNl].
  29. ].
  30.  
  31. pnt := 0 @ 0.
  32. [pnt x < 1] whileTrue: ['x?' display. pnt := readline value @ pnt y].
  33. [pnt y < 1] whileTrue: ['y?' display. pnt := pnt x @ readline value].
  34.  
  35. point := (2r1 << (6 * (3 - pnt y)) << ((3 - pnt x) * 2)) << player.
  36. ((board bitAnd: point) = 0 and: [(board >> (1 - player) bitAnd: point >> player) = 0]) ifTrue: [
  37. board := board bitOr: point.
  38. (pattern findFirst: [:x | (x bitAnd: (board >> player)) = x]) ~= 0 ifTrue: [('', player printString, ' won!') displayNl. exit value].
  39. player := player bitXor: 1
  40. ]
  41. ]] valueWithExit.
  42.  
  43. 'game end' displayNl
  44.  
Success #stdin #stdout 0s 170048KB
stdin
1
1
2
2
3
3
2
1
3
1
2
3
stdout
[0 turn]
...
...
...
x?1
y?1
[1 turn]
o..
...
...
x?2
y?2
[0 turn]
o..
.x.
...
x?3
y?3
[1 turn]
o..
.x.
..o
x?2
y?1
[0 turn]
ox.
.x.
..o
x?3
y?1
[1 turn]
oxo
.x.
..o
x?2
y?3
1 won!
game end