Skip to content

Instantly share code, notes, and snippets.

@toomasv
Last active June 20, 2019 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toomasv/5d3bc8fd4cc7204dc75f333d46348dd3 to your computer and use it in GitHub Desktop.
Save toomasv/5d3bc8fd4cc7204dc75f333d46348dd3 to your computer and use it in GitHub Desktop.
Play chess against yourself
Red [
Title: "Chess"
Author: "Toomas Vooglaid"
Date: 20-Jun-2019
]
glass: 0.0.0.216
chessboard: [origin 0x0 space 0x0]
repeat i 8 [loop 4 [append chessboard pick [[b w][w b]] even? i]]
lay: layout compose/only [
title "Chessboard" backdrop beige
style b: box brown 30x30 font-size 16
on-down [
if not any [empty? face/text " " = face/text][
f/offset: face/offset + 10x10
f/text: copy face/text
clear face/text
f/visible?: yes
]
]
style w: b linen
board: panel 8 (chessboard)
at 0x0 f: box glass 30x30 font-size 16 loose "" hidden
on-up ['local [ofs pos idx]
ofs: round/to face/offset - 10x10 30
pos: ofs / 30
idx: pos/y * 8 + pos/x + 1
pane/:idx/text: copy face/text
clear face/text
face/visible?: no
]
]
pane: board/pane
forall pane [
pane/1/text: form to-char switch/default index? pane [
1 8 [9820]
2 7 [9822]
3 6 [9821]
4 [9819]
5 [9818]
9 10 11 12 13 14 15 16 [9823]
49 50 51 52 53 54 55 56 [9817]
57 64 [9814]
58 63 [9816]
59 62 [9815]
60 [9813]
61 [9812]
][32]
]
view lay
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment