Build a GameCreating Chess

Appendix D — Tuning Tables

The numbers that make Chess play the way it does. Change them to remix the game: the game’s Logic reads them from here. Try one change at a time, and run the game after each. If something stops working, put the old number back.

D.1 Data Tables

D.1.1 Position

Where every Piece stands: one row per Square, named a1 to h8, in order a1, b1, … h1, a2, … h8 (so the row index is (rank - 1) x 8 + (file - 1)). file: the File, 1 (a) to 8 (h). fileLetter: the same File as a letter, a to h, as the labels along the Board write it. rank: the Rank, 1 to 8. kind: the Kind of the Piece on the Square (King, Queen, Rook, Bishop, Knight, or Pawn), empty when the Square is empty. side: the Side it belongs to (White or Black), empty when the Square is empty. The rows as written here are the starting position.

Data TablePositionData Structure: Position Entry
IMPORT CSV64 rows, from a file
FIRST ROWS3 of 64, to compare
Row 0a1
file1
fileLettera
rank1
kindRook
sideWhite
Row 1b1
file2
fileLetterb
rank1
kindKnight
sideWhite
Row 2c1
file3
fileLetterc
rank1
kindBishop
sideWhite

D.1.2 Kinds

One row per Kind of Piece, one column per Side. White and Black: the frame of the Piece Set art that shows this Kind for that Side (every Piece Set art keeps the same frame order). The columns are named for the Sides, so the Side of a Piece picks its column. promotionWords: what the Hint message adds when its Move promotes a Pawn to this Kind (empty for the King and the Pawn, which a Pawn never becomes). letter: the letter a Move of this Kind starts with in the Move History (none for a Pawn). promotionMark: what a Move that promotes a Pawn to this Kind ends with (empty for the King and the Pawn).

Data TableKindsData Structure: Kinds Entry
Row 0King
White0
Black6
promotionWords
letterK
promotionMark
Row 1Queen
White1
Black7
promotionWords, promote to queen
letterQ
promotionMark=Q
Row 2Rook
White4
Black10
promotionWords, promote to rook
letterR
promotionMark=R
Row 3Bishop
White2
Black8
promotionWords, promote to bishop
letterB
promotionMark=B
Row 4Knight
White3
Black9
promotionWords, promote to knight
letterN
promotionMark=N
Row 5Pawn
White5
Black11
promotionWords
letter
promotionMark

D.1.3 Sides

One row per Side. forward: the way its Pawns move along the Ranks (1 = up, toward Rank 8; -1 = down). pawnRank: the Rank its Pawns start on. opponent: the other Side. promotionRank: the last Rank for its Pawns, where a Pawn is promoted.

Data TableSidesData Structure: Sides Entry
Row 0White
forward1
pawnRank2
opponentBlack
promotionRank8
Row 1Black
forward-1
pawnRank7
opponentWhite
promotionRank1

D.1.4 Directions

Every way each Kind of Piece moves, one row per direction. kind: the Kind. fileStep and rankStep: one step, in Files and Ranks (a Pawn’s rankStep is turned round for Black by its Side’s forward). steps: how many steps it may take in one Move (7 slides across the Board). firstMoveSteps: the same, for a Piece on its Side’s Pawn Rank (a Pawn’s first Move may be two Squares). canMove: it may step onto an empty Square. canCapture: it may step onto an enemy Piece, taking it. A Piece stops at the first Piece in its way.

Data TableDirectionsData Structure: Directions Entry
IMPORT CSV35 rows, from a file
FIRST ROWS3 of 35, to compare
Row 0King up
kindKing
fileStep0
rankStep1
steps1
firstMoveSteps1
canMoveYes
canCaptureYes
Row 1King up right
kindKing
fileStep1
rankStep1
steps1
firstMoveSteps1
canMoveYes
canCaptureYes
Row 2King right
kindKing
fileStep1
rankStep0
steps1
firstMoveSteps1
canMoveYes
canCaptureYes

