Advertisement
leo3065

LINEAR MAMORY UNIT

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