fork download
  1. "プログラミングのお題スレ Part10
  2. >>779"
  3.  
  4. "Squeak/Pharo Smalltalk"
  5.  
  6. | N M empty board rest total rock rockAt disp currRock input pos dirs units check |
  7. N := 15. M := 5.
  8. empty := $. .
  9. rock := 'ox'.
  10. board:= (Array new: N withAll: (String new: N withAll: empty)) deepCopy.
  11.  
  12. rockAt := [:pt | (board at: pt y ifAbsent: #()) at: pt x ifAbsent: empty].
  13.  
  14. Transcript open.
  15. disp := [:msg | Transcript cr; cr; show: board asStringWithCr; cr; show: msg].
  16.  
  17. currRock:= nil.
  18. input := [
  19. | posStr |
  20. disp value: currRock asString, '? '.
  21. [ posStr := UIManager default request: currRock asString, '?'.
  22. (posStr isNil or: [posStr isEmpty]) ifTrue: [^self].
  23. Transcript show: posStr; space.
  24. posStr size = 2
  25. and: [1 asPoint <= (pos := posStr second digitValue @ posStr first digitValue)
  26. and: [pos <= N asPoint
  27. and: [(rockAt value: pos) == empty]]]
  28. ] whileFalse
  29. ].
  30.  
  31. dirs := 0 asPoint eightNeighbors.
  32. units := (dirs first: 4) collect: #r.
  33. check := [
  34. | limits lens |
  35. limits := dirs * 0 + pos.
  36. M-1 timesRepeat: [
  37. limits := dirs with: limits collect: [:dir :head |
  38. (rockAt value: head + dir) == currRock ifTrue: [head + dir] ifFalse: [head]
  39. ]
  40. ].
  41. lens := (((limits last: 4) - (limits first: 4) collect: #r) / units) rounded.
  42. "Transcript cr; show: lens."
  43. lens anySatisfy: [:len | len >= (M-1)].
  44. ].
  45.  
  46. rest := total := N squared.
  47. [rest > 0] whileTrue: [
  48. currRock := rock atWrap: total - rest + 1.
  49. input value.
  50. (board at: pos y) at: pos x put: currRock.
  51. check value ifTrue: [disp value: currRock asString, ' win'. ^self].
  52. rest := rest - 1.
  53. ].
  54.  
  55. disp value: 'draw'
Not running #stdin #stdout 0s 0KB
stdin
ff
ff
fe
ee
fd
dd
fc
cc
fb
bb
stdout
Standard output is empty