D.1.5 Targets

The Squares the selected Piece may move to: one row per Square, a1 to h8, in the same order as the Position table, made by Clear Targets (the table has no rows of its own). reachable: yes when the selected Piece may move there. Find Moves fills it, after Clear Targets has made every Square unreachable.

Data TableTargetsData Structure: Targets Entry

D.1.6 Words

The words the Player reads, one row per message, so they are found and changed in one place. text: the words as shown.

Data TableWordsData Structure: Words Entry
Row 0Your Move
textYour move
Row 1Check
textCheck
Row 2Promotion
textPromotion: choose a Piece
Row 3Win By Checkmate
textYou win · Checkmate
Row 4Loss By Checkmate
textYou lose · Checkmate
Row 5Draw By Stalemate
textDraw · Stalemate
Row 6Draw By Insufficient Material
textDraw · Insufficient material
Row 7Draw By Fifty Move Rule
textDraw · Fifty-move rule
Row 8Draw By Threefold Repetition
textDraw · Threefold repetition
Row 9Thinking
textThinking…
Row 10Disconnected
textOpponent disconnected
Row 11Finding Hint
textFinding a hint…
Row 12Hint Not Found
textA hint could not be found.
Row 13Loss By Resignation
textYou lose · Resignation
Row 14Capture Mark
textx
Row 15Check Mark
text+
Row 16Checkmate Mark
text#

D.1.7 Castling

The four castlings, one row per Side and side of the Board. kingFrom and kingTo: where the King starts and lands (it moves two Squares toward the Rook). rookFrom and rookTo: where the Rook starts and lands (on the Square the King crosses). rookPasses: the Square next to the Rook’s, which the Rook crosses (on the King’s side it is also where the King lands). isAllowed: yes while neither the King nor this Rook has moved and the Rook has not been taken; a new game starts with every castling allowed. notation: how the Move History writes this castling (O-O on the King’s side, O-O-O on the Queen’s).

Data TableCastlingData Structure: Castling Entry
Row 0White Kingside
kingFrome1
kingTog1
rookFromh1
rookTof1
rookPassesg1
isAllowedYes
notationO-O
Row 1White Queenside
kingFrome1
kingToc1
rookFroma1
rookTod1
rookPassesb1
isAllowedYes
notationO-O-O
Row 2Black Kingside
kingFrome8
kingTog8
rookFromh8
rookTof8
rookPassesg8
isAllowedYes
notationO-O
Row 3Black Queenside
kingFrome8
kingToc8
rookFroma8
rookTod8
rookPassesb8
isAllowedYes
notationO-O-O

D.1.8 Position History

Every position since the last Capture or Pawn Move, recorded at the start of each Turn, so the game can tell when one comes for the third time. Each position takes 64 rows, one per Square in the order of the Position table (a1, b1, … h8): the first position is rows 0 to 63, the next 64 to 127, and so on. Each row is named by its number. kind and side: the Piece on that Square (empty when none). castlingsAllowed: how many castlings were still allowed then (a castling once ended never comes back, so the same number means the same castlings). The table starts empty.

Data TablePosition HistoryData Structure: Position History Entry

D.1.9 Strengths

How the Computer plays at each Strength, one row per Strength button of the New Game panel (the row name is the button’s word). skillLevel: Stockfish’s Skill Level, from 0 (weakest) to 20 (strongest). thinkingSeconds: how long Stockfish thinks about each Move, in seconds.

Data TableStrengthsData Structure: Strengths Entry
Row 0Gentle
skillLevel0
thinkingSeconds0.2
Row 1Casual
skillLevel4
thinkingSeconds0.35
Row 2Club
skillLevel8
thinkingSeconds0.5
Row 3Strong
skillLevel14
thinkingSeconds0.8
Row 4Expert
skillLevel20
thinkingSeconds1.2

D.1.10 Chosen Moves

