Guest User

Untitled

a guest
Jun 24th, 2015
551
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.34 KB | None | 0 0
  1. -- The function get_name() should return a single string that is the name of the puzzle.
  2. --
  3. function get_name()
  4. return "TIC TAC TOE"
  5. end
  6.  
  7. -- The function get_description() should return an array of strings, where each string is
  8. -- a line of description for the puzzle. The text you return from get_description() will
  9. -- be automatically formatted and wrapped to fit inside the puzzle information box.
  10. --
  11. function get_description()
  12. return { " 1 | 2 | 3 IN.X/IN.O - MOVES",
  13. "---+---+--- X MOVES FIRST",
  14. " 4 | 5 | 6 0 - GAME ENDED",
  15. "---+---+--- OUT = 1 FOR X WIN",
  16. " 7 | 8 | 9 -1 FOR O WIN",
  17. "BY @ZARAWESOME 0 FOR TIE" }
  18. end
  19.  
  20. -- The function get_streams() should return an array of streams. Each stream is described
  21. -- by an array with exactly four values: a STREAM_* value, a name, a position, and an array
  22. -- of integer values between -999 and 999 inclusive.
  23. --
  24. -- STREAM_INPUT: An input stream containing up to 39 numerical values.
  25. -- STREAM_OUTPUT: An output stream containing up to 39 numerical values.
  26. -- STREAM_IMAGE: An image output stream, containing exactly 30*18 numerical values between 0
  27. -- and 4, representing the full set of "pixels" for the target image.
  28. --
  29. -- NOTE: Arrays in Lua are implemented as tables (dictionaries) with integer keys that start
  30. -- at 1 by convention. The sample code below creates an input array of 39 random values
  31. -- and an output array that doubles all of the input values.
  32. --
  33. -- NOTE: To generate random values you should use math.random(). However, you SHOULD NOT seed
  34. -- the random number generator with a new seed value, as that is how TIS-100 ensures that
  35. -- the first test run is consistent for all users, and thus something that allows for the
  36. -- comparison of cycle scores.
  37. --
  38. -- NOTE: Position values for streams should be between 0 and 3, which correspond to the far
  39. -- left and far right of the TIS-100 segment grid. Input streams will be automatically
  40. -- placed on the top, while output and image streams will be placed on the bottom.
  41. --
  42. function get_streams()
  43. input = {{}, {}}
  44. output = {}
  45. posInput = {1,1}
  46. posOutput = 1
  47. pos = math.random(1,9)
  48. for i = 1,7 do
  49. board = {}
  50. win = false
  51. player = 1
  52. moves = 0
  53. repeat
  54. repeat
  55. pos = math.random(1,9)
  56. until board[pos] == nil
  57. board[pos] = player
  58. input[player][posInput[player]] = pos
  59. posInput[player] = posInput[player] + 1
  60. player = 3 - player
  61. if board[1] == board[2] and board[2] == board[3] and board[1] != nil then
  62. win = 3 - (board[1] * 2)
  63. end
  64. if board[4] == board[5] and board[5] == board[6] and board[4] != nil then
  65. win = 3 - (board[4] * 2)
  66. end
  67. if board[7] == board[8] and board[8] == board[9] and board[7] != nil then
  68. win = 3 - (board[7] * 2)
  69. end
  70. if board[1] == board[5] and board[5] == board[9] and board[1] != nil then
  71. win = 3 - (board[1] * 2)
  72. end
  73. if board[3] == board[5] and board[5] == board[7] and board[3] != nil then
  74. win = 3 - (board[3] * 2)
  75. end
  76. if board[1] == board[4] and board[4] == board[7] and board[1] != nil then
  77. win = 3 - (board[1] * 2)
  78. end
  79. if board[2] == board[5] and board[5] == board[8] and board[2] != nil then
  80. win = 3 - (board[2] * 2)
  81. end
  82. if board[3] == board[6] and board[6] == board[9] and board[3] != nil then
  83. win = 3 - (board[3] * 2)
  84. end
  85. moves = moves + 1
  86. if moves >= 9 then
  87. win = 0
  88. end
  89. until win != false
  90. output[posOutput] = win
  91. posOutput = posOutput + 1
  92. input[1][posInput[1]] = 0
  93. posInput[1] = posInput[1] + 1
  94. input[2][posInput[2]] = 0
  95. posInput[2] = posInput[2] + 1
  96. end
  97. return {
  98. { STREAM_INPUT, "IN.X", 0, input[1] },
  99. { STREAM_INPUT, "IN.O", 2, input[2] },
  100. { STREAM_OUTPUT, "OUT", 1, output }
  101. }
  102. end
  103.  
  104. -- The function get_layout() should return an array of exactly 12 TILE_* values, which
  105. -- describe the layout and type of tiles found in the puzzle.
  106. --
  107. -- TILE_COMPUTE: A basic execution node (node type T21).
  108. -- TILE_MEMORY: A stack memory node (node type T30).
  109. -- TILE_DAMAGED: A damaged execution node, which acts as an obstacle.
  110. --
  111. function get_layout()
  112. return {
  113. TILE_COMPUTE, TILE_COMPUTE, TILE_COMPUTE, TILE_COMPUTE,
  114. TILE_COMPUTE, TILE_COMPUTE, TILE_COMPUTE, TILE_COMPUTE,
  115. TILE_COMPUTE, TILE_COMPUTE, TILE_COMPUTE, TILE_COMPUTE,
  116. }
  117. end
Advertisement
Add Comment
Please, Sign In to add comment