Advertisement
HugoBDesigner

Bishop movement thing

Dec 29th, 2014
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.32 KB | None | 0 0
  1. local dir1 = math.min(bishop.x, bishop.y)
  2. local skip = false
  3.  
  4. for i = 1, dir1 do
  5.     if skip then
  6.         break
  7.         --either break or keep returning false...
  8.     end
  9.    
  10.     local x = bishop.x-i+1
  11.     local y = bishop.y-i+1
  12.    
  13.     if x == bishop.x and y == bishop.y then
  14.         --return true, since it's the original position
  15.     elseif grid[x][y] == false then
  16.         --return true, since it's an empty slot
  17.     elseif grid[x][y] == piece on the same side then
  18.         --return false, for obvious reasons
  19.     elseif grid[x][y] == piece of opposite side then
  20.         skip = true
  21.         --return true, since you can move, but set skip,
  22.         --so no further movements can be done
  23.     end
  24. end
  25.  
  26. --dir1 would be moving top-left
  27.  
  28.  
  29. local dir2 = math.min(8-bishop.x, 8-bishop.y)
  30.  
  31. for i = 1, dir2 do
  32.     local x = bishop.x+i-1
  33.     local y = bishop.y+i-1
  34.    
  35.     --do same stuff, but you'll need to reset the skip variable
  36. end
  37.  
  38. --dir2 is moving down-right
  39.  
  40.  
  41. local dir3 = math.min(bishop.y, 8-bishop.x)
  42.  
  43. for i = 1, dir3 do
  44.     local x = bishop.x+i-1
  45.     local y = bishop.y-i+1
  46.    
  47.     --do same stuff, but you'll need to reset the skip variable
  48. end
  49.  
  50. --dir3 is moving top-right
  51.  
  52.  
  53. local dir4 = math.min(bishop.x, 8-bishop.y)
  54.  
  55. for i = 1, dir4 do
  56.     local x = bishop.x-i+1
  57.     local y = bishop.y+i-1
  58.    
  59.     --do same stuff, but you'll need to reset the skip variable
  60. end
  61.  
  62. --dir4 is moving bottom-left
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement