Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[CLASSES]
- local tPieces=setmetatable({},{__call=function(t,x,y)
- for num,tPiece in pairs(t) do
- if tPiece.x==x and tPiece.y==y then return tPiece,num end
- end
- return {sym=' '}
- end})
- board=function()
- return tPieces
- end
- R=function(x,y,owner)
- owner=owner or false
- return setmetatable({x=x,y=y,col=owner,sym='R',hasMoved=false},{__call=function(t)
- local tOpts={}
- for a=1,t.x-1 do
- if tPieces(t.x-a,t.y).col~=t.col then table.insert(tOpts,{t.x-a,t.y}) end
- if tPieces(t.x-a,t.y).x then break end
- end
- for a=1,8-t.x do
- if tPieces(t.x+a,t.y).col~=t.col then table.insert(tOpts,{t.x+a,t.y}) end
- if tPieces(t.x+a,t.y).x then break end
- end
- for a=1,t.y-1 do
- if tPieces(t.x,t.y-a).col~=t.col then table.insert(tOpts,{t.x,t.y-a}) end
- if tPieces(t.x,t.y-a).x then break end
- end
- for a=1,8-t.y do
- if tPieces(t.x,t.y+a).col~=t.col then table.insert(tOpts,{t.x,t.y+a}) end
- if tPieces(t.x,t.y+a).x then break end
- end
- return tOpts
- end})
- end
- B=function(x,y,owner)
- owner=owner or false
- return setmetatable({x=x,y=y,col=owner,sym='B',hasMoved=false},{__call=function(t)
- local tOpts={}
- for num=1,math.min(t.x,t.y)-1 do
- if tPieces(t.x-num,t.y-num).col~=t.col then table.insert(tOpts,{t.x-num,t.y-num}) end
- if tPieces(t.x-num,t.y-num).x then break end
- end
- for num=1,math.min(8-t.x,8-t.y) do
- if tPieces(t.x+num,t.y+num).col~=t.col then table.insert(tOpts,{t.x+num,t.y+num}) end
- if tPieces(t.x+num,t.y+num).x then break end
- end
- for num=1,math.min(9-t.x,t.y)-1 do
- if tPieces(t.x+num,t.y-num).col~=t.col then table.insert(tOpts,{t.x+num,t.y-num}) end
- if tPieces(t.x+num,t.y-num).x then break end
- end
- for num=1,math.min(t.x,9-t.y)-1 do
- if tPieces(t.x-num,t.y+num).col~=t.col then table.insert(tOpts,{t.x-num,t.y+num}) end
- if tPieces(t.x-num,t.y+num).x then break end
- end
- return tOpts
- end})
- end
- Q=function(x,y,owner)
- owner=owner or false
- return setmetatable({x=x,y=y,col=owner,sym='Q',hasMoved=false},{__call=function(t)
- local tOpts={}
- for a=1,t.x-1 do
- if tPieces(t.x-a,t.y).col~=t.col then table.insert(tOpts,{t.x-a,t.y}) end
- if tPieces(t.x-a,t.y).x then break end
- end
- for a=1,8-t.x do
- if tPieces(t.x+a,t.y).col~=t.col then table.insert(tOpts,{t.x+a,t.y}) end
- if tPieces(t.x+a,t.y).x then break end
- end
- for a=1,t.y-1 do
- if tPieces(t.x,t.y-a).col~=t.col then table.insert(tOpts,{t.x,t.y-a}) end
- if tPieces(t.x,t.y-a).x then break end
- end
- for a=1,8-t.y do
- if tPieces(t.x,t.y+a).col~=t.col then table.insert(tOpts,{t.x,t.y+a}) end
- if tPieces(t.x,t.y+a).x then break end
- end
- for num=1,math.min(t.x,t.y)-1 do
- if tPieces(t.x-num,t.y-num).col~=t.col then table.insert(tOpts,{t.x-num,t.y-num}) end
- if tPieces(t.x-num,t.y-num).x then break end
- end
- for num=1,math.min(8-t.x,8-t.y) do
- if tPieces(t.x+num,t.y+num).col~=t.col then table.insert(tOpts,{t.x+num,t.y+num}) end
- if tPieces(t.x+num,t.y+num).x then break end
- end
- for num=1,math.min(9-t.x,t.y)-1 do
- if tPieces(t.x+num,t.y-num).col~=t.col then table.insert(tOpts,{t.x+num,t.y-num}) end
- if tPieces(t.x+num,t.y-num).x then break end
- end
- for num=1,math.min(t.x,9-t.y)-1 do
- if tPieces(t.x-num,t.y+num).col~=t.col then table.insert(tOpts,{t.x-num,t.y+num}) end
- if tPieces(t.x-num,t.y+num).x then break end
- end
- return tOpts
- end})
- end
- K=function(x,y,owner)
- owner=owner or false
- return setmetatable({x=x,y=y,col=owner,sym='K',hasMoved=false},{__call=function(t)
- local tOpts={}
- for a=-1,1,1 do
- for b=-1,1,1 do
- if not (a==0 and b==0) and t.x+a>0 and t.x+a<=8 and t.y+b>0 and t.y+b<=8 and tPieces(t.x+a,t.y+b).col~=t.col then
- table.insert(tOpts,{t.x+a,t.y+b})
- end
- end
- end
- return tOpts
- end})
- end
- H=function(x,y,owner)
- owner=owner or false
- return setmetatable({x=x,y=y,col=owner,sym='H',hasMoved=false},{__call=function(t)
- local tOpts={}
- for num,to in pairs({{t.x+1,t.y+2},{t.x+1,t.y-2},{t.x-1,t.y+2},{t.x-1,t.y-2},{t.x+2,t.y+1},{t.x+2,t.y-1},{t.x-2,t.y+1},{t.x-2,t.y-1}}) do
- if tPieces(unpack(to)).col~=t.col and to[1]<=8 and to[1]>=1 and to[2]<=8 and to[2]>=1 then
- table.insert(tOpts,to)
- end
- end
- return tOpts
- end})
- end
- P=function(x,y,owner)
- owner=owner or false
- return setmetatable({x=x,y=y,col=owner,sym='P',hasMoved=false},{__call=function(t)
- local tOpts={}
- local target=tPieces(t.x,t.y+(t.col and -1 or 1))
- if not target.x and t.y+(t.col and -1 or 1)>0 and t.y+(t.col and -1 or 1)<=8 then table.insert(tOpts,{t.x,t.y+(t.col and -1 or 1)}) end
- for a=-1,1,2 do
- local target=tPieces(t.x+a,t.y+(t.col and -1 or 1))
- if target.col~=t.col and target.x then table.insert(tOpts,{t.x+a,t.y+(t.col and -1 or 1)}) end
- end
- if not t.hasMoved and not tPieces(t.x,t.y+(t.col and -1 or 1)).x and not tPieces(t.x,t.y+(t.col and -2 or 2)).x and t.y+(t.col and -2 or 2)>0 and t.y+(t.col and -2 or 2)<=8 then table.insert(tOpts,{t.x,t.y+(t.col and -2 or 2)}) end
- return tOpts
- end})
- end
Advertisement
Add Comment
Please, Sign In to add comment