Advertisement
Tooster

Untitled

Feb 28th, 2018
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.27 KB | None | 0 0
  1. -- Auto-generated code below aims at helping you parse
  2. -- the standard input according to the problem statement.
  3. -- ---
  4. -- Hint: You can use the debug stream to print initialTX and initialTY, if Thor seems not follow your orders.
  5.  
  6. -- lightX: the X position of the light of power
  7. -- lightY: the Y position of the light of power
  8. -- initialTX: Thor's starting X position
  9. -- initialTY: Thor's starting Y position
  10. next_token = string.gmatch(io.read(), "[^%s]+")
  11. lightX = tonumber(next_token())
  12. lightY = tonumber(next_token())
  13. thorX = tonumber(next_token())
  14. thorY = tonumber(next_token())
  15. moves = {
  16.             [-1] = {[-1]='NW', [0]='N', [1]='NE'},
  17.             [0]  = {[-1]='W', [0]='x', [1]='E'},
  18.             [1]  = {[-1]='SW', [0]='S', [1]='SE'}
  19.         }
  20. -- game loop
  21. while true do
  22.     remainingTurns = tonumber(io.read()) -- The remaining amount of turns Thor can move. Do not remove this line.
  23.    
  24.     -- Write an action using print()
  25.     -- To debug: io.stderr:write("Debug message\n")
  26.     dx = lightX - thorX
  27.     dy = lightY - thorY
  28.     if dx ~= 0 then dx = dx / math.abs(dx) end
  29.     if dy ~= 0 then dy = dy / math.abs(dy) end
  30.     thorX = thorX + dx
  31.     thorY = thorY + dy
  32.    
  33.  
  34.     -- A single line providing the move to be made: N NE E SE S SW W or NW
  35.    
  36. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement