Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Placing the pieces for White and Black for a chess game?

Asked by
SuperPuiu 497 Moderation Voter
2 years ago

G'day ScirptingHelpers!

Today I started working on a small chess AI. I have some ideas on it, so this isn't the question. I got stuck on the most basic part of the game: the board. Also the board is a frame.

I managed to place all the white pawns, rooks and other, but I don't think it is the most efficient way to do that.

There's my code so far:

local Nr = 0

local Images = {["King"] = "rbxassetid://5167408759", ["Rook"] = "rbxassetid://5167405525", ["Pawn"] = "rbxassetid://9067950310", ["Rook2"] = "rbxassetid://5167389475", ["King2"] = "rbxassetid://5167417298", ["Bishop"] = "rbxassetid://5167407683", ["Bishop2"] = "rbxassetid://5167391404", ["Knight"] = "rbxassetid://5167412180", ["Kinght2"] = "rbxassetid://5167419521", ["Pawn2"] = "rbxassetid://5167319726", ["Queen"] = "rbxassetid://5167410573", ["Queen2"] = "rbxassetid://5167418573"}

function make_checkerboard()

local d = 4 
for i=0,7,1 do
        for j=0,7,1 do
            Nr += 1
            local p = Instance.new("ImageButton", script.Parent.Board)
            p.Name = Nr
            p.BackgroundColor3 = Color3.new(0,0,0)
            if Nr > 8 and Nr < 17 then
                p.Image = Images["Pawn"]
                local FirstUse = Instance.new("BoolValue", p)
                FirstUse.Value = true
            elseif Nr == 4 then
                p.Image = Images["King"]
            elseif Nr == 5 then
                -- p.Text = "Queen"
            elseif Nr == 1 or Nr == 8  then
                p.Image = Images["Rook"]
            elseif Nr == 2 or Nr == 7 then
                -- p.Text = "Knight"
            elseif Nr == 3 or Nr == 6 then
                p.Image = Images["Bishop"]
            end
            if (i+j)%2==0 then
            p.BackgroundColor3 = Color3.new(1,1,1)
        end             
    end             
end

end

make_checkerboard()

Bonus question: How would movement for a piece work? For pawn I was thinking about calculating the front square. Thank you!

Answer this question