The Moves the Stockfish Bridge found, each written just before the bridge says so. Row Computer: the Computer’s Move (“computerMoveChosen”). Row Hint: the Move suggested to the Player (“hintChosen”); it stays while the Hint is shown, and is empty when there is none. from and to: the Squares the Piece moves from and to (a1 to h8). landingKind: the Kind of the Piece once it has landed: its own Kind, or, when the Move promotes a Pawn, the Kind the Pawn becomes (Queen, Rook, Bishop, or Knight).

Data TableChosen MovesData Structure: Chosen Moves Entry
Row 0Computer
from
to
landingKind
Row 1Hint
from
to
landingKind

D.1.11 Move History

Every Move of the game so far, in the order they were made, one row per Move (the first Move is row 0; each row is named by its number). from and to: the Squares the Piece moved from and to (a1 to h8). landingKind: the Kind of the Piece once it had landed: its own Kind, or, for a Promotion, the Kind the Pawn became. The number of rows is the number of Moves made. Undo takes rows off the end and plays the rest again. The table starts empty. The other columns are the Move’s name as chess players write it (standard algebraic notation), in the order it is read: letter, the Kind’s letter (none for a Pawn), or O-O or O-O-O for castling; fromFile and fromRank, the File and Rank it came from, written only when needed to tell two Pieces apart (and the File of a Pawn that captures); capture, x for a Capture; square, the Square it went to (none for castling); promotion, what a Pawn became (=Q); checkMark, + for Check or # for Checkmate. The Move’s number is not kept: rows 0 and 1 are Move 1 (White’s and Black’s), rows 2 and 3 Move 2, and so on.

Data TableMove HistoryData Structure: Move History Entry

D.1.12 Slides

Where the Pieces of the Computer’s Move slide, written just before they slide (Plan The Slide) and read by the Moving Pieces (each placement follows one row) and by the Pieces, which show nothing on a Square a slide starts from. Row Piece: the Piece that moves. Row Rook: the Rook, when the Move is a castling (empty otherwise). from and to: the Squares it slides from and to (a1 to h8).

Data TableSlidesData Structure: Slides Entry
Row 0Piece
from
to
Row 1Rook
from
to

D.1.13 Hint Strength

How hard Stockfish searches for a Hint, whatever Strength the Computer plays at (the Stockfish Bridge reads it). One row, Hint. skillLevel: Stockfish’s Skill Level, from 0 (weakest) to 20 (strongest). thinkingSeconds: how long Stockfish thinks, in seconds.

Data TableHint StrengthData Structure: Hint Strength Entry
Row 0Hint
skillLevel20
thinkingSeconds0.5

D.1.14 Threats

What Threats mode marks on each Square: one row per Square, a1 to h8, in the same order as the Position table. isAttacked: yes when the Piece standing there can be legally captured by an enemy Piece (the King: when it is in Check). isUnprotected: yes when it is attacked, is not a King, and no Capture of it can be answered by a legal recapture. pinnedBy: the Square of the enemy Queen, Rook, or Bishop that pins the Piece standing there to its own King; empty when it is not pinned. Find Threats fills it while Threats mode is on; otherwise every row is no and empty.

Data TableThreatsData Structure: Threats Entry

D.1.15 Arrows

