Options for simple board game GUI

This is a simple implementation in Makie you could play around with:

chars = ['♛', '♚', '♜', '♜', '♝', '♝', '♞', '♞', fill('♟', 8)...]
pieces = [tuple.(chars, :black); tuple.(chars, :white)]

f = Figure()
ax = Axis(f[1, 1], aspect = 1)
hidedecorations!(ax)
hm = heatmap!(ax, isodd.((1:8) .+ (1:8)'), colormap = [:black, :white])
for int in keys(interactions(ax))
    deactivate_interaction!(ax, int)
end 
mevents = addmouseevents!(ax.scene, hm)

function place_random_piece!(square)
    isempty(pieces) && return
    i = rand(eachindex(pieces))
    (marker, color) = splice!(pieces, i)
    scatter!(ax, square; marker, color,
        strokecolor = color === :white ? :black : :white,
        strokewidth = 1,
        markersize = 0.8, markerspace = :data
    )
    return
end

onmouseleftclick(mevents) do event
    square = round.(Int, event.data)
    place_random_piece!(square)
end

f

14 Likes