- Learn
- Build a Game
- Chess
- Appendices
- A Logic Reference
Appendix A — Logic Reference
Every Logic Component and Function in Chess, as it is in the finished game. Each entry stands on its own: read what it does, see what it needs, and build it from its card into your own game. A card’s Shared Variables and Per Instance Variables are the values you can change. A Shared Variable holds one value for the whole Object, under Variables in its Properties. A Per Instance Variable holds one for each placement in the Scene.
A.1 Lay Out The Board
Built in Chapter 1, The Board and the Pieces.
Makes the Objects that show each Square of the Board when the Scene starts: for every row of the Position table (one Square, a1 to h8), a Piece Object, a Square, a Move Mark, a Threat Mark and a Pin Mark are made on that Square (Square Position), and each is given the Square's name (its Square Info); a Square in the left or right column also gets a Rank Label, and one in the bottom or top row a File Label (turned over, the h-File is on the left and Rank 8 at the bottom). Then it says "boardLaidOut". pieceObject, squareObject, moveMarkObject, threatMarkObject, pinMarkObject: the Objects made on each Square; rankLabelObject, fileLabelObject: the labels. squareMeters: how wide one Square is.
Any Objectself.layOutTheBoardData- Name
boardBottom- Value
0
- Name
boardLeft- Value
0
- Variable
boardLeft- Value
self.transform.position.x - 4 * @self.squareMeters
- Variable
boardBottom- Value
self.transform.position.y - 4 * @self.squareMeters
dataCount('Position')times- Component Value
self.layOutTheBoardData.squareName- Value
dataRow('Position', local.index)
- Action Name
spot- square
self.layOutTheBoardData.squareName- isFlipped
No- squareMeters
@self.squareMeters- boardLeft
boardLeft- boardBottom
boardBottom
- Object to Create
@self.pieceObject- X
spot.x- Y
spot.y- Created As
piece
- Variable
piece.name- Value
self.layOutTheBoardData.squareName
- Object to Create
@self.squareObject- X
spot.x- Y
spot.y- Created As
square
- Variable
square.name- Value
self.layOutTheBoardData.squareName
- Object to Create
@self.moveMarkObject- X
spot.x- Y
spot.y- Created As
moveMark
- Variable
moveMark.name- Value
self.layOutTheBoardData.squareName
- Object to Create
@self.threatMarkObject- X
spot.x- Y
spot.y- Created As
threatMark
- Variable
threatMark.name- Value
self.layOutTheBoardData.squareName
- Object to Create
@self.pinMarkObject- X
spot.x- Y
spot.y- Created As
pinMark
- Variable
pinMark.name- Value
self.layOutTheBoardData.squareName
data('Position', self.layOutTheBoardData.squareName, 'file') == 1 || data('Position', self.layOutTheBoardData.squareName, 'file') == 8- Object to Create
@self.rankLabelObject- X
spot.x- Y
spot.y- Created As
rankLabel
- Variable
rankLabel.name- Value
self.layOutTheBoardData.squareName
data('Position', self.layOutTheBoardData.squareName, 'rank') == 1 || data('Position', self.layOutTheBoardData.squareName, 'rank') == 8- Object to Create
@self.fileLabelObject- X
spot.x- Y
spot.y- Created As
fileLabel
- Variable
fileLabel.name- Value
self.layOutTheBoardData.squareName
- Custom Event
boardLaidOut
A.2 Show Label
Built in Chapter 1, The Board and the Pieces.
Writes the Rank number or the File letter of the Square this label stands on (its Square Info), read from the Position table: shows names the column (rank, or fileLetter). Its color follows the Board Finish chosen (Settings, on the Game Rules, sends "lookChanged"): the Board Finishes table gives one color for a label on a light Square and one for a label on a dark Square (a Square is dark when its File and Rank add up to an even number, as a1). It shows only while its Square is drawn on the edge of the Board where labels go, the left column or the bottom row, whichever way round the Board is drawn (Flip Board, on the Game Rules, its Other, sends "boardFlipped"). edge: the Position table's column that counts from that edge, file for a Rank Label (the left column) and rank for a File Label (the bottom row).
Any Objectself.squareInfoText / UI- Component Value
self.text.text- Value
data('Position', self.squareInfo.name, @self.shows)
- Name
edgeLine- Value
0
- Variable
edgeLine- Value
data('Position', self.squareInfo.name, @self.edge)
other.boardState.isFlipped == true- Variable
edgeLine- Value
9 - edgeLine
edgeLine == 1- Visible
Yes
- Visible
No
- Type
Text- Name
finish
- Name
squareShade- Value
0
- Name
rank- Value
0
- Name
file- Value
0
- Variable
finish- Value
other.boardState.boardFinish
- Variable
file- Value
data('Position', self.squareInfo.name, 'file')
- Variable
rank- Value
data('Position', self.squareInfo.name, 'rank')
- Variable
squareShade- Value
(file + rank) % 2
squareShade == 1- Component Value
self.text.color- Value
data('Board Finishes', finish, 'labelOnLight')
- Component Value
self.text.color- Value
data('Board Finishes', finish, 'labelOnDark')
A.3 Show Piece
Built in Chapter 1, The Board and the Pieces.
Shows the Piece that stands on this Piece Object's Square: once the Board is laid out (Lay Out The Board sends "boardLaidOut"), and again after every Move (the Game Rules send "positionChanged"). While the Computer's Move slides ("slideStarted"), a Piece on a Square a slide starts from (the Slides table) shows nothing, because a Moving Piece carries it. It shows the Piece in the Piece Set chosen, again whenever the choice changes (Settings sends "lookChanged").
Any Objectself.squareInfo- piece
self
- piece
self
dataFind('Slides', 'from', self.squareInfo.name) != (-1)- Alpha
0
- piece
self- pieceSet
other.boardState.pieceSet
- piece
self
A.4 Square Position (Function)
Built in Chapter 1, The Board and the Pieces.
Answers where the center of a Square is in the world, in meters, for the Board as it is drawn. square: the Square's name (a1 to h8). isFlipped: whether the Board is drawn turned over (Black at the bottom). squareMeters: how wide one Square is. boardLeft and boardBottom: where the Board's bottom-left corner is in the world. It returns x and y: the Square's center.
- Name
file- Value
0
- Name
rank- Value
0
- Name
x- Value
0
- Name
y- Value
0
- Variable
file- Value
data('Position', square, 'file')
- Variable
rank- Value
data('Position', square, 'rank')
isFlipped == true- Variable
file- Value
9 - file
- Variable
rank- Value
9 - rank
- Variable
x- Value
boardLeft + (file - 0.5) * squareMeters
- Variable
y- Value
boardBottom + (rank - 0.5) * squareMeters
- x
x- y
y
A.5 Clear Targets (Function)
Built in Chapter 2, Select and Move.
Makes every Square unreachable: the Targets table is emptied, then gets one row for each Square of the Position table, a1 to h8 in the same order, with reachable no (the column's default). The Targets table has no rows of its own; Clear Targets makes them, each time it is used.
- Type
Text- Name
square
- Table
Targets
dataCount('Position')times- Variable
square- Value
dataRow('Position', local.index)
- Action Name
addedRow- Table
Targets- Row
square
A.6 Find Moves (Function)
Built in Chapter 2, Select and Move.
Finds every Square the Piece on one Square may move to (by how its Kind moves; Check and the special Moves come later) and marks them in the Targets table, clearing the marks of any Piece looked at before. from: the Piece's Square (a1 to h8).
- Type
Text- Name
kind
- Variable
kind- Value
data('Position', from, 'kind')
dataCount('Directions')timesdata('Directions', local.index, 'kind') == kind- from
from- direction
local.index
A.7 Follow Direction (Function)
Built in Chapter 2, Select and Move.
Follows one direction a Piece moves in, Square by Square, marking each Square it may go to in the Targets table, until it leaves the Board, meets a Piece, or has taken as many steps as the Directions table allows. from: the Piece's Square (a1 to h8). direction: the row (0 = first) of the Directions table.
- Type
Text- Name
side
- Name
forward- Value
1
- Name
file- Value
0
- Name
rank- Value
0
- Name
stepsLeft- Value
0
- Type
Boolean- Name
keepGoing- Value
true
- Variable
side- Value
data('Position', from, 'side')
- Variable
forward- Value
data('Sides', side, 'forward')
- Variable
file- Value
data('Position', from, 'file')
- Variable
rank- Value
data('Position', from, 'rank')
- Variable
stepsLeft- Value
data('Directions', direction, 'steps')
rank == data('Sides', side, 'pawnRank')- Variable
stepsLeft- Value
data('Directions', direction, 'firstMoveSteps')
keepGoing == true && stepsLeft > 0- Variable
file- Operator
+=- Value
data('Directions', direction, 'fileStep')
- Variable
rank- Operator
+=- Value
data('Directions', direction, 'rankStep') * forward
- Variable
stepsLeft- Operator
-=- Value
1
- Action Name
squareLook- file
file- rank
rank- side
side- canMove
data('Directions', direction, 'canMove')- canCapture
data('Directions', direction, 'canCapture')
- Variable
keepGoing- Value
squareLook.value
A.8 Look At Square (Function)
Built in Chapter 2, Select and Move.
Looks at one Square a Piece could step onto. file and rank: the Square (they may be off the Board). side: the Side of the moving Piece. canMove: it may step onto an empty Square. canCapture: it may take an enemy Piece there. It marks the Square in the Targets table when the Piece may go there. keepGoing (returned): yes when the Square is on the Board and empty, so a sliding Piece may go on past it.
- Type
Boolean- Name
isOnBoard- Value
false
- Name
square- Value
0
- Type
Boolean- Name
keepGoing- Value
false
file >= 1 && file <= 8 && rank >= 1 && rank <= 8- Variable
isOnBoard- Value
true
- Variable
square- Value
(rank - 1) * 8 + (file - 1)
isOnBoard == true && data('Position', square, 'kind') == ""- Variable
keepGoing- Value
true
keepGoing == true && canMove == true- Table
Targets- Row
square- Column
"reachable"- Value
"true"
isOnBoard == true && data('Position', square, 'kind') != "" && data('Position', square, 'side') != side && canCapture == true- Table
Targets- Row
square- Column
"reachable"- Value
"true"
- Value
keepGoing
A.9 Report Click
Built in Chapter 2, Select and Move.
When the Player clicks this Square while the game is being played (Game State Playing), it tells whoever listens (the Game Rules) with "squareClicked"; the listener reads which Square it was as Other. While the Promotion choice is open, and after the game has ended, the Board does not answer.
Any Object- Action Name
isPlaying- Game State
Playing
isPlaying.value == true- Custom Event
squareClicked
A.10 Select and Move
Built in Chapter 2, Select and Move.
Decides what a click on a Square means. A click on a Square the selected Piece may move to writes it down (Record Move) and makes it (Make Move: castling and en passant included) and tells the Game Rules "moveMade" (Start Turn then starts the other Side's Turn); when the Move takes a Pawn to its last Rank, it opens the Promotion choice instead (Game State Promotion), and Choose Promotion makes the Move. A click on a Piece of the Side to move selects it and marks its Legal Moves (Find Legal Moves); any other click clears the selection. In Threats mode a click that is not a Move also inspects the Piece clicked, of either Side (Inspect Piece). Then it tells everyone "positionChanged". Its Other is the clicked Square. Every click forgets the Hint (Forget The Hint). Escape (the Command Cancel) clears the selection and the Inspected Piece while the game is being played.
Any Objectself.boardStateself.selectAndMoveData- Type
Text- Name
selectedSquare
- Type
Text- Name
clickedSquare
- Variable
clickedSquare- Value
other.squareInfo.name
- Variable
selectedSquare- Value
self.boardState.selected
selectedSquare != "" && data('Targets', clickedSquare, 'reachable') == true- Component Value
self.selectAndMoveData.side- Value
self.boardState.sideToMove
data('Position', selectedSquare, 'kind') == "Pawn" && data('Position', clickedSquare, 'rank') == data('Sides', self.selectAndMoveData.side, 'promotionRank')- gameRules
self- square
clickedSquare
- gameRules
self- from
selectedSquare- to
clickedSquare- landingKind
data('Position', selectedSquare, 'kind')
- gameRules
self- from
selectedSquare- to
clickedSquare
- Custom Event
moveMade
data('Position', clickedSquare, 'side') == self.boardState.sideToMove && clickedSquare != selectedSquare- Component Value
self.boardState.selected- Value
clickedSquare
- from
clickedSquare- enPassantSquare
self.boardState.enPassantSquare
- Component Value
self.boardState.selected- Value
''
- gameRules
self- square
clickedSquare
- Custom Event
positionChanged
- Action Name
isPlaying- Game State
Playing
isPlaying.value == true- Component Value
self.boardState.selected- Value
''
- Component Value
self.boardState.inspected- Value
''
- Custom Event
positionChanged
A.11 Show Move Mark
Built in Chapter 2, Select and Move.
Shows whether the selected Piece may move to this Move Mark's Square, after every change (the Game Rules send "positionChanged"): a dot on an empty Square, a ring around a Piece it may take, and nothing on any other Square. It reads the Targets table, which the Game Rules fill when a Piece is selected.
Any Objectself.squareInfodata('Targets', self.squareInfo.name, 'reachable') == true- Visible
Yes
data('Position', self.squareInfo.name, 'kind') == ""- Frame
0
- Frame
1
- Visible
No
A.12 Show Piece On Square (Function)
Built in Chapter 2, Select and Move.
Shows the Piece that stands on one Square of the Board: the frame of the Piece Set art that the Kinds table gives for its Kind and Side, or nothing (fully transparent) when the Square is empty. piece: the Piece Object to show it with; its Square Info names its Square, which is its row in the Position table.
squareInfoData StructureSquare Info- Type
Text- Name
kind
- Type
Text- Name
side
- Variable
kind- Value
data('Position', piece.squareInfo.name, 'kind')
kind == ""- Applies to
piece- Alpha
0
- Applies to
piece
- Variable
side- Value
data('Position', piece.squareInfo.name, 'side')
- Applies to
piece- Frame
data('Kinds', kind, side)
A.13 Square Marks
Built in Chapter 2, Select and Move.
Shows the highlight on this Square after every change (the Game Rules send "positionChanged" and are its Other): a tint when it was part of the last Move, when its Piece is attacked in Threats mode (the Threats table; a stronger red when it is unprotected), when its Piece is inspected in Threats mode, when its Piece is selected, when it is one of the Hint's two Squares (the Chosen Moves table, row Hint), or when its King is in Check (the most important one shows). The colors, and how strongly each shows, are the Square's Shared Variables (Show Highlight shows them). While the Computer's Move slides ("slideStarted"), no highlight is shown.
Any Objectself.squareInfo- Alpha
0
self.squareInfo.name == other.boardState.lastFrom || self.squareInfo.name == other.boardState.lastTo- square
self- color
@self.lastMoveColor- alpha
@self.lastMoveAlpha
data('Threats', self.squareInfo.name, 'isAttacked') == true- square
self- color
@self.attackedColor- alpha
@self.attackedAlpha
data('Threats', self.squareInfo.name, 'isUnprotected') == true- Alpha
@self.unprotectedAlpha
self.squareInfo.name == other.boardState.inspected- square
self- color
@self.inspectedColor- alpha
@self.inspectedAlpha
self.squareInfo.name == other.boardState.selected- square
self- color
@self.selectedColor- alpha
@self.selectedAlpha
self.squareInfo.name == data('Chosen Moves', 'Hint', 'from') || self.squareInfo.name == data('Chosen Moves', 'Hint', 'to')- square
self- color
@self.hintColor- alpha
@self.hintAlpha
self.squareInfo.name == other.boardState.checkSquare- square
self- color
@self.checkColor- alpha
@self.checkAlpha
- Alpha
0
A.14 Drop Move If Unsafe (Function)
Built in Chapter 3, Turns and Check.
Tries one marked Move on the Position table, asks whether the mover's own King is then attacked, and takes the Move back, so the Position is as it was; if the King would be attacked, the Move is unmarked in the Targets table. from and to: the Squares of the Move (a1 to h8). taken: the Square of the Piece the Move would take: the same as to, except for en passant. kingSquare: where the mover's King stands now. enemy: the other Side.
- Type
Text- Name
takenKind
- Type
Text- Name
takenSide
- Type
Text- Name
checkSquare
- Variable
takenKind- Value
data('Position', taken, 'kind')
- Variable
takenSide- Value
data('Position', taken, 'side')
- Table
Position- Row
taken- Column
"kind"- Value
''
- Table
Position- Row
taken- Column
"side"- Value
''
- from
from- to
to
- Variable
checkSquare- Value
kingSquare
from == kingSquare- Variable
checkSquare- Value
to
- Action Name
kingLook- square
checkSquare- bySide
enemy
kingLook.attacked == true- Table
Targets- Row
to- Column
"reachable"- Value
"false"
- from
to- to
from
- Table
Position- Row
taken- Column
"kind"- Value
takenKind
- Table
Position- Row
taken- Column
"side"- Value
takenSide
A.15 Find Attacker Along (Function)
Built in Chapter 3, Turns and Check.
Looks back from one Square along one direction of the Directions table for the first Piece in the way (Find First Piece Along). attackers (returned): 1 when that Piece belongs to bySide and is of the direction's Kind, so it could capture onto the Square, else 0 (for a Pawn, the direction is turned round by its Side's forward). attacker (returned): the Square of that attacking Piece, or empty when there is none. square: the Square looked from (a1 to h8). direction: the row (0 = first) of the Directions table. bySide: the attacking Side.
- Type
Text- Name
piece
- Name
attackers- Value
0
- Type
Text- Name
attacker
- Action Name
pieceLook- square
square- direction
direction- bySide
bySide
- Variable
piece- Value
pieceLook.value
piece != "" && data('Position', piece, 'side') == bySide && data('Position', piece, 'kind') == data('Directions', direction, 'kind')- Variable
attackers- Value
1
- Variable
attacker- Value
piece
- attackers
attackers- attacker
attacker
A.16 Find King (Function)
Built in Chapter 3, Turns and Check.
Finds where one Side's King stands. side: White or Black. kingSquare (returned): its Square (a1 to h8).
- Type
Text- Name
kingSquare
dataCount('Position')timesdata('Position', local.index, 'kind') == "King" && data('Position', local.index, 'side') == side- Variable
kingSquare- Value
dataRow('Position', local.index)
- Value
kingSquare
A.17 Is Square Attacked (Function)
Built in Chapter 3, Turns and Check.
Answers whether any Piece of one Side could capture onto a Square. square: the Square (a1 to h8). bySide: the attacking Side (White or Black). attacked (returned): yes when at least one of its Pieces attacks the Square. attackers (returned): how many do.
- Name
attackerCount- Value
0
- Type
Boolean- Name
attacked- Value
false
dataCount('Directions')timesdata('Directions', local.index, 'canCapture') == true- Action Name
attackerLook- square
square- direction
local.index- bySide
bySide
- Variable
attackerCount- Operator
+=- Value
attackerLook.attackers
attackerCount > 0- Variable
attacked- Value
true
- attacked
attacked- attackers
attackerCount
A.18 Keep Safe Moves (Function)
Built in Chapter 3, Turns and Check.
Of the Squares marked in the Targets table for the Piece on one Square, unmarks every one that would leave its own King attacked, so only Legal Moves stay marked. from: the Piece's Square (a1 to h8).
- Type
Text- Name
side
- Type
Text- Name
enemy
- Type
Text- Name
kingSquare
- Variable
side- Value
data('Position', from, 'side')
- Variable
enemy- Value
data('Sides', side, 'opponent')
- Action Name
kingLook- side
side
- Variable
kingSquare- Value
kingLook.value
dataCount('Targets')timesdata('Targets', local.index, 'reachable') == true- from
from- to
dataRow('Targets', local.index)- taken
dataRow('Targets', local.index)- kingSquare
kingSquare- enemy
enemy
A.19 Look For Check (Function)
Built in Chapter 3, Turns and Check.
Asks whether the Side to move is in Check: whether its King's Square is attacked by the other Side. The Board State remembers the answer (checkSquare: the King's Square, or empty), and the status line's words ($status) say "Check" or "Your move". gameRules: the Game Rules Object, whose Board State says whose Turn it is.
boardStateData StructureBoard State- Type
Text- Name
side
- Type
Text- Name
enemy
- Type
Text- Name
kingSquare
- Variable
side- Value
gameRules.boardState.sideToMove
- Variable
enemy- Value
data('Sides', side, 'opponent')
- Action Name
kingLook- side
side
- Variable
kingSquare- Value
kingLook.value
- Action Name
checkLook- square
kingSquare- bySide
enemy
checkLook.attacked == true- Component Value
gameRules.boardState.checkSquare- Value
kingSquare
- Variable
$status- Value
data('Words', 'Check', 'text')
- Component Value
gameRules.boardState.checkSquare- Value
''
- Variable
$status- Value
data('Words', 'Your Move', 'text')
A.20 Move Piece (Function)
Built in Chapter 3, Turns and Check.
Moves the Piece on one Square to another in the Position table: the Piece takes the new Square (and any Piece that stood there is gone), and its old Square becomes empty. from and to: the two Squares (a1 to h8).
- Table
Position- Row
to- Column
"kind"- Value
data('Position', from, 'kind')
- Table
Position- Row
to- Column
"side"- Value
data('Position', from, 'side')
- Table
Position- Row
from- Column
"kind"- Value
''
- Table
Position- Row
from- Column
"side"- Value
''
A.21 Start Turn
Built in Chapter 3, Turns and Check.
Starts each Turn: the first one (White's) when the game begins, and the next one after every Move, giving the Turn to the other Side (Pass The Turn). Each Turn starts with Start The Turn: it asks whether the Side to move is in Check, then tells the Game Rules that the Turn has started ("turnStarted").
Any Objectself.boardState- gameRules
self
- Custom Event
positionChanged
- gameRules
self
- Component Value
self.boardState.selected- Value
''
- Component Value
self.boardState.inspected- Value
''
- gameRules
self
A.22 Choose Promotion
Built in Chapter 4, Special Moves.
Closes the Promotion choice when the Player presses one of its buttons ("promotionChosen"; the button is its Other): the panel is hidden and the game is played again (Game State Playing). A Kind then writes down the waiting Pawn Move (Record Move) and makes it (Make Move), puts the chosen Kind on the Square, and tells the Game Rules "moveMade"; Cancel makes no Move, and the Pawn stays selected. Then everyone hears "positionChanged".
Any Objectself.boardStateself.choosePromotionData- Action Name
isChoosing- Game State
Promotion
isChoosing.value == true- Component Value
self.choosePromotionData.chosenKind- Value
other.promotionChoice.kind
- Component Value
self.choosePromotionData.landingSquare- Value
self.boardState.promotionSquare
- Component Value
self.boardState.promotionSquare- Value
''
- UI Group
"Promotion"- Visible
No
- Game State
Playing
self.choosePromotionData.chosenKind != ""- gameRules
self- from
self.boardState.selected- to
self.choosePromotionData.landingSquare- landingKind
self.choosePromotionData.chosenKind
- gameRules
self- from
self.boardState.selected- to
self.choosePromotionData.landingSquare
- Table
Position- Row
self.choosePromotionData.landingSquare- Column
"kind"- Value
self.choosePromotionData.chosenKind
- Custom Event
moveMade
- gameRules
self
- Custom Event
positionChanged
A.23 Find En Passant Move (Function)
Built in Chapter 4, Special Moves.
Marks the en passant Square in the Targets table when the Pawn on one Square may take en passant there, and the Move does not leave its own King attacked. from: the Pawn's Square (a1 to h8). enPassantSquare: the Square an enemy Pawn has just passed over (empty when none).
- Type
Text- Name
side
- Type
Text- Name
enemy
- Name
fromFile- Value
0
- Name
fromRank- Value
0
- Name
targetFile- Value
0
- Name
targetRank- Value
0
- Name
forward- Value
0
- Type
Text- Name
passedPawn
- Type
Text- Name
kingSquare
- Variable
side- Value
data('Position', from, 'side')
- Variable
forward- Value
data('Sides', side, 'forward')
- Variable
fromFile- Value
data('Position', from, 'file')
- Variable
fromRank- Value
data('Position', from, 'rank')
- Variable
targetFile- Value
data('Position', enPassantSquare, 'file')
- Variable
targetRank- Value
data('Position', enPassantSquare, 'rank')
enPassantSquare != "" && data('Position', from, 'kind') == "Pawn" && (targetRank - fromRank) == forward && abs(targetFile - fromFile) == 1- Variable
passedPawn- Value
dataRow('Position', (fromRank - 1) * 8 + (targetFile - 1))
- Table
Targets- Row
enPassantSquare- Column
"reachable"- Value
"true"
- Action Name
kingLook- side
side
- Variable
kingSquare- Value
kingLook.value
- Variable
enemy- Value
data('Sides', side, 'opponent')
- from
from- to
enPassantSquare- taken
passedPawn- kingSquare
kingSquare- enemy
enemy
A.24 Find Legal Moves (Function)
Built in Chapter 4, Special Moves.
Finds every Legal Move of the Piece on one Square and marks them in the Targets table: the ordinary Moves of its Kind that do not leave its own King attacked, then castling and en passant when they are legal. from: the Piece's Square (a1 to h8). enPassantSquare: the Square an enemy Pawn has just passed over (empty when none).
- Type
Text- Name
side
- Type
Text- Name
enemy
- Variable
side- Value
data('Position', from, 'side')
- Variable
enemy- Value
data('Sides', side, 'opponent')
- from
from
- from
from
dataCount('Castling')timesdata('Castling', local.index, 'kingFrom') == from && data('Castling', local.index, 'isAllowed') == true- castling
local.index- enemy
enemy
- from
from- enPassantSquare
enPassantSquare
A.25 Make Move (Function)
Built in Chapter 4, Special Moves.
Makes one Legal Move on the Position table, with everything it brings: the fifty-move rule's count, the Rook's part of castling (Update Castling), en passant (Update En Passant), and the last Move's Squares. gameRules: the Game Rules Object, whose Board State it updates. from and to: the Squares of the Move (a1 to h8).
boardStateData StructureBoard Statedata('Position', from, 'kind') == "Pawn" || data('Position', to, 'kind') != ""- Component Value
gameRules.boardState.fiftyMoveCount- Value
0
- Component Value
gameRules.boardState.fiftyMoveCount- Operator
+=- Value
1
- from
from- to
to
- gameRules
gameRules- from
from- to
to
- from
from- to
to
- Component Value
gameRules.boardState.lastFrom- Value
from
- Component Value
gameRules.boardState.lastTo- Value
to
A.26 Report Choice
Built in Chapter 4, Special Moves.
When the Player presses this button of the Promotion panel, it tells whoever listens (the Game Rules) with "promotionChosen"; the listener reads the button's Promotion Choice (a Kind, or empty to cancel) as Other.
Any Objectself.promotionChoice- Custom Event
promotionChosen
A.27 Show Promotion Choice
Built in Chapter 4, Special Moves.
Shows this Promotion Button's Kind (its Promotion Choice) in the Piece Set art of the Side to move, after every change (the Game Rules send "positionChanged" and are its Other), so the panel always offers the Pieces of the Side that promotes. It shows the Piece Set chosen, whenever the choice changes (Settings sends "lookChanged").
Any Objectself.promotionChoice- Type
Text- Name
choiceKind
- Type
Text- Name
side
- Variable
side- Value
other.boardState.sideToMove
- Variable
choiceKind- Value
self.promotionChoice.kind
- Frame
data('Kinds', choiceKind, side)
- piece
self- pieceSet
other.boardState.pieceSet
A.28 Try Castling (Function)
Built in Chapter 4, Special Moves.
Marks one castling's King Square in the Targets table when the castling is legal now: the Squares between the King and the Rook are empty, and the King is not in Check, does not cross an attacked Square, and does not land on one. castling: the row (0 = first) of the Castling table, still allowed. enemy: the other Side.
- Name
row- Value
0
- Type
Text- Name
kingFrom
- Type
Text- Name
kingTo
- Type
Text- Name
rookTo
- Type
Text- Name
rookPasses
- Name
attacks- Value
0
- Variable
row- Value
castling
- Variable
kingFrom- Value
data('Castling', row, 'kingFrom')
- Variable
kingTo- Value
data('Castling', row, 'kingTo')
- Variable
rookTo- Value
data('Castling', row, 'rookTo')
- Variable
rookPasses- Value
data('Castling', row, 'rookPasses')
data('Position', kingTo, 'kind') == "" && data('Position', rookTo, 'kind') == "" && data('Position', rookPasses, 'kind') == ""- Action Name
startLook- square
kingFrom- bySide
enemy
- Variable
attacks- Value
startLook.attackers
- Action Name
crossLook- square
rookTo- bySide
enemy
- Variable
attacks- Operator
+=- Value
crossLook.attackers
- Action Name
landLook- square
kingTo- bySide
enemy
- Variable
attacks- Operator
+=- Value
landLook.attackers
attacks == 0- Table
Targets- Row
kingTo- Column
"reachable"- Value
"true"
A.29 Update Castling (Function)
Built in Chapter 4, Special Moves.
Keeps the Castling table up to date for one Move, before the Move is made. When the Move is a King castling (from its starting Square to a castling's King Square), the Rook moves too. Any Move from the King's or a Rook's starting Square, or onto a Rook's starting Square (taking it), ends that castling for the rest of the game. from and to: the Squares of the Move (a1 to h8).
- Type
Text- Name
kind
- Type
Text- Name
castling
- Variable
kind- Value
data('Position', from, 'kind')
dataCount('Castling')times- Variable
castling- Value
dataRow('Castling', local.index)
kind == "King" && data('Castling', castling, 'kingFrom') == from && data('Castling', castling, 'kingTo') == to- from
data('Castling', castling, 'rookFrom')- to
data('Castling', castling, 'rookTo')
data('Castling', castling, 'kingFrom') == from || data('Castling', castling, 'rookFrom') == from || data('Castling', castling, 'rookFrom') == to- Table
Castling- Row
castling- Column
"isAllowed"- Value
"false"
A.30 Can Take En Passant (Function)
Built in Chapter 5, The End of the Game.
Asks whether the Side to move may take en passant right now: an enemy Pawn has just passed over the en passant Square, and a Pawn of the Side to move may take it there without leaving its own King attacked. gameRules: the Game Rules Object, whose Board State says whose Turn it is and where en passant is possible. canTake (returned): true when such a Move is a Legal Move. It leaves the Targets table empty.
boardStateData StructureBoard State- Type
Text- Name
side
- Type
Text- Name
enPassant
- Type
Text- Name
square
- Type
Boolean- Name
canTake- Value
false
- Variable
side- Value
gameRules.boardState.sideToMove
- Variable
enPassant- Value
gameRules.boardState.enPassantSquare
dataCount('Position')times- Variable
square- Value
dataRow('Position', local.index)
enPassant != "" && data('Position', square, 'kind') == "Pawn" && data('Position', square, 'side') == side- from
square- enPassantSquare
enPassant
dataFind('Targets', 'reachable', true) != (-1)- Variable
canTake- Value
true
- Value
canTake
A.31 Is Material Insufficient (Function)
Built in Chapter 5, The End of the Game.
Asks whether neither Side has enough Pieces left to give Checkmate, which ends the game as a Draw: only the two Kings; a King and one Knight or one Bishop against a King; or Kings and Bishops whose Bishops all stand on Squares of one shade. isInsufficient (returned): true when that is so.
- Type
Text- Name
kind
- Name
file- Value
0
- Name
rank- Value
0
- Name
squareShade- Value
0
- Name
otherPieces- Value
0
- Name
knights- Value
0
- Name
darkBishops- Value
0
- Name
lightBishops- Value
0
- Type
Boolean- Name
isInsufficient- Value
false
dataCount('Position')times- Variable
kind- Value
data('Position', local.index, 'kind')
- Variable
file- Value
data('Position', local.index, 'file')
- Variable
rank- Value
data('Position', local.index, 'rank')
- Variable
squareShade- Value
(file + rank) % 2
kind != "" && kind != "King"- Variable
otherPieces- Operator
+=- Value
1
kind == "Knight"- Variable
knights- Operator
+=- Value
1
kind == "Bishop" && squareShade == 0- Variable
darkBishops- Operator
+=- Value
1
kind == "Bishop" && squareShade == 1- Variable
lightBishops- Operator
+=- Value
1
otherPieces == 1 && knights == 1- Variable
isInsufficient- Value
true
otherPieces == darkBishops || otherPieces == lightBishops- Variable
isInsufficient- Value
true
- Value
isInsufficient
A.32 Is Out Of Moves (Function)
Built in Chapter 5, The End of the Game.
Asks whether the Side to move has no Legal Move at all, which ends the game. gameRules: the Game Rules Object, whose Board State says whose Turn it is and where en passant is possible. isOutOfMoves (returned): true when no Piece of the Side to move has a Legal Move. It leaves the Targets table empty.
boardStateData StructureBoard State- Type
Text- Name
side
- Type
Text- Name
enPassant
- Type
Text- Name
square
- Type
Boolean- Name
isOutOfMoves- Value
true
- Variable
side- Value
gameRules.boardState.sideToMove
- Variable
enPassant- Value
gameRules.boardState.enPassantSquare
dataCount('Position')times- Variable
square- Value
dataRow('Position', local.index)
isOutOfMoves == true && data('Position', square, 'side') == side- from
square- enPassantSquare
enPassant
dataFind('Targets', 'reachable', true) != (-1)- Variable
isOutOfMoves- Value
false
- Value
isOutOfMoves
A.33 Is Position Repeated (Function)
Built in Chapter 5, The End of the Game.
Asks whether the position recorded last in the Position History table has now been seen timesForDraw times, which ends the game as a Draw. Only every other position before it can be the same, because the Sides take turns: those had the same Side to move. timesForDraw: how many times the same position must be seen (3, threefold repetition). isRepeated (returned): true when it has been seen that often.
- Name
lastPosition- Value
0
- Name
earlier- Value
0
- Name
timesSeen- Value
1
- Type
Boolean- Name
isRepeated- Value
false
- Variable
lastPosition- Value
dataCount('Position History') / dataCount('Position') - 1
floor(lastPosition / 2)times- Variable
earlier- Value
lastPosition - 2 * (local.index + 1)
- Action Name
positionLook- earlier
earlier- later
lastPosition
positionLook.value == true- Variable
timesSeen- Operator
+=- Value
1
timesSeen >= timesForDraw- Variable
isRepeated- Value
true
- Value
isRepeated
A.34 Is Same Position (Function)
Built in Chapter 5, The End of the Game.
Asks whether two positions recorded in the Position History table are the same: the same Piece on every Square and the same number of castlings allowed. earlier and later: the two positions' numbers in the table (0 is the first one recorded). isSame (returned): true when they are the same.
- Name
squares- Value
0
- Name
earlierRow- Value
0
- Name
laterRow- Value
0
- Name
sameSquares- Value
0
- Type
Boolean- Name
isSame- Value
false
- Variable
squares- Value
dataCount('Position')
squarestimes- Variable
earlierRow- Value
earlier * squares + local.index
- Variable
laterRow- Value
later * squares + local.index
data('Position History', earlierRow, 'kind') == data('Position History', laterRow, 'kind') && data('Position History', earlierRow, 'side') == data('Position History', laterRow, 'side') && data('Position History', earlierRow, 'castlingsAllowed') == data('Position History', laterRow, 'castlingsAllowed')- Variable
sameSquares- Operator
+=- Value
1
sameSquares == squares- Variable
isSame- Value
true
- Value
isSame
A.35 Look For Game End
Built in Chapter 5, The End of the Game.
Ends the game at the start of every Turn (Start Turn sends "turnStarted") when the Side to move has no Legal Move (Is Out Of Moves), when neither Side can give Checkmate (Is Material Insufficient), when the same position has come timesSeenForDraw times (Record Position, Is Position Repeated), or when fiftyMoveCountForDraw Moves in a row have had no Capture and no Pawn Move (the fifty-move rule; Make Move counts them). The status line shows the result (Show Result), a Checkmate is marked # in the Move History, and the game is over (Game State Game Over), so the Board no longer answers and the final position stays. Otherwise it tells the Game Rules "gameContinues", and the Turn goes on. timesSeenForDraw: 3, threefold repetition. fiftyMoveCountForDraw: 100, fifty Moves by each Side.
Any Objectself.boardState- Action Name
outOfMoves- gameRules
self
- Action Name
material
- gameRules
self
- Action Name
repetition- timesForDraw
@self.timesSeenForDraw
outOfMoves.value == true || material.value == true || repetition.value == true || self.boardState.fiftyMoveCount >= @self.fiftyMoveCountForDraw- gameRules
self- isOutOfMoves
outOfMoves.value- isMaterialInsufficient
material.value- isRepeated
repetition.value
outOfMoves.value == true && self.boardState.checkSquare != "" && dataCount('Move History') > 0- Table
Move History- Row
dataCount('Move History') - 1- Column
"checkMark"- Value
data('Words', 'Checkmate Mark', 'text')
- Game State
Game Over
- Custom Event
gameContinues
A.36 Record Position (Function)
Built in Chapter 5, The End of the Game.
Adds the position on the Board to the Position History table at the start of a Turn: for every Square, the Piece on it and how many castlings are still allowed. After a Capture or a Pawn Move (and at the start of a game) the table starts over, because no earlier position can come again. A position in which en passant can be taken is not recorded: en passant is possible only on the very next Move, so that position can never come again either. gameRules: the Game Rules Object, whose Board State holds the fifty-move rule's count, whose Turn it is, and the en passant Square.
boardStateData StructureBoard State- Name
castlingsStillAllowed- Value
0
- Type
Text- Name
square
- Name
lastRow- Value
0
gameRules.boardState.fiftyMoveCount == 0- Table
Position History
- Action Name
enPassantLook- gameRules
gameRules
dataCount('Castling')timesdata('Castling', local.index, 'isAllowed') == true- Variable
castlingsStillAllowed- Operator
+=- Value
1
enPassantLook.value != truedataCount('Position')times- Variable
square- Value
dataRow('Position', local.index)
- Action Name
addedRow- Table
Position History- Row
dataCount('Position History')
- Variable
lastRow- Value
dataCount('Position History') - 1
- Table
Position History- Row
lastRow- Column
"kind"- Value
data('Position', square, 'kind')
- Table
Position History- Row
lastRow- Column
"side"- Value
data('Position', square, 'side')
- Table
Position History- Row
lastRow- Column
"castlingsAllowed"- Value
castlingsStillAllowed
A.37 Show Result (Function)
Built in Chapter 5, The End of the Game.
Shows how the game ended in the status line ($status), once the game has ended. When the Side to move has no Legal Move: Checkmate if its King is in Check (the Player wins or loses), else Stalemate (a Draw). Otherwise the game ended as a Draw by rule: insufficient material, else threefold repetition, else the fifty-move rule. gameRules: the Game Rules Object, whose Board State says whose Turn it is, where Check is, and which Side the Player plays. isOutOfMoves: the Side to move has no Legal Move. isMaterialInsufficient: neither Side can give Checkmate. isRepeated: the same position has come for the third time.
boardStateData StructureBoard State- Type
Text- Name
side
- Type
Text- Name
checkSquare
- Variable
side- Value
gameRules.boardState.sideToMove
- Variable
checkSquare- Value
gameRules.boardState.checkSquare
isOutOfMoves == true && checkSquare != "" && side == gameRules.boardState.playerSide- Variable
$status- Value
data('Words', 'Loss By Checkmate', 'text')
isOutOfMoves == true && checkSquare != ""- Variable
$status- Value
data('Words', 'Win By Checkmate', 'text')
isOutOfMoves == true- Variable
$status- Value
data('Words', 'Draw By Stalemate', 'text')
isMaterialInsufficient == true- Variable
$status- Value
data('Words', 'Draw By Insufficient Material', 'text')
isRepeated == true- Variable
$status- Value
data('Words', 'Draw By Threefold Repetition', 'text')
- Variable
$status- Value
data('Words', 'Draw By Fifty Move Rule', 'text')
A.38 Update En Passant (Function)
Built in Chapter 5, The End of the Game.
Keeps en passant up to date for one Move, before the Move is made. A Pawn moving onto the en passant Square takes the enemy Pawn that passed over it. Then the en passant Square is set for the next Move: the Square a Pawn passes over with a two-Square Move, else empty. gameRules: the Game Rules Object, whose Board State holds the en passant Square. from and to: the Squares of the Move (a1 to h8).
boardStateData StructureBoard State- Type
Text- Name
kind
- Name
fromFile- Value
0
- Name
fromRank- Value
0
- Name
toFile- Value
0
- Name
toRank- Value
0
- Name
passedPawn- Value
0
- Name
passedRank- Value
0
- Type
Text- Name
passedSquare
- Variable
kind- Value
data('Position', from, 'kind')
- Variable
fromFile- Value
data('Position', from, 'file')
- Variable
fromRank- Value
data('Position', from, 'rank')
- Variable
toFile- Value
data('Position', to, 'file')
- Variable
toRank- Value
data('Position', to, 'rank')
kind == "Pawn" && to == gameRules.boardState.enPassantSquare- Variable
passedPawn- Value
(fromRank - 1) * 8 + (toFile - 1)
- Table
Position- Row
passedPawn- Column
'kind'- Value
''
- Table
Position- Row
passedPawn- Column
"side"- Value
''
- Component Value
gameRules.boardState.enPassantSquare- Value
''
kind == "Pawn" && abs(toRank - fromRank) == 2- Variable
passedRank- Value
(fromRank + toRank) / 2
- Variable
passedSquare- Value
dataRow('Position', (passedRank - 1) * 8 + (fromFile - 1))
- Component Value
gameRules.boardState.enPassantSquare- Value
passedSquare
A.39 Close New Game
Built in Chapter 6, New Game, Side and Flip.
What the Cancel button of the New Game panel does: it closes the panel and the game goes on as it was.
Any Object- Operation
Hide- Menu Element
New Game Panel
A.40 Flip Board
Built in Chapter 6, New Game, Side and Flip.
Turns the Board over for viewing when the Player presses Flip ("flipPressed"), or back again; once everyone has heard "boardFlipped", it tells its own Object "flipFinished", so Save The Game saves the game the new way round. Only the way the Board is drawn changes (Board State's isFlipped): the position, the Turn, and the Player's Side stay as they are. Then it tells everyone "boardFlipped", so every Piece, Square, Move Mark, and label shows itself the new way round. When the Board has been laid out ("boardLaidOut"), it tells everyone "boardFlipped" too, so everything is shown the way round the Board is drawn.
Any Objectself.boardStateself.boardState.isFlipped == true- Component Value
self.boardState.isFlipped- Value
false
- Component Value
self.boardState.isFlipped- Value
true
- Custom Event
boardFlipped
- Custom Event
flipFinished
- Custom Event
boardFlipped
A.41 New Game
Built in Chapter 6, New Game, Side and Flip.
Starts every game with the Side and the Strength the Player chose last, and lets the Player start a new game. When the game begins (Game Start, before the first Turn), it takes the choices saved on this device (the Strength through Use The Last Strength, which it uses again when a saved game has been brought back, "savedGameLoaded") (Persistent Values), when the game has them (the Sides and Strengths tables; otherwise, and the first time, Board State's own playerSide and strength), turns the Board over for a Player who plays Black, and tells everyone "gameStarted". When the Player presses New Game ("newGamePressed"), it opens the New Game panel, a menu that holds the game while it is open, showing the current choices as chosen and asking "Replace the current game?" when a game is in progress and has Moves. Each Side or Strength pressed ("sideChosen", "strengthChosen"; the button is its Other) becomes the chosen one. Play ("playPressed") saves the choices, forgets the saved game (the slot "auto"), and restarts the game, which starts again from the beginning with them.
Any Objectself.boardState- Action Name
savedSide- Key
"playerSide"- Default
self.boardState.playerSide
- Action Name
isKnownSide- Table
Sides- Row
savedSide.value
isKnownSide.value == true- Component Value
self.boardState.playerSide- Value
savedSide.value
- gameRules
self
self.boardState.playerSide == "Black"- Component Value
self.boardState.isFlipped- Value
true
- Custom Event
gameStarted
- Component Value
self.boardState.chosenSide- Value
self.boardState.playerSide
- Component Value
self.boardState.chosenStrength- Value
self.boardState.strength
- Menu Element
New Game Panel
- Menu Element
New Game Panel
- Action Name
isOver- Game State
Game Over
self.boardState.lastFrom != "" && isOver.value == false- Element
Replace Question
- Element
Replace Question- Visible
No
- Custom Event
choiceChanged
- Component Value
self.boardState.chosenSide- Value
other.panelOption.option
- Custom Event
choiceChanged
- Component Value
self.boardState.chosenStrength- Value
other.panelOption.option
- Custom Event
choiceChanged
- Action Name
persistentWriteResult- Key
"playerSide"- Value
self.boardState.chosenSide
- Action Name
persistentWriteResult2- Key
"strength"- Value
self.boardState.chosenStrength
- Slot
"auto"
- gameRules
self
A.42 Place On Board
Built in Chapter 6, New Game, Side and Flip.
Keeps this Object on its Square (Square Info) when the Board is turned over: when the Game Rules say "boardFlipped" (they are its Other), it moves to where its Square is now drawn (Square Position). The Piece, the Square, the Move Mark, the Threat Mark, and the Pin Mark of each Square all use it. squareMeters: how wide one Square is (3.75 m: the Board art is 30 m across). boardLeft and boardBottom: where the Board's bottom-left corner is in the world (0 and 4.375 m: the game window is 140 px taller than the Board, for the status line and the buttons under it).
Any Objectself.squareInfo- Type
Boolean- Name
isFlipped- Value
false
- Variable
isFlipped- Value
other.boardState.isFlipped
- Action Name
mySquare- square
self.squareInfo.name- isFlipped
isFlipped- squareMeters
@self.squareMeters- boardLeft
@self.boardLeft- boardBottom
@self.boardBottom
- X
mySquare.x- Y
mySquare.y
A.43 Report Flip
Built in Chapter 6, New Game, Side and Flip.
What the Flip button does: it tells whoever listens (the Game Rules) with "flipPressed".
Any Object- Custom Event
flipPressed
A.44 Report New Game
Built in Chapter 6, New Game, Side and Flip.
What the New Game button does: it tells whoever listens (the Game Rules) with "newGamePressed".
Any Object- Custom Event
newGamePressed
A.45 Report Play
Built in Chapter 6, New Game, Side and Flip.
What the Play button of the New Game panel does: it tells whoever listens (the Game Rules) with "playPressed".
Any Object- Custom Event
playPressed
A.46 Report Side
Built in Chapter 6, New Game, Side and Flip.
What a Side button of the New Game panel does (White or Black): it tells whoever listens (the Game Rules) with "sideChosen"; the listener reads the button's Panel Option as Other.
Any Object- Custom Event
sideChosen
A.47 Report Strength
Built in Chapter 6, New Game, Side and Flip.
What a Strength button of the New Game panel does (Gentle to Expert): it tells whoever listens (the Game Rules) with "strengthChosen"; the listener reads the button's Panel Option as Other.
Any Object- Custom Event
strengthChosen
A.48 Show Option
Built in Chapter 6, New Game, Side and Flip.
Marks this option of a panel (New Game or Settings) when it is chosen, whenever the choice changes (the Game Rules send "choiceChanged" and are its Other): the Side or the Strength the panel shows as chosen, the Board Finish, or the Piece Set. chosenColor: the color of a chosen option. plainColor: the color of the others.
Any Objectself.panelOption- Type
Text- Name
myOption
- Variable
myOption- Value
self.panelOption.option
myOption == other.boardState.chosenSide || myOption == other.boardState.chosenStrength || myOption == other.boardState.boardFinish || myOption == other.boardState.pieceSet- Value
@self.chosenColor
- Value
@self.plainColor
A.49 Ask The Computer (Function)
Built in Chapter 7, The Computer.
Asks the Computer for its Move: the Board waits (Game State Computer's Turn), the status line says the Computer is thinking, and the Stockfish Bridge (a Library of code) asks Stockfish for a Move at the Strength in Board State; it answers with "computerMoveChosen". The named timer answerWait rings once if no answer has come in time: the Strength's thinking time plus spareSeconds. gameRules: the Game Rules Object. spareSeconds: how much longer than its thinking time the Computer may take to answer, starting Stockfish included.
boardStateData StructureBoard State- Name
waitSeconds- Value
0
- Game State
Computer's Turn
- Variable
$status- Value
data('Words', 'Thinking', 'text')
- Applies to
gameRules- Java Script
lib.ext.stockfishBridge.chooseComputerMove(api, ctx.self);
- Variable
waitSeconds- Value
data('Strengths', gameRules.boardState.strength, 'thinkingSeconds')
- Variable
waitSeconds- Operator
+=- Value
spareSeconds
- Applies to
gameRules- Timer Name
"answerWait"- Repeat Every (s)
waitSeconds- Ring Once
true
A.50 Can Undo (Function)
Built in Chapter 7, The Computer.
Asks whether the Undo button can be used: once a Move has been made (the Move History has a row). isOn (returned): true when it can.
- Type
Boolean- Name
isOn- Value
false
dataCount('Move History') > 0- Variable
isOn- Value
true
- Value
isOn
A.51 Go Back To The Start (Function)
Built in Chapter 7, The Computer.
Puts the game back as it is when a game starts: the starting position, every castling allowed again, no position seen yet, and nothing marked (the tables as they were made), and Board State as a game starts: White to move, no en passant Square, no Moves counted for the fifty-move rule, no last Move, and nothing selected or inspected. gameRules: the Game Rules Object.
boardStateData StructureBoard State- Table
Position
- Table
Castling
- Table
Position History
- Component Value
gameRules.boardState.sideToMove- Value
'White'
- Component Value
gameRules.boardState.enPassantSquare- Value
''
- Component Value
gameRules.boardState.fiftyMoveCount- Value
0
- Component Value
gameRules.boardState.lastFrom- Value
''
- Component Value
gameRules.boardState.lastTo- Value
''
- Component Value
gameRules.boardState.selected- Value
''
- Component Value
gameRules.boardState.inspected- Value
''
A.52 Make Computer Move
Built in Chapter 7, The Computer.
Plays the Computer's Turns. When a Turn goes on ("gameContinues", from Look For Game End) and the Side to move is the Player's opponent (the Sides table), it asks the Computer for a Move (Ask The Computer: the Board waits in Computer's Turn while the Stockfish Bridge asks Stockfish at the Strength in Board State). When Stockfish answers ("computerMoveChosen"; the Move is in the Chosen Moves table) and it is still the Computer's Turn and the Move is a Legal Move, the Move slides first (Plan The Slide fills the Slides table; everyone hears "slideStarted"). When it has landed ("pieceLanded", from the Moving Piece), it is made if it is still the Computer's Turn, the way the Player's Moves are made: Record Move, Make Move, the Kind it lands as (a promoted Pawn becomes the Kind Stockfish named), then "moveMade" (Start Turn starts the Player's Turn) and "positionChanged". When Stockfish gives no Move, or one that is not legal, or does not answer within its thinking time and spareSeconds more (the answerWait timer), the position stays and the Computer is marked unavailable (Mark Computer Unavailable) until the Player presses Retry ("retryPressed"), which asks again. spareSeconds: how much longer than its thinking time the Computer may take to answer, starting Stockfish included. A Player whose device asks for less motion (the system setting "reduce motion", the Myth Global prefersReducedMotion) sees the Move made at once, with no slide.
Any Objectself.boardStateself.makeComputerMoveDataself.boardState.sideToMove == data('Sides', self.boardState.playerSide, 'opponent')- gameRules
self- spareSeconds
@self.spareSeconds
- Action Name
isThinking- Game State
Computer's Turn
isThinking.value == true- Timer Name
"answerWait"
- Component Value
self.makeComputerMoveData.fromSquare- Value
data('Chosen Moves', 'Computer', 'from')
- Component Value
self.makeComputerMoveData.toSquare- Value
data('Chosen Moves', 'Computer', 'to')
- from
self.makeComputerMoveData.fromSquare- enPassantSquare
self.boardState.enPassantSquare
data('Targets', self.makeComputerMoveData.toSquare, 'reachable') == true$prefersReducedMotion == 1- Custom Event
pieceLanded
- from
self.makeComputerMoveData.fromSquare- to
self.makeComputerMoveData.toSquare
- Custom Event
slideStarted
- gameRules
self
- Action Name
isLanding- Game State
Computer's Turn
isLanding.value == true- Component Value
self.makeComputerMoveData.fromSquare- Value
data('Chosen Moves', 'Computer', 'from')
- Component Value
self.makeComputerMoveData.toSquare- Value
data('Chosen Moves', 'Computer', 'to')
- Component Value
self.makeComputerMoveData.landingKind- Value
data('Chosen Moves', 'Computer', 'landingKind')
- Game State
Playing
- gameRules
self- from
self.makeComputerMoveData.fromSquare- to
self.makeComputerMoveData.toSquare- landingKind
self.makeComputerMoveData.landingKind
- gameRules
self- from
self.makeComputerMoveData.fromSquare- to
self.makeComputerMoveData.toSquare
- Table
Position- Row
self.makeComputerMoveData.toSquare- Column
"kind"- Value
self.makeComputerMoveData.landingKind
- Custom Event
moveMade
- Custom Event
positionChanged
- Action Name
isStillThinking- Game State
Computer's Turn
isStillThinking.value == true- gameRules
self
- Action Name
isUnavailable- Game State
Computer Unavailable
isUnavailable.value == true- gameRules
self- spareSeconds
@self.spareSeconds
A.54 Pass The Turn (Function)
Built in Chapter 7, The Computer.
Gives the Turn to the other Side (the Sides table's opponent column). gameRules: the Game Rules Object, whose Board State holds whose Turn it is (sideToMove).
boardStateData StructureBoard State- Type
Text- Name
side
- Variable
side- Value
gameRules.boardState.sideToMove
- Component Value
gameRules.boardState.sideToMove- Value
data('Sides', side, 'opponent')
A.55 Plan The Slide (Function)
Built in Chapter 7, The Computer.
Writes where the Pieces of one Move slide, before the Move is made (the Slides table): the Piece from its Square to the new one, and, when the Move is a castling, the Rook too, as the Castling table says. from and to: the Squares the Piece moves from and to.
- Type
Text- Name
kind
- Type
Text- Name
rookFrom
- Type
Text- Name
rookTo
- Variable
kind- Value
data('Position', from, 'kind')
- Table
Slides
- Table
Slides- Row
"Piece"- Column
'from'- Value
from
- Table
Slides- Row
"Piece"- Column
'to'- Value
to
dataCount('Castling')timeskind == "King" && data('Castling', local.index, 'kingFrom') == from && data('Castling', local.index, 'kingTo') == to- Variable
rookFrom- Value
data('Castling', local.index, 'rookFrom')
- Variable
rookTo- Value
data('Castling', local.index, 'rookTo')
- Table
Slides- Row
"Rook"- Column
'from'- Value
rookFrom
- Table
Slides- Row
"Rook"- Column
'to'- Value
rookTo
A.56 Record Move (Function)
Built in Chapter 7, The Computer.
Writes a Move at the end of the Move History table just before it is made: the Squares it goes from and to, the Kind the Piece lands as (its own Kind, or the Kind a promoted Pawn becomes), and its name as chess players write it (Name The Move), which depends on the position before the Move. Each Logic that makes a Move calls it just before Make Move (Select and Move, Choose Promotion, Make Computer Move). gameRules: the Game Rules Object, whose Board State holds the en passant Square. from, to: the Move's Squares. landingKind: the Kind the Piece lands as.
boardStateData StructureBoard State- Name
lastRow- Value
0
- Action Name
addedRow- Table
Move History- Row
dataCount('Move History')
- Variable
lastRow- Value
dataCount('Move History') - 1
- Table
Move History- Row
lastRow- Column
'from'- Value
from
- Table
Move History- Row
lastRow- Column
'to'- Value
to
- Table
Move History- Row
lastRow- Column
'landingKind'- Value
landingKind
- from
from- to
to- landingKind
landingKind- enPassantSquare
gameRules.boardState.enPassantSquare- row
lastRow
A.57 Report Retry
Built in Chapter 7, The Computer.
What the Retry button does: it tells whoever listens (the Game Rules) with "retryPressed".
Any Object- Custom Event
retryPressed
A.58 Report Undo
Built in Chapter 7, The Computer.
What the Undo button does: it tells whoever listens (the Game Rules) with "undoPressed". After every change on the Board ("positionChanged"), which the Game Rules also send when the game begins, it asks Can Undo whether the button can be used now, and turns it on or off (Show Button On Or Off).
Any ObjectUI Interaction- Custom Event
undoPressed
- Action Name
canUse
- button
self- isOn
canUse.value
A.61 Slide Piece
Built in Chapter 7, The Computer.
Slides one Piece of the Computer's Move across the Board before the Move is made. When the Game Rules say "slideStarted" (they are its Other), it reads its row of the Slides table: if the row names a Square, it shows the Piece standing there, in the Piece Set chosen, and glides from that Square to the row's other Square in slideSeconds, starting and ending slowly. The Moving Piece that says so (saysWhenLanded) then tells the Game Rules "pieceLanded", and they make the Move; the next "positionChanged" hides it again. While it slides, a Board turned over or back ("boardFlipped") ends the slide at once (Event Logic Land At Once): the Move is made, drawn the new way round; and another Piece Set chosen meanwhile ("lookChanged") shows on it at once (Show The New Piece Set); between slides a turned Board changes nothing here (Stay Hidden). slide: which row of the Slides table it follows (Piece, or Rook for a castling). slideSeconds: how long the slide takes. saysWhenLanded: true for the one Moving Piece that says when the slide is over (a King and its Rook land together). squareMeters, boardLeft, and boardBottom: where the Squares are (as for Place On Board).
Any Objectself.slidePieceData- Type
Text- Name
toSquare
- Type
Text- Name
fromSquare
- Variable
fromSquare- Value
data('Slides', self.slide, 'from')
- Variable
toSquare- Value
data('Slides', self.slide, 'to')
fromSquare != ""- Component Value
self.slidePieceData.isFlipped- Value
other.boardState.isFlipped
- Action Name
startSquare- square
fromSquare- isFlipped
self.slidePieceData.isFlipped- squareMeters
@self.squareMeters- boardLeft
@self.boardLeft- boardBottom
@self.boardBottom
- Action Name
endSquare- square
toSquare- isFlipped
self.slidePieceData.isFlipped- squareMeters
@self.squareMeters- boardLeft
@self.boardLeft- boardBottom
@self.boardBottom
- Component Value
self.slidePieceData.kind- Value
data('Position', fromSquare, 'kind')
- Component Value
self.slidePieceData.side- Value
data('Position', fromSquare, 'side')
- piece
self- pieceSet
other.boardState.pieceSet
- Frame
data('Kinds', self.slidePieceData.kind, self.slidePieceData.side)
- X
startSquare.x- Y
startSquare.y
- Visible
Yes
- Event
On Board Flipped- Mode
Land At Once
- Event
On Look Changed- Mode
Show The New Piece Set
- Value
self.transform.position.x- Target
endSquare.x- Duration
@self.slideSeconds- Ease
Sine in Out
- Value
self.transform.position.y- Target
endSquare.y- Duration
@self.slideSeconds- Ease
Sine in Out
self.saysWhenLanded == true- Timer Name
"landing"- Repeat Every (s)
@self.slideSeconds- Ring Once
Yes
- Custom Event
pieceLanded
- Visible
No
- Timer Name
"landing"
- Event
On Board Flipped- Mode
Stay Hidden
- Event
On Look Changed- Mode
Stay Hidden
self.saysWhenLanded == true- Custom Event
pieceLanded
- piece
self- pieceSet
other.boardState.pieceSet
- Frame
data('Kinds', self.slidePieceData.kind, self.slidePieceData.side)
A.62 Start The Turn (Function)
Built in Chapter 7, The Computer.
Starts the Turn of the Side to move, in the position on the Board: marks a King in Check and sets the status line (Look For Check), marks the Move that gave Check with + in the Move History, then tells the Game Rules "turnStarted" (Look For Game End asks whether the game is over; if it goes on, Make Computer Move asks whether it is the Computer's Turn). gameRules: the Game Rules Object.
boardStateData StructureBoard State- gameRules
gameRules
gameRules.boardState.checkSquare != "" && dataCount('Move History') > 0- Table
Move History- Row
dataCount('Move History') - 1- Column
"checkMark"- Value
data('Words', 'Check Mark', 'text')
- Applies to
gameRules- Custom Event
turnStarted
A.63 Take Back Moves (Function)
Built in Chapter 7, The Computer.
Takes back every Move after the first movesKept Moves: they leave the Move History, the game goes back to its start (Go Back To The Start), and the Moves kept are made again in order, as the game made them, with the position of each Turn recorded first (as at the start of every Turn) so threefold repetition still counts them. Castling, en passant, Promotion, and the fifty-move count come back as they were, because every Move is made with Make Move. gameRules: the Game Rules Object. movesKept: how many Moves, from the first, stay made.
boardStateData StructureBoard State- Type
Text- Name
movedFrom
- Type
Text- Name
movedTo
- Type
Text- Name
landingKind
dataCount('Move History') - movesKepttimes- Action Name
addedRow- Operation
Remove- Table
Move History- Row
dataCount('Move History') - 1
- gameRules
gameRules
movesKepttimes- Variable
movedFrom- Value
data('Move History', local.index, 'from')
- Variable
movedTo- Value
data('Move History', local.index, 'to')
- Variable
landingKind- Value
data('Move History', local.index, 'landingKind')
- gameRules
gameRules
- gameRules
gameRules- from
movedFrom- to
movedTo
- Table
Position- Row
movedTo- Column
"kind"- Value
landingKind
- gameRules
gameRules
A.64 Undo
Built in Chapter 7, The Computer.
Takes back the Player's last Turn when the Player presses Undo ("undoPressed"): the Computer's reply and the Player's Move before it, or only the Player's Move when the Computer has not replied (it is still thinking, or the game ended on that Move). Then that Turn starts again, as play went: a finished game is played again, and if the Turn is the Computer's (a Player who plays Black, back at the start), the Computer moves again. A Stockfish answer still on its way counts for nothing, because the Game State is no longer Computer's Turn. Undo answers only when a Move has been made, and not while the Promotion choice or a menu (the New Game panel) is open. Undo forgets the Hint (Forget The Hint).
Any Objectself.boardStateself.undoDatadataCount('Move History') > 0- Component Value
self.undoData.movesKept- Value
dataCount('Move History') - 1
self.boardState.sideToMove == self.boardState.playerSide && self.undoData.movesKept > 0- Component Value
self.undoData.movesKept- Operator
-=- Value
1
- gameRules
self- movesKept
self.undoData.movesKept
- Game State
Playing
- gameRules
self
- Custom Event
positionChanged
A.65 Can Ask For A Hint (Function)
Built in Chapter 8, The Hint.
Asks whether the Hint button can be used: on the Player's Turn in a game that goes on (Game State Playing). isOn (returned): true when it can.
- Type
Boolean- Name
isOn- Value
false
- Action Name
isPlaying- Game State
Playing
isPlaying.value == true- Variable
isOn- Value
true
- Value
isOn
A.66 Forget The Hint (Function)
Built in Chapter 8, The Hint.
Forgets the Hint: the Chosen Moves table's row Hint is emptied, so no Square shows it any more (the Squares redraw on the next "positionChanged").
- Table
Chosen Moves- Row
"Hint"- Column
"from"- Value
''
- Table
Chosen Moves- Row
"Hint"- Column
"to"- Value
''
- Table
Chosen Moves- Row
"Hint"- Column
"landingKind"- Value
''
A.67 Give A Hint
Built in Chapter 8, The Hint.
Gives the Player a Hint. When the Hint button is pressed ("hintPressed") on the Player's Turn (Game State Playing), the selection is cleared, the Board waits (Game State Finding A Hint), the status line says a Hint is being found, and the Stockfish Bridge asks Stockfish for a Move at the Hint Strength (the Hint Strength table). When Stockfish answers ("hintChosen"; the Move is in the Chosen Moves table, row Hint) and the Move is a Legal Move, the game is played again, the status line shows the Turn again (Look For Check), everyone hears "hintFound" (the Hint message shows it), and the Squares redraw ("positionChanged") with the Hint marked. When the Move is not legal, is empty, or has not come within the Hint's thinking time and spareSeconds more (the hintWait timer), no Hint is shown (Mark Hint Not Found). spareSeconds: how much longer than its thinking time Stockfish may take to answer, starting Stockfish included. When a saved game is brought back while a Hint was being found ("savedGameLoaded"), the Player's Turn goes on without it.
Any Objectself.boardStateself.giveAHintData- Action Name
isPlaying- Game State
Playing
isPlaying.value == true- Component Value
self.boardState.selected- Value
''
- Game State
Finding A Hint
- Variable
$status- Value
data('Words', 'Finding Hint', 'text')
- Java Script
lib.ext.stockfishBridge.chooseHint(api, ctx.self);
- Component Value
self.giveAHintData.waitSeconds- Value
data('Hint Strength', 'Hint', 'thinkingSeconds')
- Component Value
self.giveAHintData.waitSeconds- Operator
+=- Value
@self.spareSeconds
- Timer Name
"hintWait"- Repeat Every (s)
self.giveAHintData.waitSeconds- Ring Once
Yes
- Custom Event
positionChanged
- Action Name
isFinding- Game State
Finding A Hint
isFinding.value == true- Timer Name
"hintWait"
- Component Value
self.giveAHintData.fromSquare- Value
data('Chosen Moves', 'Hint', 'from')
- Component Value
self.giveAHintData.toSquare- Value
data('Chosen Moves', 'Hint', 'to')
- from
self.giveAHintData.fromSquare- enPassantSquare
self.boardState.enPassantSquare
data('Targets', self.giveAHintData.toSquare, 'reachable') == true- Game State
Playing
- gameRules
self
- Custom Event
hintFound
- Custom Event
positionChanged
- gameRules
self
- Action Name
isStillFinding- Game State
Finding A Hint
isStillFinding.value == true- gameRules
self
- Action Name
wasFindingHint- Game State
Finding A Hint
wasFindingHint.value == true- Game State
Playing
- gameRules
self
A.68 Mark Hint Not Found (Function)
Built in Chapter 8, The Hint.
Gives up on the Hint: nothing is marked, the game is played again (Game State Playing), and the status line says that no Hint could be found. gameRules: the Game Rules Object.
boardStateData StructureBoard State- Applies to
gameRules- Timer Name
"hintWait"
- Game State
Playing
- Variable
$status- Value
data('Words', 'Hint Not Found', 'text')
- Custom Event
positionChanged
A.69 Open Promotion Choice (Function)
Built in Chapter 8, The Hint.
Opens the Promotion choice for a Pawn that is about to reach its last Rank: the Board waits (Game State Promotion), the status line asks for the Piece, and the Promotion panel is shown; Choose Promotion then makes the Move. gameRules: the Game Rules Object. square: the Square the Pawn will be promoted on.
boardStateData StructureBoard State- Component Value
gameRules.boardState.promotionSquare- Value
square
- Variable
$status- Value
data('Words', 'Promotion', 'text')
- UI Group
"Promotion"
- Game State
Promotion
A.70 Report Hint
Built in Chapter 8, The Hint.
What the Hint button does: it tells whoever listens (the Game Rules) with "hintPressed". After every change on the Board ("positionChanged"), which the Game Rules also send when the game begins, it asks Can Ask For A Hint whether the button can be used now, and turns it on or off (Show Button On Or Off).
Any ObjectUI Interaction- Custom Event
hintPressed
- Action Name
canUse
- button
self- isOn
canUse.value
A.71 Show Hint Message
Built in Chapter 8, The Hint.
Shows the Hint message ("Try e2 to e4.", with ", promote to queen" when the Move promotes a Pawn) for showSeconds when a Hint has been found ("hintFound"), then hides it. The Move is read from the Chosen Moves table (row Hint) into the message's own Hint Words, which its words show. showSeconds: how long the message stays, in seconds.
Any Objectself.hintWordsUI Interaction- Type
Text- Name
landingKind
- Type
Text- Name
fromSquare
- Variable
fromSquare- Value
data('Chosen Moves', 'Hint', 'from')
- Variable
landingKind- Value
data('Chosen Moves', 'Hint', 'landingKind')
- Component Value
self.hintWords.from- Value
fromSquare
- Component Value
self.hintWords.to- Value
data('Chosen Moves', 'Hint', 'to')
- Component Value
self.hintWords.promotion- Value
''
landingKind != data('Position', fromSquare, 'kind')- Component Value
self.hintWords.promotion- Value
data('Kinds', landingKind, 'promotionWords')
- Timer Name
"messageTime"- Repeat Every (s)
@self.showSeconds- Ring Once
Yes
- Visible
No
A.72 Can Capture (Function)
Built in Chapter 9, Threats.
Answers whether the Piece on one Square can legally capture an enemy Piece: the Capture must be one of its Moves, and must not leave its own King attacked. from: the capturing Piece's Square. to: the Square it moves to. taken: the Square of the Piece it takes (the same as to, except en passant). enPassantSquare: the en passant Square when the Capture may be en passant, else empty. canCapture (returned): yes when it can.
- Type
Text- Name
side
- Type
Text- Name
enemy
- Type
Boolean- Name
canCapture- Value
false
- Variable
side- Value
data('Position', from, 'side')
- Variable
enemy- Value
data('Sides', side, 'opponent')
- from
from
- from
from- enPassantSquare
enPassantSquare
data('Targets', to, 'reachable') == true && data('Position', taken, 'side') == enemy- Action Name
kingLook- side
side
- from
from- to
to- taken
taken- kingSquare
kingLook.value- enemy
enemy
data('Targets', to, 'reachable') == true && data('Position', taken, 'side') == enemy- Variable
canCapture- Value
true
- Value
canCapture
A.73 Can Recapture (Function)
Built in Chapter 9, Threats.
Answers whether a Capture can be answered: the Piece on from legally captures, and then a Piece of the captured Side can legally capture back on the Square it moved to. Pinned Pieces cannot, since every Capture is a Legal Move. from: the capturing Piece's Square. to: the Square it moves to. taken: the Square of the Piece it takes (the same as to, except en passant). enPassantSquare: the en passant Square for an en passant Capture, else empty. canRecapture (returned): yes when the Capture can be made and answered.
- Type
Text- Name
takenKind
- Type
Text- Name
defender
- Type
Boolean- Name
canRecapture- Value
false
- Variable
takenKind- Value
data('Position', taken, 'kind')
- Variable
defender- Value
data('Position', taken, 'side')
- Action Name
captureLook- from
from- to
to- taken
taken- enPassantSquare
enPassantSquare
captureLook.value == true- Table
Position- Row
taken- Column
"kind"- Value
''
- Table
Position- Row
taken- Column
"side"- Value
''
- from
from- to
to
- Action Name
recaptureLook- square
to- bySide
defender
- Variable
canRecapture- Value
recaptureLook.value
- from
to- to
from
- Table
Position- Row
taken- Column
"kind"- Value
takenKind
- Table
Position- Row
taken- Column
"side"- Value
defender
- Value
canRecapture
A.74 Can Show Threats (Function)
Built in Chapter 9, Threats.
Asks whether the Threats button can be used: on the Player's Turn (Game State Playing) or once the game has ended (Game Over), when no Move is being made. isOn (returned): true when it can.
- Type
Boolean- Name
isOn- Value
false
- Action Name
isPlaying- Game State
Playing
- Action Name
isOver- Game State
Game Over
isPlaying.value == true || isOver.value == true- Variable
isOn- Value
true
- Value
isOn
A.75 Can Side Capture (Function)
Built in Chapter 9, Threats.
Answers whether any Piece of one Side can legally capture the enemy Piece on a Square (Can Capture, for each of its Pieces in turn until one can). square: the Square (a1 to h8). bySide: the capturing Side. canCapture (returned): yes when one can.
- Type
Text- Name
piece
- Type
Boolean- Name
canCapture- Value
false
dataCount('Position')times- Variable
piece- Value
dataRow('Position', local.index)
data('Position', piece, 'side') == bySide && canCapture == false- Action Name
captureLook- from
piece- to
square- taken
square- enPassantSquare
''
- Variable
canCapture- Value
captureLook.value
- Value
canCapture
A.76 Clear Threats (Function)
Built in Chapter 9, Threats.
Marks nothing on any Square: the Threats table is emptied, then gets one row for each Square of the Position table, a1 to h8 in the same order, every cell its column's default (no, or empty). The Threats table has no rows of its own; Clear Threats makes them, each time it is used.
- Type
Text- Name
square
- Table
Threats
dataCount('Position')times- Variable
square- Value
dataRow('Position', local.index)
- Action Name
addedRow- Table
Threats- Row
square
A.77 Find First Piece Along (Function)
Built in Chapter 9, Threats.
Looks back from one Square along one direction of the Directions table, Square by Square, and finds the first Piece in the way. square: the Square looked from (a1 to h8). direction: the row (0 = first) of the Directions table. bySide: the Side whose Pieces move this way (a Pawn's direction is turned round by its Side's forward). firstPiece (returned): the Square of the first Piece, or empty when the edge of the Board, or the end of the direction's steps, comes first.
- Name
forward- Value
1
- Name
file- Value
0
- Name
rank- Value
0
- Name
stepsLeft- Value
0
- Type
Boolean- Name
isOnBoard- Value
false
- Name
index- Value
0
- Type
Boolean- Name
keepLooking- Value
true
- Type
Text- Name
firstPiece
- Variable
forward- Value
data('Sides', bySide, 'forward')
- Variable
file- Value
data('Position', square, 'file')
- Variable
rank- Value
data('Position', square, 'rank')
- Variable
stepsLeft- Value
data('Directions', direction, 'steps')
keepLooking == true && stepsLeft > 0- Variable
file- Operator
-=- Value
data('Directions', direction, 'fileStep')
- Variable
rank- Operator
-=- Value
data('Directions', direction, 'rankStep') * forward
- Variable
stepsLeft- Operator
-=- Value
1
- Variable
isOnBoard- Value
false
file >= 1 && file <= 8 && rank >= 1 && rank <= 8- Variable
isOnBoard- Value
true
- Variable
index- Value
(rank - 1) * 8 + (file - 1)
- Variable
keepLooking- Value
false
isOnBoard == true && data('Position', index, 'kind') == ""- Variable
keepLooking- Value
true
isOnBoard == true && data('Position', index, 'kind') != ""- Variable
firstPiece- Value
dataRow('Position', index)
- Value
firstPiece
A.78 Find Passed Pawn (Function)
Built in Chapter 9, Threats.
Finds the Pawn that the Side to move can take en passant right now: the enemy Pawn that has just passed one of its Pawns by moving two Squares. It stands one Rank behind the en passant Square, as seen by the Side to move. gameRules: the Game Rules Object. passedPawn (returned): its Square, or empty when no Pawn can be taken en passant (Can Take En Passant).
boardStateData StructureBoard State- Type
Text- Name
enPassant
- Type
Text- Name
side
- Name
passedRank- Value
0
- Name
passedFile- Value
0
- Type
Text- Name
passedPawn
- Action Name
enPassantLook- gameRules
gameRules
enPassantLook.value == true- Variable
enPassant- Value
gameRules.boardState.enPassantSquare
- Variable
side- Value
gameRules.boardState.sideToMove
- Variable
passedRank- Value
data('Position', enPassant, 'rank')
- Variable
passedRank- Operator
-=- Value
data('Sides', side, 'forward')
- Variable
passedFile- Value
data('Position', enPassant, 'file')
- Variable
passedPawn- Value
dataRow('Position', (passedRank - 1) * 8 + passedFile - 1)
- Value
passedPawn
A.79 Find Pin Along (Function)
Built in Chapter 9, Threats.
Looks from a King along one line (a direction of the Directions table) for a pin: the first Piece on the line is one of the King's own, and the next Piece beyond it is an enemy that moves along this line (the direction's Kind). That own Piece is pinned: the Threats table's pinnedBy gets the enemy Piece's Square. king: the King's Square. direction: the row (0 = first) of the Directions table.
- Type
Text- Name
side
- Type
Text- Name
enemy
- Type
Text- Name
candidate
- Type
Text- Name
pinner
- Variable
side- Value
data('Position', king, 'side')
- Variable
enemy- Value
data('Sides', side, 'opponent')
- Action Name
firstLook- square
king- direction
direction- bySide
enemy
- Variable
candidate- Value
firstLook.value
candidate != "" && data('Position', candidate, 'side') == side- Action Name
beyondLook- square
candidate- direction
direction- bySide
enemy
- Variable
pinner- Value
beyondLook.value
pinner != "" && data('Position', pinner, 'side') == enemy && data('Position', pinner, 'kind') == data('Directions', direction, 'kind')- Table
Threats- Row
candidate- Column
"pinnedBy"- Value
pinner
A.80 Find Threats (Function)
Built in Chapter 9, Threats.
Fills the Threats table for the position on the Board: every Piece that an enemy Piece can legally capture is attacked (Mark Captures, for each Piece of both Sides), the King in Check is attacked (Board State's checkSquare), and so is a Pawn that the Side to move can take en passant (Find Passed Pawn); every Piece pinned to its King is marked (Mark Pins, for each King); then every attacked Piece with no legal recapture is unprotected (Mark Unprotected Pieces). gameRules: the Game Rules Object.
boardStateData StructureBoard State- Type
Text- Name
kingSquare
- Type
Text- Name
square
- Type
Text- Name
passedPawn
- Variable
kingSquare- Value
gameRules.boardState.checkSquare
kingSquare != ""- Table
Threats- Row
kingSquare- Column
"isAttacked"- Value
"true"
- Action Name
passedLook- gameRules
gameRules
- Variable
passedPawn- Value
passedLook.value
passedPawn != ""- Table
Threats- Row
passedPawn- Column
"isAttacked"- Value
"true"
dataCount('Position')times- Variable
square- Value
dataRow('Position', local.index)
data('Position', square, 'side') != ""- from
square
data('Position', square, 'kind') == "King"- king
square
- gameRules
gameRules- passedPawn
passedPawn
A.81 Is Unprotected (Function)
Built in Chapter 9, Threats.
Answers whether an attacked Piece is unprotected: no enemy Capture of it can be answered by a legal recapture (Can Recapture, for each enemy Piece in turn until one Capture can be answered). square: the Piece's Square. passedPawn: the Pawn the Side to move can take en passant, else empty (Find Passed Pawn). enPassantSquare: the en passant Square. isUnprotected (returned): yes when it is unprotected.
- Type
Text- Name
side
- Type
Text- Name
enemy
- Type
Text- Name
attacker
- Type
Boolean- Name
isProtected- Value
false
- Type
Boolean- Name
isUnprotected- Value
false
- Variable
side- Value
data('Position', square, 'side')
- Variable
enemy- Value
data('Sides', side, 'opponent')
dataCount('Position')times- Variable
attacker- Value
dataRow('Position', local.index)
data('Position', attacker, 'side') == enemy && isProtected == false- Action Name
recaptureLook- from
attacker- to
square- taken
square- enPassantSquare
''
- Variable
isProtected- Value
recaptureLook.value
square == passedPawn && data('Position', attacker, 'kind') == "Pawn" && data('Position', attacker, 'side') == enemy && isProtected == false- Action Name
enPassantLook- from
attacker- to
enPassantSquare- taken
square- enPassantSquare
enPassantSquare
- Variable
isProtected- Value
enPassantLook.value
isProtected == false- Variable
isUnprotected- Value
true
- Value
isUnprotected
A.82 Mark Captures (Function)
Built in Chapter 9, Threats.
Marks, in the Threats table, every enemy Piece that the Piece on one Square can legally capture. It asks Find Legal Moves, so a Capture that would leave the capturing Side's own King attacked does not count. En passant is left to Find Threats, because the Pawn it takes does not stand on the Square moved to. from: the Square of the capturing Piece.
- Type
Text- Name
side
- Type
Text- Name
enemy
- Type
Text- Name
target
- Variable
side- Value
data('Position', from, 'side')
- Variable
enemy- Value
data('Sides', side, 'opponent')
- from
from- enPassantSquare
''
dataCount('Targets')times- Variable
target- Value
dataRow('Targets', local.index)
data('Targets', target, 'reachable') == true && data('Position', target, 'side') == enemy- Table
Threats- Row
target- Column
"isAttacked"- Value
"true"
A.83 Mark Pins (Function)
Built in Chapter 9, Threats.
Marks, in the Threats table, every Piece pinned to one King (Find Pin Along, for every line a Queen, Rook, or Bishop slides along). king: the King's Square.
dataCount('Directions')timesdata('Directions', local.index, 'steps') > 1- king
king- direction
local.index
A.84 Mark Unprotected Pieces (Function)
Built in Chapter 9, Threats.
Marks, in the Threats table, every attacked Piece other than a King that is unprotected (Is Unprotected). It runs once every attacked Piece is marked. gameRules: the Game Rules Object. passedPawn: the Pawn the Side to move can take en passant, else empty (Find Passed Pawn).
boardStateData StructureBoard State- Type
Text- Name
enPassant
- Type
Text- Name
square
- Variable
enPassant- Value
gameRules.boardState.enPassantSquare
dataCount('Position')times- Variable
square- Value
dataRow('Position', local.index)
data('Threats', square, 'isAttacked') == true && data('Position', square, 'kind') != "King"- Action Name
unprotectedLook- square
square- passedPawn
passedPawn- enPassantSquare
enPassant
- Table
Threats- Row
square- Column
"isUnprotected"- Value
unprotectedLook.value
A.85 Report Threats
Built in Chapter 9, Threats.
What the Threats button does: it tells whoever listens (the Game Rules) with "threatsPressed". After every change on the Board ("positionChanged"), which the Game Rules also send when the game begins, it asks Can Show Threats whether the button can be used now, and turns it on or off (Show Button On Or Off).
Any ObjectUI Interaction- Custom Event
threatsPressed
- Action Name
canUse
- button
self- isOn
canUse.value
A.86 Show Pin Mark
Built in Chapter 9, Threats.
Shows the amber bar under this Pin Mark's Piece in Threats mode when the Piece is pinned to its own King (the Threats table's pinnedBy), after every change (the Game Rules send "positionChanged"), and hides it while the Computer's Move slides ("slideStarted").
Any Objectself.squareInfodata('Threats', self.squareInfo.name, 'pinnedBy') != ""- Visible
Yes
- Visible
No
- Visible
No
A.87 Show Threat Mark
Built in Chapter 9, Threats.
Outlines this Threat Mark's Square in Threats mode when the Piece standing there is attacked, with a double ring around it when it is unprotected (the Threats table), after every change (the Game Rules send "positionChanged"), and hides the mark while the Computer's Move slides ("slideStarted").
Any Objectself.squareInfodata('Threats', self.squareInfo.name, 'isAttacked') == true- Visible
Yes
- Visible
No
data('Threats', self.squareInfo.name, 'isUnprotected') == true- Frame
1
- Frame
0
- Visible
No
A.88 Show Threats
Built in Chapter 9, Threats.
Turns Threats mode on and off, and keeps its marks up to date. When the game begins (Game Start), and when a saved game has been brought back ("savedGameLoaded"), it takes the choice kept on this device (the Persistent Value "threats", through Use The Last Threats Choice); after a saved game it also fills the Threats table and shows the legend, or empties it, ends any inspecting, and hides the legend, and shows the legend (the UI Group "Threats Legend") when Threats mode is on. At the start of every Turn ("turnStarted") it fills the Threats table again (Find Threats) while Threats mode is on. When the Threats button is pressed ("threatsPressed") on the Player's Turn or after the game has ended, it turns Threats mode over (Board State's isShowingThreats) and ends any inspecting, fills or empties the Threats table, shows or hides the legend, keeps the choice on this device, and every Square redraws ("positionChanged").
Any Objectself.boardState- gameRules
self
self.boardState.isShowingThreats == true- UI Group
"Threats Legend"
self.boardState.isShowingThreats == true- gameRules
self
- Action Name
threatsLook
threatsLook.value == true- Component Value
self.boardState.inspected- Value
''
self.boardState.isShowingThreats == true- Component Value
self.boardState.isShowingThreats- Value
false
- UI Group
"Threats Legend"- Visible
No
- Component Value
self.boardState.isShowingThreats- Value
true
- gameRules
self
- UI Group
"Threats Legend"
self.boardState.selected != ""- from
self.boardState.selected- enPassantSquare
self.boardState.enPassantSquare
- Action Name
persistentWriteResult- Key
"threats"- Value
self.boardState.isShowingThreats
- Custom Event
positionChanged
- gameRules
self
self.boardState.isShowingThreats == true- gameRules
self
- UI Group
"Threats Legend"
- Component Value
self.boardState.inspected- Value
''
- UI Group
"Threats Legend"- Visible
No
A.89 Add Arrow (Function)
Built in Chapter 10, Pin Lines and Arrows.
Adds one arrow at the end of the Arrows table. from and to: the Squares it runs from and to (a1 to h8). color: its color, with how strongly it shows.
- Name
lastRow- Value
0
- Action Name
addedRow- Table
Arrows- Row
dataCount('Arrows')
- Variable
lastRow- Value
dataCount('Arrows') - 1
- Table
Arrows- Row
lastRow- Column
'from'- Value
from
- Table
Arrows- Row
lastRow- Column
'to'- Value
to
- Table
Arrows- Row
lastRow- Column
'color'- Value
color
A.90 Add Arrow Along (Function)
Built in Chapter 10, Pin Lines and Arrows.
Adds the arrow a Piece shows along one of its directions, to the farthest Square it reaches that way (Find Farthest Square Along): in toEnemyColor when an enemy Piece stands there, else in otherColor (an empty Square, or a Piece of its own Side that it protects). No arrow when the direction leaves the Board at once. from: the Square of the Piece. direction: the row (0 = first) of the Directions table.
- Type
Text- Name
enemy
- Type
Text- Name
farthest
- Type
Color- Name
color- Value
'#ffffff'
- Variable
enemy- Value
data('Sides', data('Position', from, 'side'), 'opponent')
- Action Name
reachLook- from
from- direction
direction
- Variable
farthest- Value
reachLook.value
- Variable
color- Value
otherColor
data('Position', farthest, 'side') == enemy- Variable
color- Value
toEnemyColor
farthest != ""- from
from- to
farthest- color
color
A.91 Add Threat Arrow (Function)
Built in Chapter 10, Pin Lines and Arrows.
Adds an arrow from an enemy Piece that attacks a Piece, when it could really capture it: the Capture is a Legal Move (Can Capture), or the Piece attacked is a King. from: the Square of the attacking Piece (empty: no arrow). to: the Square it would move to. taken: the Square of the Piece it would take (not to for en passant). enPassantSquare: the en passant Square, for an en passant Capture, else empty. color: the arrow's color.
- Type
Boolean- Name
isThreat- Value
false
from != ""- Action Name
captureLook- from
from- to
to- taken
taken- enPassantSquare
enPassantSquare
- Variable
isThreat- Value
captureLook.value
data('Position', taken, 'kind') == "King"- Variable
isThreat- Value
true
isThreat == true- from
from- to
to- color
colorInput
A.92 Draw Arrow (Function)
Built in Chapter 10, Pin Lines and Arrows.
Draws one arrow, in the current Draw Color, from one point on the game screen toward another: a straight shaft and a head of two short lines at its end. Use it in a Draw Event. fromX, fromY: where the arrow starts; toX, toY: where it points to (screen pixels, from the bottom-left corner). startGap: how far after the start the shaft begins; endGap: how far before the end the head's tip is. headLength: how far back the head reaches along the shaft. headSpread: how far each side of the head reaches out, as a share of headLength. width: how thick the lines are. All but headSpread in screen pixels.
- Name
distance- Value
0
- Name
stepX- Value
0
- Name
stepY- Value
0
- Name
tipX- Value
0
- Name
tipY- Value
0
- Name
backX- Value
0
- Name
backY- Value
0
- Name
sideX- Value
0
- Name
sideY- Value
0
- Variable
distance- Value
hypot(toX - fromX, toY - fromY)
distance > 0- Variable
stepX- Value
(toX - fromX) / distance
- Variable
stepY- Value
(toY - fromY) / distance
- Variable
tipX- Value
toX - stepX * endGap
- Variable
tipY- Value
toY - stepY * endGap
- Variable
backX- Value
tipX - stepX * headLength
- Variable
backY- Value
tipY - stepY * headLength
- Variable
sideX- Value
stepY * headLength * headSpread
- Variable
sideY- Value
stepX * headLength * headSpread
- X 1
fromX + stepX * startGap- Y 1
fromY + stepY * startGap- X 2
tipX- Y 2
tipY- Line Width
width
- X 1
tipX- Y 1
tipY- X 2
backX - sideX- Y 2
backY + sideY- Line Width
width
- X 1
tipX- Y 1
tipY- X 2
backX + sideX- Y 2
backY - sideY- Line Width
width
A.93 Draw Dashed Line (Function)
Built in Chapter 10, Pin Lines and Arrows.
Draws one dashed line, in the current Draw Color, from one point on the game screen toward another. Use it in a Draw Event. fromX, fromY: where the line starts; toX, toY: where it points to (screen pixels, from the bottom-left corner). startGap: how far after the start the first dash begins; endGap: how far before the end the last dash stops. dashLength: how long each dash is; dashSpacing: how far one dash starts after the one before (more than dashLength leaves a gap). width: how thick the line is. All in screen pixels.
- Name
distance- Value
0
- Name
stepX- Value
0
- Name
stepY- Value
0
- Name
along- Value
0
- Name
lastPoint- Value
0
- Name
dashEnd- Value
0
- Variable
distance- Value
hypot(toX - fromX, toY - fromY)
- Variable
along- Value
startGap
- Variable
lastPoint- Value
distance - endGap
distance > 0- Variable
stepX- Value
(toX - fromX) / distance
- Variable
stepY- Value
(toY - fromY) / distance
along < lastPoint- Variable
dashEnd- Value
along + dashLength
dashEnd > lastPoint- Variable
dashEnd- Value
lastPoint
- X 1
fromX + stepX * along- Y 1
fromY + stepY * along- X 2
fromX + stepX * dashEnd- Y 2
fromY + stepY * dashEnd- Line Width
width
- Variable
along- Operator
+=- Value
dashSpacing
A.94 Draw Threat Lines
Built in Chapter 10, Pin Lines and Arrows.
Draws the lines of Threats mode over the Board: the arrows of the selected or inspected Piece (the Arrows table, which Find Arrows fills on every "positionChanged": red to an enemy Piece it attacks and teal to any other Square it reaches, and red from each enemy Piece that can capture it), and a dashed amber line from every Piece that pins an enemy Piece to its King, to that King (the Threats table's pinnedBy, which Find Threats fills only while Threats mode is on). The Draw Event runs every frame; nothing is drawn while the Computer's Move slides ("slideStarted") or the Promotion choice is open (Game State Promotion), until the next "positionChanged". arrowToEnemyColor, arrowToOtherColor, arrowFromAttackerColor: the arrows' colors. arrowWidth, arrowGapAtStart, arrowGapAtEnd, arrowHeadLength: the arrows' sizes, in Squares (0.035, 0.22, 0.27, 0.11); arrowHeadSpread: how far each side of a head reaches out, as a share of its length (0.6). pinColor: the pin lines' color. pinLineWidth, pinDashLength, pinDashSpacing: the dashes, in Squares (0.03, 0.12, 0.22). pinGapAtStart, pinGapAtKing: how far from the pinning Piece's and the King's centers the line starts and stops, in Squares. squareMeters, boardLeft, boardBottom: where the Squares are (as for Place On Board). pixelsPerMeter: the project's Pixels Per Unit.
Any Objectself.boardStateself.drawThreatLinesData- Name
squarePixels- Value
0
- Variable
squarePixels- Value
@self.squareMeters * @self.pixelsPerMeter
dataCount('Arrows')times- Component Value
self.drawThreatLinesData.arrowFrom- Value
data('Arrows', local.index, 'from')
- Component Value
self.drawThreatLinesData.arrowTo- Value
data('Arrows', local.index, 'to')
- Color
data('Arrows', local.index, 'color')
- Action Name
arrowStart- square
self.drawThreatLinesData.arrowFrom- isFlipped
self.boardState.isFlipped- squareMeters
@self.squareMeters- boardLeft
@self.boardLeft- boardBottom
@self.boardBottom- pixelsPerMeter
@self.pixelsPerMeter
- Action Name
arrowEnd- square
self.drawThreatLinesData.arrowTo- isFlipped
self.boardState.isFlipped- squareMeters
@self.squareMeters- boardLeft
@self.boardLeft- boardBottom
@self.boardBottom- pixelsPerMeter
@self.pixelsPerMeter
- fromX
arrowStart.x- fromY
arrowStart.y- toX
arrowEnd.x- toY
arrowEnd.y- startGap
@self.arrowGapAtStart * squarePixels- endGap
@self.arrowGapAtEnd * squarePixels- headLength
@self.arrowHeadLength * squarePixels- headSpread
@self.arrowHeadSpread- width
@self.arrowWidth * squarePixels
- Color
@self.pinColor
dataCount('Threats')times- Component Value
self.drawThreatLinesData.pinned- Value
dataRow('Threats', local.index)
data('Threats', self.drawThreatLinesData.pinned, 'pinnedBy') != ""- Component Value
self.drawThreatLinesData.pinner- Value
data('Threats', self.drawThreatLinesData.pinned, 'pinnedBy')
- Action Name
kingLook- side
data('Position', self.drawThreatLinesData.pinned, 'side')
- Action Name
pinnerPoint- square
self.drawThreatLinesData.pinner- isFlipped
self.boardState.isFlipped- squareMeters
@self.squareMeters- boardLeft
@self.boardLeft- boardBottom
@self.boardBottom- pixelsPerMeter
@self.pixelsPerMeter
- Action Name
kingPoint- square
kingLook.value- isFlipped
self.boardState.isFlipped- squareMeters
@self.squareMeters- boardLeft
@self.boardLeft- boardBottom
@self.boardBottom- pixelsPerMeter
@self.pixelsPerMeter
- fromX
pinnerPoint.x- fromY
pinnerPoint.y- toX
kingPoint.x- toY
kingPoint.y- startGap
@self.pinGapAtStart * squarePixels- endGap
@self.pinGapAtKing * squarePixels- dashLength
@self.pinDashLength * squarePixels- dashSpacing
@self.pinDashSpacing * squarePixels- width
@self.pinLineWidth * squarePixels
- Event
When Drawn- Mode
Draw Nothing
- gameRules
self- toEnemyColor
@self.arrowToEnemyColor- otherColor
@self.arrowToOtherColor- attackerColor
@self.arrowFromAttackerColor
- Action Name
isChoosing- Game State
Promotion
isChoosing.value == true- Event
When Drawn- Mode
Draw Nothing
- Event
When Drawn- Mode
Draw The Lines
A.95 Find Arrows (Function)
Built in Chapter 10, Pin Lines and Arrows.
Fills the Arrows table for the position on the Board. In Threats mode the selected Piece, or, when none is selected, the inspected Piece, shows an arrow along each direction it captures along, to the farthest Square it reaches (Add Arrow Along), and an arrow from every enemy Piece that can capture it (Find Arrows Toward). Outside Threats mode, or with no such Piece, the table stays empty. gameRules: the Game Rules Object. toEnemyColor, otherColor: the colors of its own arrows to an enemy Piece and to anything else. attackerColor: the color of the arrows from enemy Pieces.
boardStateData StructureBoard State- Type
Text- Name
focus
- Table
Arrows
- Variable
focus- Value
gameRules.boardState.selected
focus == ""- Variable
focus- Value
gameRules.boardState.inspected
gameRules.boardState.isShowingThreats != true- Variable
focus- Value
''
dataCount('Directions')timesfocus != "" && data('Directions', local.index, 'kind') == data('Position', focus, 'kind') && data('Directions', local.index, 'canCapture') == true- from
focus- direction
local.index- toEnemyColor
toEnemyColor- otherColor
otherColor
focus != ""- gameRules
gameRules- target
focus- color
attackerColor
gameRules.boardState.selected != ""- from
gameRules.boardState.selected- enPassantSquare
gameRules.boardState.enPassantSquare
A.96 Find Arrows Toward (Function)
Built in Chapter 10, Pin Lines and Arrows.
Adds an arrow from every enemy Piece that can capture a Piece (Add Threat Arrow): each direction a Piece captures along is looked along backwards from it for an enemy attacker (Find Attacker Along). A Pawn that can be taken en passant also gets an arrow from each enemy Pawn that can take it, to the en passant Square. gameRules: the Game Rules Object. target: the Square of the Piece. color: the arrows' color.
boardStateData StructureBoard State- Type
Text- Name
enemy
- Type
Text- Name
enPassant
- Variable
enemy- Value
data('Sides', data('Position', target, 'side'), 'opponent')
- Action Name
passedLook- gameRules
gameRules
passedLook.value == target- Variable
enPassant- Value
gameRules.boardState.enPassantSquare
dataCount('Directions')timesdata('Directions', local.index, 'canCapture') == true- Action Name
attackerLook- square
target- direction
local.index- bySide
enemy
- from
attackerLook.attacker- to
target- taken
target- enPassantSquare
''- color
colorInput
data('Directions', local.index, 'canCapture') == true && data('Directions', local.index, 'kind') == "Pawn" && enPassant != ""- Action Name
enPassantLook- square
enPassant- direction
local.index- bySide
enemy
- from
enPassantLook.attacker- to
enPassant- taken
target- enPassantSquare
enPassant- color
colorInput
A.97 Find Farthest Square Along (Function)
Built in Chapter 10, Pin Lines and Arrows.
Follows one direction of the Directions table from a Piece, Square by Square, as far as the Piece reaches that way: up to the first Piece in the way (of either Side), the edge of the Board, or the end of the direction's steps. from: the Square of the Piece (a1 to h8). direction: the row (0 = first) of the Directions table (a Pawn's direction is turned round by its Side's forward). farthest (returned): the last Square reached, or empty when the first step leaves the Board.
- Type
Text- Name
side
- Name
forward- Value
1
- Name
file- Value
0
- Name
rank- Value
0
- Name
stepsLeft- Value
0
- Type
Boolean- Name
isOnBoard- Value
false
- Name
index- Value
0
- Type
Boolean- Name
keepGoing- Value
true
- Type
Text- Name
farthest
- Variable
side- Value
data('Position', from, 'side')
- Variable
forward- Value
data('Sides', side, 'forward')
- Variable
file- Value
data('Position', from, 'file')
- Variable
rank- Value
data('Position', from, 'rank')
- Variable
stepsLeft- Value
data('Directions', direction, 'steps')
keepGoing == true && stepsLeft > 0- Variable
file- Operator
+=- Value
data('Directions', direction, 'fileStep')
- Variable
rank- Operator
+=- Value
data('Directions', direction, 'rankStep') * forward
- Variable
stepsLeft- Operator
-=- Value
1
- Variable
isOnBoard- Value
false
file >= 1 && file <= 8 && rank >= 1 && rank <= 8- Variable
isOnBoard- Value
true
- Variable
index- Value
(rank - 1) * 8 + (file - 1)
- Variable
keepGoing- Value
false
isOnBoard == true- Variable
farthest- Value
dataRow('Position', index)
isOnBoard == true && data('Position', index, 'kind') == ""- Variable
keepGoing- Value
true
- Value
farthest
A.98 Inspect Piece (Function)
Built in Chapter 10, Pin Lines and Arrows.
In Threats mode, inspects the Piece standing on a Square the Player clicked (Board State's inspected), whichever Side it belongs to, so its arrows can be shown without selecting it for a Move. A click on an empty Square, or any click outside Threats mode, inspects nothing. gameRules: the Game Rules Object. square: the Square that was clicked.
boardStateData StructureBoard StategameRules.boardState.isShowingThreats == true && data('Position', square, 'kind') != ""- Component Value
gameRules.boardState.inspected- Value
square
- Component Value
gameRules.boardState.inspected- Value
''
A.99 Show Highlight (Function)
Built in Chapter 10, Pin Lines and Arrows.
Shows a Square's highlight in one color: tints the Square and sets how strongly the tint shows. square: the Square Object to highlight. color: the color. alpha: how strongly it shows, from 0 (not at all) to 1 (solid).
- Applies to
square- Value
color
- Applies to
square- Alpha
alpha
A.101 Square Screen Point (Function)
Built in Chapter 10, Pin Lines and Arrows.
Answers where the center of a Square is on the game screen, in screen pixels counted from the bottom-left corner of the screen, as the Draw Actions count them. It asks Square Position where the Square is in the world, in meters, and turns meters into pixels: the camera never moves, so the world's (0, 0) is the screen's bottom-left corner. square: the Square (a1 to h8). isFlipped, squareMeters, boardLeft, boardBottom: as for Square Position. pixelsPerMeter: the project's Pixels Per Unit (32). It returns x and y: the Square's center on the screen.
- Name
x- Value
0
- Name
y- Value
0
- Action Name
worldPoint- square
square- isFlipped
isFlipped- squareMeters
squareMeters- boardLeft
boardLeft- boardBottom
boardBottom
- Variable
x- Value
worldPoint.x * pixelsPerMeter
- Variable
y- Value
worldPoint.y * pixelsPerMeter
- x
x- y
y
A.102 Close Settings
Built in Chapter 11, Settings and Saving.
What the Done button of the Settings panel does: it closes the panel, and the game goes on with the choices made.
Any Object- Operation
Hide- Menu Element
Settings Panel
A.103 Continue The Game
Built in Chapter 11, Settings and Saving.
Brings back the saved game (the save slot "auto") when the game is opened. On Game Start, when the slot holds a game, it turns Save The Game off and loads it: the Scene's own new game still begins first, and must not be saved over the game on its way. When the engine has brought the saved game back ("load:succeeded"), it tells its own Object "savedGameLoaded" (Settings, New Game, and Show Threats use the choices kept on this device again), every Square redraws ("positionChanged"), and, when the game is not over, it says "gameContinues", so the Computer moves when it is its Move and the game is saved again. Save The Game comes back on with the saved game; when a load fails ("load:failed") it is turned on again here.
Any Objectself.boardState- Action Name
hasSavedGame- Slot
"auto"
hasSavedGame.value == true- Logic Component
Save The Game- State
Disable
- Action Name
gameLoad- Slot
"auto"
- Custom Event
savedGameLoaded
- Custom Event
positionChanged
- Action Name
isGameOver- Game State
Game Over
isGameOver.value != true- Custom Event
gameContinues
- Logic Component
Save The Game
A.104 Report Board Finish
Built in Chapter 11, Settings and Saving.
What a Board Finish button of the Settings panel does (Walnut, Tournament, Slate, Marble): it tells whoever listens (the Game Rules) with "boardFinishChosen"; the listener reads the button's Panel Option as Other.
Any Object- Custom Event
boardFinishChosen
A.105 Report Piece Set
Built in Chapter 11, Settings and Saving.
What a Piece Set button of the Settings panel does (Carved walnut, Ivory & gold, Sculpted marble): it tells whoever listens (the Game Rules) with "pieceSetChosen"; the listener reads the button's Panel Option as Other.
Any Object- Custom Event
pieceSetChosen
A.106 Report Settings
Built in Chapter 11, Settings and Saving.
What the Settings button does: it tells whoever listens (the Game Rules) with "settingsPressed".
Any Object- Custom Event
settingsPressed
A.107 Report Strength Setting
Built in Chapter 11, Settings and Saving.
What a Strength button of the Settings panel does (Gentle to Expert): it tells whoever listens (the Game Rules) with "strengthSettingChosen"; the listener reads the button's Panel Option as Other.
Any Object- Custom Event
strengthSettingChosen
A.108 Save The Game
Built in Chapter 11, Settings and Saving.
Saves the game in the save slot "auto" whenever it changes: at the start of every Turn of a game that goes on ("gameContinues", which Look For Game End sends after deciding the game is not over, and Continue The Game after a saved game has been brought back), when the game ends (the Game State becomes Game Over), and when the Player has turned the Board over or back ("flipFinished", from Flip Board). The save holds the Board, the Move History, Board State, the Game State, and every Object as it is; Continue The Game brings it back when the game is opened again.
Any Object- Action Name
gameSave- Slot
"auto"
- Action Name
isGameOver- Game State
Game Over
isGameOver.value == true- Action Name
finishedGameSave- Slot
"auto"
- Action Name
flippedGameSave- Slot
"auto"
A.109 Settings
Built in Chapter 11, Settings and Saving.
Keeps the Player's settings: the Strength, the Board Finish, and the Piece Set. When the game begins (Game Start, and again after Restart Game), and when a saved game has been brought back ("savedGameLoaded"), it takes (Use The Last Look) the Board Finish and the Piece Set saved on this device (Persistent Values), when the game has them (the Board Finishes and Piece Sets tables; otherwise, and the first time, Board State's own boardFinish and pieceSet), and tells everyone "lookChanged", so the Board, its labels, and every Piece show them. (New Game takes the Strength saved, with the Side.) When the Player presses Settings ("settingsPressed"), it opens the Settings panel, a menu that holds the game while it is open. Each option pressed is used at once and kept on this device: a Strength ("strengthSettingChosen") is the Computer's from its next Move; a Board Finish ("boardFinishChosen") or a Piece Set ("pieceSetChosen") is shown at once ("lookChanged"). The pressed button is its Other, and every option then shows whether it is chosen ("choiceChanged").
Any Objectself.boardState- gameRules
self
- Custom Event
lookChanged
- Component Value
self.boardState.chosenStrength- Value
self.boardState.strength
- Menu Element
Settings Panel
- Menu Element
Settings Panel
- Custom Event
choiceChanged
- Component Value
self.boardState.strength- Value
other.panelOption.option
- Component Value
self.boardState.chosenStrength- Value
other.panelOption.option
- Action Name
persistentWriteResult- Key
"strength"- Value
self.boardState.strength
- Custom Event
choiceChanged
- Component Value
self.boardState.boardFinish- Value
other.panelOption.option
- Action Name
persistentWriteResult2- Key
"boardFinish"- Value
self.boardState.boardFinish
- Custom Event
lookChanged
- Custom Event
choiceChanged
- Component Value
self.boardState.pieceSet- Value
other.panelOption.option
- Action Name
persistentWriteResult3- Key
"pieceSet"- Value
self.boardState.pieceSet
- Custom Event
lookChanged
- Custom Event
choiceChanged
- gameRules
self
- Custom Event
lookChanged
A.110 Show Board Finish
Built in Chapter 11, Settings and Saving.
Shows the Board in the Board Finish chosen (Board State's boardFinish, a row of the Board Finishes table) when the game begins and whenever the choice changes (Settings, on the Game Rules, sends "lookChanged" and is its Other).
Any Object- Sprite
data('Board Finishes', other.boardState.boardFinish, 'board')
A.111 Show Piece Set (Function)
Built in Chapter 11, Settings and Saving.
Shows a Piece Set's art on one Object that shows a Piece (a Piece, a Moving Piece, or a Promotion button), at the set's size. Changing the art shows its first frame, so the caller shows the right Piece afterwards. piece: the Object. pieceSet: the Piece Set, a row of the Piece Sets table.
- Applies to
piece- Sprite
data('Piece Sets', pieceSet, 'pieces')
- Applies to
piece- Horizontal Scale
data('Piece Sets', pieceSet, 'size')- Vertical Scale
data('Piece Sets', pieceSet, 'size')
A.112 Use The Last Look (Function)
Built in Chapter 11, Settings and Saving.
Takes the Board Finish and the Piece Set kept on this device (the Persistent Values "boardFinish" and "pieceSet") into Board State, when the game has them (a row of the Board Finishes table, a row of the Piece Sets table; otherwise Board State's own value stays), and tells everyone "lookChanged", so the Board, its labels, and every Piece show them. gameRules: the Object that carries Board State.
boardStateData StructureBoard State- Action Name
savedFinish- Key
"boardFinish"- Default
gameRules.boardState.boardFinish
- Action Name
savedPieceSet- Key
"pieceSet"- Default
gameRules.boardState.pieceSet
- Action Name
isKnownFinish- Table
Board Finishes- Row
savedFinish.value
isKnownFinish.value == true- Component Value
gameRules.boardState.boardFinish- Value
savedFinish.value
- Action Name
isKnownPieceSet- Table
Piece Sets- Row
savedPieceSet.value
isKnownPieceSet.value == true- Component Value
gameRules.boardState.pieceSet- Value
savedPieceSet.value
A.113 Use The Last Strength (Function)
Built in Chapter 11, Settings and Saving.
Takes the Strength kept on this device (the Persistent Value "strength") into Board State, when the game has it (a row of the Strengths table; otherwise Board State's own strength stays). gameRules: the Object that carries Board State.
boardStateData StructureBoard State- Action Name
savedStrength- Key
"strength"- Default
gameRules.boardState.strength
- Action Name
isKnownStrength- Table
Strengths- Row
savedStrength.value
isKnownStrength.value == true- Component Value
gameRules.boardState.strength- Value
savedStrength.value
A.114 Use The Last Threats Choice (Function)
Built in Chapter 11, Settings and Saving.
Takes Threats mode as it is kept on this device (the Persistent Value "threats") into Board State's isShowingThreats: on when the kept value is true, off otherwise (the first time there is none, and Board State's own value stays). gameRules: the Object that carries Board State.
boardStateData StructureBoard State- Action Name
savedThreats- Key
"threats"- Default
gameRules.boardState.isShowingThreats
savedThreats.value == true- Component Value
gameRules.boardState.isShowingThreats- Value
true
- Component Value
gameRules.boardState.isShowingThreats- Value
false
A.115 Ask To Resign
Built in Chapter 12, Game Menu and Keyboard.
What the Resign button of the Game menu does: the Game menu closes and the question "Resign?" opens in its place, a menu that holds the game while it is open. After every change on the Board ("positionChanged"), which the Game Rules also send when the game begins, it asks Can Resign whether the button can be used now, and turns it on or off (Show Button On Or Off).
Any ObjectUI Interaction- Operation
Hide- Menu Element
Game Menu Panel
- Menu Element
Resign Question
- Menu Element
Resign Question
- Action Name
canUse
- button
self- isOn
canUse.value
A.116 Can Resign (Function)
Built in Chapter 12, Game Menu and Keyboard.
Asks whether the Resign button can be used: while the game is not over (any Game State but Game Over). isOn (returned): true when it can.
- Type
Boolean- Name
isOn- Value
false
- Action Name
isGameOver- Game State
Game Over
isGameOver.value != true- Variable
isOn- Value
true
- Value
isOn
A.117 Cancel With Escape
Built in Chapter 12, Game Menu and Keyboard.
Lets Escape (the Command Cancel Choice) cancel the Promotion choice, as a click on its Cancel button does: the button tells whoever listens (the Game Rules) "promotionChosen", and the listener reads its Promotion Choice, empty for Cancel, as Other. Cancel Choice is one of the Promotion choice's own keys, live only while the choice is open (Choose With Keys turns them on).
Any Object- Custom Event
promotionChosen
A.118 Choose With Keys
Built in Chapter 12, Game Menu and Keyboard.
Lets the Player choose the Promotion with the keyboard. While the Promotion choice is open the keys choose among its Pieces instead of playing on the Board: the Input Context Promotion Choice is on and Default (the Board's keys) is off, turned when the choice opens or closes and when a saved game comes back ("positionChanged", from the Game Rules). Left and Right (the Command Choose Piece) move this outline from Piece to Piece, from the Queen to the Knight; Enter or Space (Promote) promotes the Pawn to the Piece it is on: this Object carries that Kind in its Promotion Choice, so the Game Rules (Choose Promotion) hear "promotionChosen" from it as from a button. The outline starts on the Queen each time the choice opens. firstPieceX and pieceY: where the Queen's button stands, in screen pixels right of and above the middle of the screen; pieceSpacing: how far apart the buttons stand.
Any Objectself.promotionChoiceself.chooseWithKeysData- Action Name
isChoosing- Game State
Promotion
isChoosing.value == true- Input Context
Default- Active
No
- Input Context
Promotion Choice
- Component Value
self.chooseWithKeysData.place- Value
1
- promotionFocus
self- place
self.chooseWithKeysData.place- firstPieceX
@self.firstPieceX- pieceY
@self.pieceY- pieceSpacing
@self.pieceSpacing
- Input Context
Promotion Choice- Active
No
- Input Context
Default
- Component Value
self.chooseWithKeysData.place- Value
clamp(self.chooseWithKeysData.place - 1, 1, 4)
- promotionFocus
self- place
self.chooseWithKeysData.place- firstPieceX
@self.firstPieceX- pieceY
@self.pieceY- pieceSpacing
@self.pieceSpacing
- Component Value
self.chooseWithKeysData.place- Value
clamp(self.chooseWithKeysData.place + 1, 1, 4)
- promotionFocus
self- place
self.chooseWithKeysData.place- firstPieceX
@self.firstPieceX- pieceY
@self.pieceY- pieceSpacing
@self.pieceSpacing
- Custom Event
promotionChosen
A.120 Close How To Play
Built in Chapter 12, Game Menu and Keyboard.
What the Done button of the How to play panel does: it closes the panel, and the game goes on.
Any Object- Operation
Hide- Menu Element
How To Play Panel
A.121 Close Resign Question
Built in Chapter 12, Game Menu and Keyboard.
What the Cancel button of the question "Resign?" does: it closes the question, and the game goes on.
Any Object- Operation
Hide- Menu Element
Resign Question
A.122 Find Other Pieces Reaching (Function)
Built in Chapter 12, Game Menu and Keyboard.
Asks, before a Move is made, whether another Piece of the same Kind and Side as the one on from could also make a Legal Move to the Square to, as standard notation needs to know (a Pawn is never asked: its Capture is named by its File). from, to: the Move's Squares. enPassantSquare: the Square a Pawn may take en passant now (Board State). isFileNeeded (returned): true when the name must say the File the Piece came from (another such Piece reaches to from another File, or from the same File and the same Rank). isRankNeeded (returned): true when the name must say the Rank it came from (another such Piece reaches to from the same File). The Targets table is left empty.
- Type
Text- Name
square
- Type
Boolean- Name
isReached- Value
false
- Type
Boolean- Name
isSameFile- Value
false
- Type
Boolean- Name
isSameRank- Value
false
- Type
Boolean- Name
isFileNeeded- Value
false
- Type
Boolean- Name
isRankNeeded- Value
false
dataCount('Position')times- Variable
square- Value
dataRow('Position', local.index)
data('Position', square, 'kind') == data('Position', from, 'kind') && data('Position', square, 'side') == data('Position', from, 'side') && square != from && data('Position', from, 'kind') != "Pawn"- from
square- enPassantSquare
enPassantSquare
data('Targets', to, 'reachable') == true- Variable
isReached- Value
true
data('Targets', to, 'reachable') == true && data('Position', square, 'file') == data('Position', from, 'file')- Variable
isSameFile- Value
true
data('Targets', to, 'reachable') == true && data('Position', square, 'rank') == data('Position', from, 'rank')- Variable
isSameRank- Value
true
isReached == trueisSameFile == true && isSameRank == true- Variable
isFileNeeded- Value
true
- Variable
isRankNeeded- Value
true
isSameFile == true- Variable
isRankNeeded- Value
true
- Variable
isFileNeeded- Value
true
- isFileNeeded
isFileNeeded- isRankNeeded
isRankNeeded
A.124 Keyboard Focus
Built in Chapter 12, Game Menu and Keyboard.
Lets the Player play with the keyboard: keeps the focused Square (this Object's Square Info) and draws the Focus Mark on it. The arrow keys (Move Focus) move the focus one Square on the screen, Home and End (Focus Row Start, Focus Row End) to the ends of its row, always stopping at the Board's edges, and the way the Board is drawn turns them round ("boardFlipped", from the Game Rules). Enter or Space (Press Square) presses the focused Square as a click does ("squareClicked"), while the game is being played. The focus starts on the Square in front of the Player's King when each game begins ("gameStarted", from the Game Rules), and shows itself from the first key. These keys are the Input Context Default: while the Promotion choice is open they rest, and the focus stays where it is (Choose With Keys turns them off and the choice's own keys on). startFile: the File the focus starts on (5: File e). squareMeters, boardLeft, boardBottom: the Board as Place On Board draws it.
Any Objectself.squareInfoself.keyboardFocusData- Name
row- Value
0
- Name
rank- Value
0
- Component Value
self.keyboardFocusData.isFlipped- Value
other.boardState.isFlipped
- Variable
rank- Value
data('Sides', other.boardState.playerSide, 'pawnRank')
- Variable
row- Value
(rank - 1) * 8 + (@self.startFile - 1)
- Component Value
self.squareInfo.name- Value
dataRow('Position', row)
- focusMark
self- isFlipped
self.keyboardFocusData.isFlipped- squareMeters
@self.squareMeters- boardLeft
@self.boardLeft- boardBottom
@self.boardBottom
- Component Value
self.keyboardFocusData.isFlipped- Value
other.boardState.isFlipped
- focusMark
self- isFlipped
self.keyboardFocusData.isFlipped- squareMeters
@self.squareMeters- boardLeft
@self.boardLeft- boardBottom
@self.boardBottom
- focusMark
self- fileStep
-1- rankStep
0- isFlipped
self.keyboardFocusData.isFlipped- squareMeters
@self.squareMeters- boardLeft
@self.boardLeft- boardBottom
@self.boardBottom
- focusMark
self- fileStep
1- rankStep
0- isFlipped
self.keyboardFocusData.isFlipped- squareMeters
@self.squareMeters- boardLeft
@self.boardLeft- boardBottom
@self.boardBottom
- focusMark
self- fileStep
0- rankStep
1- isFlipped
self.keyboardFocusData.isFlipped- squareMeters
@self.squareMeters- boardLeft
@self.boardLeft- boardBottom
@self.boardBottom
- focusMark
self- fileStep
0- rankStep
-1- isFlipped
self.keyboardFocusData.isFlipped- squareMeters
@self.squareMeters- boardLeft
@self.boardLeft- boardBottom
@self.boardBottom
- focusMark
self- fileStep
-7- rankStep
0- isFlipped
self.keyboardFocusData.isFlipped- squareMeters
@self.squareMeters- boardLeft
@self.boardLeft- boardBottom
@self.boardBottom
- focusMark
self- fileStep
7- rankStep
0- isFlipped
self.keyboardFocusData.isFlipped- squareMeters
@self.squareMeters- boardLeft
@self.boardLeft- boardBottom
@self.boardBottom
- Action Name
isPlaying- Game State
Playing
isPlaying.value == true- Visible
Yes
- Custom Event
squareClicked
A.125 Move Pages
Built in Chapter 12, Game Menu and Keyboard.
Chooses which full Moves the Game menu's Move List shows, movesPerPage at a time (Board State's firstShownMove): the page that holds the newest Move when the menu opens ("gameMenuOpened"), the page before when Earlier is pressed ("earlierMovesPressed"), and the page after when Later is pressed ("laterMovesPressed"). Each time it tells everyone "movePageChanged", so the list shows the page.
Any Objectself.boardStateself.movePagesData- Component Value
self.boardState.firstShownMove- Value
0
dataCount('Move History') > 0- Component Value
self.movePagesData.newestMove- Value
floor((dataCount('Move History') - 1) / 2)
- Component Value
self.movePagesData.newestPage- Value
floor(self.movePagesData.newestMove / self.boardState.movesPerPage)
- Component Value
self.boardState.firstShownMove- Value
self.movePagesData.newestPage * self.boardState.movesPerPage
- Custom Event
movePageChanged
- Component Value
self.boardState.firstShownMove- Operator
-=- Value
self.boardState.movesPerPage
- Custom Event
movePageChanged
- Component Value
self.boardState.firstShownMove- Operator
+=- Value
self.boardState.movesPerPage
- Custom Event
movePageChanged
A.126 Move The Focus Mark (Function)
Built in Chapter 12, Game Menu and Keyboard.
Moves the Focus Mark to where its Square (its Square Info) is drawn now, as Place On Board moves a Piece (Square Position). focusMark: the Focus Mark. isFlipped: whether the Board is drawn turned over. squareMeters, boardLeft and boardBottom: the Board's size and corner, as Place On Board has them.
squareInfoData StructureSquare Info- Action Name
focusedSquare- square
focusMark.squareInfo.name- isFlipped
isFlipped- squareMeters
squareMeters- boardLeft
boardLeft- boardBottom
boardBottom
- Applies to
focusMark- X
focusedSquare.x- Y
focusedSquare.y
A.127 Move The Promotion Focus (Function)
Built in Chapter 12, Game Menu and Keyboard.
Puts the Promotion Focus on the Piece at one place of the Promotion choice: its Promotion Choice becomes that Kind, and its outline is drawn over that Piece's button. promotionFocus: the Promotion Focus. place: 1 to 4, the Queen, Rook, Bishop and Knight, as their buttons stand from left to right. firstPieceX and pieceY: where the Queen's button stands, in screen pixels right of and above the middle of the screen; pieceSpacing: how far apart the buttons stand.
promotionChoiceData StructurePromotion Choice- Component Value
promotionFocus.promotionChoice.kind- Value
dataRow('Kinds', place)
- Applies to
promotionFocus- Position Relative To
Screen- X
firstPieceX + (place - 1) * pieceSpacing- Y
pieceY
A.128 Name The Move (Function)
Built in Chapter 12, Game Menu and Keyboard.
Writes a Move's name, as chess players write it (standard algebraic notation: e4, Nf3, exd5, O-O, e8=Q, Rad1), into its row of the Move History, before the Move is made: the name depends on the position the Move is made in. The check mark (+ or #) is written when the next Turn starts (Start The Turn, Look For Game End). from, to: the Move's Squares. landingKind: the Kind the Piece lands as. enPassantSquare: the Square a Pawn may take en passant now. row: the Move's row in the Move History.
- Type
Text- Name
movedKind
- Type
Text- Name
castling
- Variable
movedKind- Value
data('Position', from, 'kind')
- Table
Move History- Row
row- Column
"letter"- Value
data('Kinds', movedKind, 'letter')
- Table
Move History- Row
row- Column
"square"- Value
to
data('Position', to, 'kind') != ""- Table
Move History- Row
row- Column
"capture"- Value
data('Words', 'Capture Mark', 'text')
movedKind == "Pawn" && data('Position', from, 'file') != data('Position', to, 'file')- Table
Move History- Row
row- Column
"capture"- Value
data('Words', 'Capture Mark', 'text')
- Table
Move History- Row
row- Column
"fromFile"- Value
data('Position', from, 'fileLetter')
landingKind != movedKind- Table
Move History- Row
row- Column
"promotion"- Value
data('Kinds', landingKind, 'promotionMark')
dataCount('Castling')times- Variable
castling- Value
dataRow('Castling', local.index)
movedKind == "King" && data('Castling', castling, 'kingFrom') == from && data('Castling', castling, 'kingTo') == to- Table
Move History- Row
row- Column
"letter"- Value
data('Castling', castling, 'notation')
- Table
Move History- Row
row- Column
"square"- Value
''
- Action Name
others- from
from- to
to- enPassantSquare
enPassantSquare
others.isFileNeeded == true- Table
Move History- Row
row- Column
"fromFile"- Value
data('Position', from, 'fileLetter')
others.isRankNeeded == true- Table
Move History- Row
row- Column
"fromRank"- Value
data('Position', from, 'rank')
A.129 Report Earlier Moves
Built in Chapter 12, Game Menu and Keyboard.
What the Earlier button of the Move List does: it tells whoever listens (the Game Rules) with "earlierMovesPressed".
Any Object- Custom Event
earlierMovesPressed
A.131 Report Later Moves
Built in Chapter 12, Game Menu and Keyboard.
What the Later button of the Move List does: it tells whoever listens (the Game Rules) with "laterMovesPressed".
Any Object- Custom Event
laterMovesPressed
A.132 Report Resign
Built in Chapter 12, Game Menu and Keyboard.
What the Resign button of the question "Resign?" does: it tells whoever listens (the Game Rules) with "resignConfirmed".
Any Object- Custom Event
resignConfirmed
A.133 Resign
Built in Chapter 12, Game Menu and Keyboard.
Ends the game when the Player resigns: when the Player answers "Resign?" with Resign ("resignConfirmed"), the question closes and, if the game is not over yet, the status line shows "You lose · Resignation" (the Words row Loss By Resignation) and the game is over (Game State Game Over), so the Board no longer answers and the final position stays, as at every other end of a game. Then everyone hears "positionChanged", so the buttons show what can be used now. An answer from the Computer still on its way is not used: the Computer's Logic asks whether it is still the Computer's Turn.
Any Object- Operation
Hide- Menu Element
Resign Question
- Action Name
isGameOver- Game State
Game Over
isGameOver.value != true- Variable
$status- Value
data('Words', 'Loss By Resignation', 'text')
- Game State
Game Over
- Custom Event
positionChanged
A.134 Show How To Play
Built in Chapter 12, Game Menu and Keyboard.
What the How to play button of the Game menu does: the Game menu closes and the How to play panel opens in its place, a menu that holds the game while it is open.
Any Object- Operation
Hide- Menu Element
Game Menu Panel
- Menu Element
How To Play Panel
- Menu Element
How To Play Panel
A.135 Show No Moves Note
Built in Chapter 12, Game Menu and Keyboard.
Shows "No moves yet." in the Game menu's Move List while no Move has been made, and hides it once there is one, each time the page is drawn ("movePageChanged", from the Game Rules).
Any ObjectUI InteractiondataCount('Move History') == 0- Visible
No
A.137 Show Recorded Move
Built in Chapter 12, Game Menu and Keyboard.
Shows one Move of the game in the Game menu's Move List, as chess players write it, read from its row of the Move History into this Object's own Move Notation, which its words show. Each line of the list is two placements, White's Move and Black's. When the page changes ("movePageChanged", from the Game Rules), the Move shown is the line's full Move on that page; a line past the newest Move shows nothing. line: the line of the list, 0 (top) to 11. isBlackMove: true for the placement that shows Black's Move of the line (false: White's, with the move number).
Any Objectself.moveNotationUI Interaction- Name
row- Value
0
- Variable
row- Value
(other.boardState.firstShownMove + self.line) * 2
self.isBlackMove == true- Variable
row- Operator
+=- Value
1
row < dataCount('Move History')- Component Value
self.moveNotation.number- Value
objectComponentProperty("otherObject","boardState","firstShownMove") + instanceVar("self","line") + 1
- Component Value
self.moveNotation.letter- Value
data('Move History', row, 'letter')
- Component Value
self.moveNotation.fromFile- Value
data('Move History', row, 'fromFile')
- Component Value
self.moveNotation.fromRank- Value
data('Move History', row, 'fromRank')
- Component Value
self.moveNotation.capture- Value
data('Move History', row, 'capture')
- Component Value
self.moveNotation.square- Value
data('Move History', row, 'square')
- Component Value
self.moveNotation.promotion- Value
data('Move History', row, 'promotion')
- Component Value
self.moveNotation.checkMark- Value
data('Move History', row, 'checkMark')
- Visible
No
A.138 Step The Focus (Function)
Built in Chapter 12, Game Menu and Keyboard.
Moves the focus by a number of Squares on the screen, and stops at the Board's edges: the Focus Mark's Square becomes the one reached, the mark is shown, and it moves there (Move The Focus Mark). focusMark: the Focus Mark. fileStep: Squares to the right; rankStep: Squares up (negative: left, down). isFlipped: whether the Board is drawn turned over. squareMeters, boardLeft and boardBottom: the Board's size and corner.
squareInfoData StructureSquare Info- Name
across- Value
0
- Name
up- Value
0
- Name
file- Value
0
- Name
rank- Value
0
- Name
row- Value
0
- Variable
across- Value
fileStep
- Variable
up- Value
rankStep
isFlipped == true- Variable
across- Operator
*=- Value
-1
- Variable
up- Operator
*=- Value
-1
- Variable
file- Value
data('Position', focusMark.squareInfo.name, 'file')
- Variable
file- Operator
+=- Value
across
- Variable
file- Value
clamp(file, 1, 8)
- Variable
rank- Value
data('Position', focusMark.squareInfo.name, 'rank')
- Variable
rank- Operator
+=- Value
up
- Variable
rank- Value
clamp(rank, 1, 8)
- Variable
row- Value
(rank - 1) * 8 + (file - 1)
- Component Value
focusMark.squareInfo.name- Value
dataRow('Position', row)
- Applies to
focusMark- Visible
true
- focusMark
focusMark- isFlipped
isFlipped- squareMeters
squareMeters- boardLeft
boardLeft- boardBottom
boardBottom
