Advertisement
Zemyla

8R8KDOWN - Custom puzzle for TIS-100

Jun 17th, 2015
554
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.37 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 "8R8KDOWN"
  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 { "READ VALUES FROM IN", "WRITE NUM8ER of 8 DIGITS TO OUT" }
  13. end
  14.  
  15. function not8()
  16.         i = math.random(0, 8)
  17.         if i == 8 then
  18.             i = 9
  19.         end
  20.         return i
  21. end
  22.  
  23. -- The function get_streams() should return an array of streams. Each stream is described
  24. -- by an array with exactly four values: a STREAM_* value, a name, a position, and an array
  25. -- of integer values between -999 and 999 inclusive.
  26. --
  27. -- STREAM_INPUT: An input stream containing up to 39 numerical values.
  28. -- STREAM_OUTPUT: An output stream containing up to 39 numerical values.
  29. -- STREAM_IMAGE: An image output stream, containing exactly 30*18 numerical values between 0
  30. --               and 4, representing the full set of "pixels" for the target image.
  31. --
  32. -- NOTE: Arrays in Lua are implemented as tables (dictionaries) with integer keys that start
  33. --       at 1 by convention. The sample code below creates an input array of 39 random values
  34. --       and an output array that doubles all of the input values.
  35. --
  36. -- NOTE: To generate random values you should use math.random(). However, you SHOULD NOT seed
  37. --       the random number generator with a new seed value, as that is how TIS-100 ensures that
  38. --       the first test run is consistent for all users, and thus something that allows for the
  39. --       comparison of cycle scores.
  40. --
  41. -- NOTE: Position values for streams should be between 0 and 3, which correspond to the far
  42. --       left and far right of the TIS-100 segment grid. Input streams will be automatically
  43. --       placed on the top, while output and image streams will be placed on the bottom.
  44. --
  45. function get_streams()
  46.     input = {}
  47.     output = {}
  48.     for i = 1,39 do
  49.                 dl = { not8(), not8(), not8() }
  50.                 ch = math.random(0, 7)
  51.                 if ch >= 6 then
  52.                     dl = { 8, 8, 8 }
  53.                     j = 3
  54.                     if ch == 6 then
  55.                         dl[math.random(1, 3)] = not8()
  56.                         j = 2
  57.                     end
  58.                 else
  59.                     j = 0
  60.                     if ch >= 4 then
  61.                         dl[math.random(1, 3)] = 8
  62.                         j = 1
  63.                     end
  64.                 end
  65.         input[i] = dl[1] * 100 + dl[2] * 10 + dl[3]
  66.         output[i] = j
  67.     end
  68.     return {
  69.         { STREAM_INPUT, "IN", 1, input },
  70.         { STREAM_OUTPUT, "OUT", 2, output },
  71.     }
  72. end
  73.  
  74. -- The function get_layout() should return an array of exactly 12 TILE_* values, which
  75. -- describe the layout and type of tiles found in the puzzle.
  76. --
  77. -- TILE_COMPUTE: A basic execution node (node type T21).
  78. -- TILE_MEMORY: A stack memory node (node type T30).
  79. -- TILE_DAMAGED: A damaged execution node, which acts as an obstacle.
  80. --
  81. function get_layout()
  82.     return {
  83.         TILE_COMPUTE,   TILE_COMPUTE,   TILE_COMPUTE,   TILE_COMPUTE,
  84.         TILE_COMPUTE,   TILE_COMPUTE,   TILE_COMPUTE,   TILE_COMPUTE,
  85.         TILE_COMPUTE,   TILE_COMPUTE,   TILE_COMPUTE,   TILE_COMPUTE,
  86.     }
  87. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement