Script for Chess
Intro
The script below creates a chessboard and all the chess pieces using Unicode.
Here is the link: https://www.geogebra.org/m/rxqjvedd
Inspired from this post in Reddit:
https://www.reddit.com/r/geogebra/comments/1hqeef6/i_made_a_chessboard_without_image/
Script Setup: Version 1
#-- Unicode Chess symbols --#
# https://www.alt-codes.net/chess-symbols.php
Lw = Sequence(k, k, 9812, 9817)
Lb = Sequence(k, k, 9818, 9823)
L6 = 1...6
Execute(Zip("w"+i+" = UnicodeToLetter("+j+")", i, L6, j, Lw))
Execute(Zip("b"+i+" = UnicodeToLetter("+j+")", i, L6, j, Lb))
#-- Board --#
Lk = Sequence(k, k, 2, 17, 2)
Lp = Zip(Zip((i, j), i, Lk), j, Lk)
LVector = Zip(Zip(Vector((i, j)), i, Lk), j, Lk)
L8 = 1...8
# Black squares
LP1 = RemoveUndefined(Flatten(Zip(Zip(If(Mod(i, 2) == 0, Vector(Element(LVector, i, 2*j)), Vector(Element(LVector, i, 2*j-1))), i, L8), j, L8)))
# White squares
LP2 = RemoveUndefined(Flatten(Zip(Zip(If(Mod(i, 2) == 0, Vector(Element(LVector, i, 2*j - 1)), Vector(Element(LVector, i, 2*j))), i, L8), j, L8)))
L32 = 1...Length(LP1)
mainPoly = Polygon((-1, -1), (1, -1), 4)
Execute(Zip("sb"+k+" = Translate(mainPoly, "+v+")", k, L32, v, LP1))
Execute(Zip("sw"+k+" = Translate(mainPoly, "+v+")", k, L32, v, LP2))
# https://www.geogebra.org/m/ggxj5scb#material/fugwthpd
colWhite = "White"
colGreen = "ForestGreen"
Execute(Zip("SetColor(sb"+k+", colGreen)", k, L32))
Execute(Zip("SetFilling(sb"+k+", 1)", k, L32))
Execute(Zip("SetColor(sw"+k+", colWhite)", k, L32))
Execute(Zip("SetFilling(sw"+k+", 1)", k, L32))
#-- Set position of pieces --#
# Blacks
# Pawns
val = 2
xP = 0.75
yP = 0.65
scaleB = "\scalebox{"+val+"}" + b6
Execute(Zip("B0"+k+" = scaleB", k, L8))
Execute(Zip("SetCoords( B0"+k+", x(LVector(2, "+k+")) - xP, y(LVector(2, "+k+")) + yP )", k, L8))
# Everything else
B11 = "\scalebox{"+val+"}" + b3
B12 = "\scalebox{"+val+"}" + b5
B13 = "\scalebox{"+val+"}" + b4
B14 = "\scalebox{"+val+"}" + b1
B15 = "\scalebox{"+val+"}" + b2
B16 = "\scalebox{"+val+"}" + b4
B17 = "\scalebox{"+val+"}" + b5
B18 = "\scalebox{"+val+"}" + b3
Execute(Zip("SetCoords( B1"+k+", x(LVector(1, "+k+")) - xP, y(LVector(1, "+k+")) + yP )", k, L8))
# Whites
# Pawns
scaleW = "\scalebox{"+val+"}" + w6
Execute(Zip("W0"+k+" = scaleW", k, L8))
Execute(Zip("SetCoords( W0"+k+", x(LVector(7, "+k+")) - xP, y(LVector(7, "+k+")) + yP )", k, L8))
# Everything else
W11 = "\scalebox{"+val+"}" + w3
W12 = "\scalebox{"+val+"}" + w5
W13 = "\scalebox{"+val+"}" + w4
W14 = "\scalebox{"+val+"}" + w1
W15 = "\scalebox{"+val+"}" + w2
W16 = "\scalebox{"+val+"}" + w4
W17 = "\scalebox{"+val+"}" + w5
W18 = "\scalebox{"+val+"}" + w3
Execute(Zip("SetCoords( W1"+k+", x(LVector(8, "+k+")) - xP, y(LVector(8, "+k+")) + yP )", k, L8))
# -- IMPORTANT -- #
# After creating the chess pieces you must open
# its properties and select the Text Tab to
# activate the LaTeX box. I did this manually.
# I don't know if there is an easier way. :)
#-- Extra Settings --#
SetBackgroundColor("Black")
ShowAxes(false)
ShowGrid(false)
Script Setup: Version 2 Improved
#-- Unicode Chess symbols --#
# https://www.alt-codes.net/chess-symbols.php
Lw = Sequence(k, k, 9812, 9817)
Lb = Sequence(k, k, 9818, 9823)
L6 = 1...6
Execute(Zip("w"+i+" = UnicodeToLetter("+j+")", i, L6, j, Lw))
Execute(Zip("b"+i+" = UnicodeToLetter("+j+")", i, L6, j, Lb))
#-- Board --#
Lk = Sequence(k, k, 2, 17, 2)
Lp = Zip(Zip((i, j), i, Lk), j, Lk)
LVector = Zip(Zip(Vector((i, j)), i, Lk), j, Lk)
L8 = 1...8
# Black squares
LP1 = RemoveUndefined(Flatten(Zip(Zip(If(Mod(i, 2) == 0, Vector(Element(LVector, i, 2*j)), Vector(Element(LVector, i, 2*j-1))), i, L8), j, L8)))
# White squares
LP2 = RemoveUndefined(Flatten(Zip(Zip(If(Mod(i, 2) == 0, Vector(Element(LVector, i, 2*j - 1)), Vector(Element(LVector, i, 2*j))), i, L8), j, L8)))
L32 = 1...Length(LP1)
mainPoly = Polygon((-1, -1), (1, -1), 4)
Execute(Zip("sb"+k+" = Translate(mainPoly, "+v+")", k, L32, v, LP1))
Execute(Zip("sw"+k+" = Translate(mainPoly, "+v+")", k, L32, v, LP2))
# https://www.geogebra.org/m/ggxj5scb#material/fugwthpd
colWhite = "White"
colGreen = "ForestGreen"
Execute(Zip("SetColor(sb"+k+", colGreen)", k, L32))
Execute(Zip("SetFilling(sb"+k+", 1)", k, L32))
Execute(Zip("SetColor(sw"+k+", colWhite)", k, L32))
Execute(Zip("SetFilling(sw"+k+", 1)", k, L32))
#-- Set position of pieces --#
val = 3
xP = 1.1
yP = -1
#CopyFreeObject( )
Execute(Zip("BB0"+k+" = CopyFreeObject( Lp(2, "+k+") )", k, L8))
Execute(Zip("BB1"+k+" = CopyFreeObject( Lp(1, "+k+") )", k, L8))
# Blacks
# Pawns
scaleB = "\scalebox{"+val+"}" + b6
Execute(Zip("B0"+k+" = Text(scaleB, BB0"+k+" + (xP, yP), true, true, -1 )", k, L8))
# Everything else
Lm = {b3, b5, b4, b1, b2, b4, b5, b3}
LB = Zip("\scalebox{"+val+"}" + b, b, Lm)
Execute(Zip("B1"+k+" = Text(Element(LB, "+k+"), BB1"+k+" + (xP, yP), true, true, -1 )", k, L8))
# White pawns
Execute(Zip("WW0"+k+" = CopyFreeObject( Lp(7, "+k+") )", k, L8))
Execute(Zip("WW1"+k+" = CopyFreeObject( Lp(8, "+k+") )", k, L8))
scaleW = "\scalebox{"+val+"}" + w6
Execute(Zip("W0"+k+" = Text(scaleW, WW0"+k+" + (xP, yP), true, true, -1 )", k, L8))
# Everything else
Ln = {w3, w5, w4, w1, w2, w4, w5, w3}
LW = Zip("\scalebox{"+val+"}" + b, b, Ln)
Execute(Zip("W1"+k+" = Text(Element(LW, "+k+"), WW1"+k+" + (xP, yP), true, true, -1 )", k, L8))
#-- Extra Settings --#
SetBackgroundColor("Black")
ShowAxes(false)
Execute(Zip("SetVisibleInView(w"+k+", 1, false)", k, L6))
Execute(Zip("SetVisibleInView(b"+k+", 1, false)", k, L6))
Lname = {"LVector", "Lp", "LP1", "LP2", "mainPoly", "colWhite", "colGreen", "scaleB", "scaleW", "LB", "LW"}
Execute(Zip("SetVisibleInView("+name+", 1, false)", name, Lname))
Execute(Zip("ShowLabel(BB0"+k+", false)", k, L8))
Execute(Zip("ShowLabel(BB1"+k+", false)", k, L8))
Execute(Zip("ShowLabel(WW0"+k+", false)", k, L8))
Execute(Zip("ShowLabel(WW1"+k+", false)", k, L8))
Execute(Zip("SetPointSize(BB0"+k+", 15)", k, L8))
Execute(Zip("SetPointSize(BB1"+k+", 15)", k, L8))
Execute(Zip("SetPointSize(WW0"+k+", 15)", k, L8))
Execute(Zip("SetPointSize(WW1"+k+", 15)", k, L8))
Execute(Zip("SetPointStyle(BB0"+k+", 2)", k, L8))
Execute(Zip("SetPointStyle(BB1"+k+", 2)", k, L8))
Execute(Zip("SetPointStyle(WW0"+k+", 2)", k, L8))
Execute(Zip("SetPointStyle(WW1"+k+", 2)", k, L8))
Execute(Zip("SetLayer(BB0"+k+", 3)", k, L8))
Execute(Zip("SetLayer(BB1"+k+", 3)", k, L8))
Execute(Zip("SetLayer(WW0"+k+", 3)", k, L8))
Execute(Zip("SetLayer(WW1"+k+", 3)", k, L8))
Execute(Zip("SetLayer(B0"+k+", 5)", k, L8))
Execute(Zip("SetLayer(B1"+k+", 5)", k, L8))
Execute(Zip("SetLayer(W0"+k+", 5)", k, L8))
Execute(Zip("SetLayer(W1"+k+", 5)", k, L8))
Remark
I made a first version in GGB Classic. However, when it is uploaded to the GGB website, the position for each piece changes (don't know why). So, after uploading it to the website, you may need to redefine the position for each piece.
If you like my work, you can support me in Patreon. Thanks! Have fun!