I just scripted a GetDiagonals function for my chess game (for the bishop), is there anything I should change?
function RoundModule.GetDiagonal(posX, posY, which)
local squares = {}
if which == "rightTop" or which == "all" then
--right top
local rightX = posX
for y = posY, 8 do
rightX = RoundModule.GetNextLetter(rightX)
if rightX == nil then
break
end
table.insert(squares, {X = rightX, Y = y})
end
end
if which == "leftTop" or which == "all" then
--left top
local leftX = posX
for y = posY, 8 do
leftX = RoundModule.GetPreviousLetter(leftX)
if leftX == nil then
break
end
table.insert(squares, {X = leftX, Y = y})
end
end
if which == "rightBottom" or which == "all" then
--right bottom
local rightBottomX = posX
for y = posY, 1 do
rightBottomX = RoundModule.GetNextLetter(rightBottomX)
if rightBottomX == nil then
break
end
table.insert(squares, {X = rightBottomX, Y = y})
end
end
if which == "leftBottom" or which == "all" then
--left bottom
local leftBottomX = posX
for y = posY, 1 do
leftBottomX = RoundModule.GetPreviousLetter(leftBottomX)
if leftBottomX == nil then
break
end
table.insert(squares, {X = leftBottomX, Y = y})
end
end
return squares
end
Thanks!