The arrows Threats mode shows for the selected or inspected Piece, one row per arrow (each row is named by its number). from and to: the Squares the arrow runs from and to (a1 to h8). color: the arrow’s color, with how strongly it shows (#rrggbbaa). Find Arrows fills it after every change; Draw Threat Lines draws it. Empty when no arrow is shown.

Data TableArrowsData Structure: Arrows Entry

D.1.16 Board Finishes

The four looks of the Board the Player can choose (Settings). One row per Board Finish, named by the word the Player reads. board: the Board art. labelOnLight: the color of a Rank number or File letter on a light Square. labelOnDark: the color of one on a dark Square.

Data TableBoard FinishesData Structure: Board Finishes Entry
Row 0Walnut
boardWalnut Board
labelOnLight#503a2b
labelOnDark#dfc69b
Row 1Tournament
boardTournament Board
labelOnLight#314b3e
labelOnDark#e8ead5
Row 2Slate
boardSlate Board
labelOnLight#344756
labelOnDark#dce4e8
Row 3Marble
boardMarble Board
labelOnLight#424840
labelOnDark#eae5db

D.1.17 Piece Sets

The three looks of the Pieces the Player can choose (Settings). One row per Piece Set, named by the words the Player reads. pieces: the Piece Set art, twelve frames in the order of the Kinds table. size: how large the art is drawn, 1 being the size of the Carved walnut art, so that every set’s King is 0.84 of a Square tall.

Data TablePiece SetsData Structure: Piece Sets Entry
Row 0Carved walnut
piecesCarved Walnut Pieces
size1
Row 1Ivory & gold
piecesIvory And Gold Pieces
size0.9591
Row 2Sculpted marble
piecesSculpted Marble Pieces
size0.9535

D.2 Logic Numbers

The numbers and colors each Logic Component keeps in its Shared Variables and Per Instance Variables, with the Starting Value its card gives. A value set on its Object, under Variables in the Properties, or on a placement in the Scene, wins over the value here.

LAY OUT THE BOARD
  squareMeters ............... 3.75
SQUARE MARKS
  selectedColor .............. #f4d273
  selectedAlpha .............. 0.44
  lastMoveColor .............. #e9c44f
  lastMoveAlpha .............. 0.32
  checkColor ................. #cd493f
  checkAlpha ................. 0.66
  hintColor .................. #61a9b8
  hintAlpha .................. 0.35
  attackedColor .............. #d64b46
  attackedAlpha .............. 0.4
  unprotectedAlpha ........... 0.5
  inspectedColor ............. #56a59d
  inspectedAlpha ............. 0.27
LOOK FOR GAME END
  timesSeenForDraw ........... 3
  fiftyMoveCountForDraw ...... 100
PLACE ON BOARD
  squareMeters ............... 3.75
  boardLeft .................. 0
  boardBottom ................ 4.375
SHOW OPTION
  chosenColor ................ #a9c79b
  plainColor ................. #e2d5b4
MAKE COMPUTER MOVE
  spareSeconds ............... 20
SLIDE PIECE
  slideSeconds ............... 0.36
  squareMeters ............... 3.75
  boardLeft .................. 0
  boardBottom ................ 4.375
GIVE A HINT
  spareSeconds ............... 20
SHOW HINT MESSAGE
  showSeconds ................ 4
DRAW THREAT LINES
  pinColor ................... #c68a20cc
  pinLineWidth ............... 0.03
  pinDashLength .............. 0.12
  pinDashSpacing ............. 0.22
  pinGapAtStart .............. 0.3
  pinGapAtKing ............... 0.25
  arrowToEnemyColor .......... #b6403ab0
  arrowToOtherColor .......... #257f7690
  arrowFromAttackerColor ..... #b6403acc
  arrowWidth ................. 0.035
  arrowGapAtStart ............ 0.22
  arrowGapAtEnd .............. 0.27
  arrowHeadLength ............ 0.11
  arrowHeadSpread ............ 0.6
  squareMeters ............... 3.75
  boardLeft .................. 0
  boardBottom ................ 4.375
  pixelsPerMeter ............. 32
SHOW THREATS BUTTON PRESSED
  pressedColor ............... #e3eadc
  pressedWordColor ........... #244739
  plainColor ................. #e2d5b4
  plainWordColor ............. #503a2b
SHOW RECORDED MOVE
  line ....................... 0
SHOW PAGE BUTTON
  direction .................. 1
KEYBOARD FOCUS
  squareMeters ............... 3.75
  boardLeft .................. 0
  boardBottom ................ 4.375
  startFile .................. 5
CHOOSE WITH KEYS
  firstPieceX ................ -195
  pieceY ..................... 66
  pieceSpacing ............... 130