generic interface
Returns the set of sides that are currently in the game. Order in the result list does not matter.Returns the side to play once side’s turn is over. This should be called after side’s turn is over and game-state has been updated with side’s move choice.procedure
game-statesidetbg:TBGgame-state:GameStateside:Sidemove-choice:MoveChoiceDetermines whether the given move-choice is a valid legal move according to the rules of the game. If it is legal, valid-move-choice? returns true, otherwise it returns false.procedure
( valid-move-choices tbggame-stateside)
tbg:TBGgame-state:GameStateside:SideReturns a sequence which will enumerate all possible legal moves within the rules of the game.NOTE: This sequence may or may not be finite, so if you’re relying on using it to iterate through all the elements, check with known-finite? first.
procedure
game-statesidetbg:TBGgame-state:GameStateside:Sidemove-choice:MoveChoiceReturns the game state after side plays the given move-choice for their turn. This should not mutate the original game state, but return a new one.procedure
( winning-state? tbggame-stateside)→Boolean
tbg:TBGgame-state:GameStateside:SideDetermines whether the given side has won in the given game-state according to the rules of the game.
generic interface
procedure
( standard-initial-state tbg)→GameState
tbg:TBGIProduces the standard initial game state for the given turn-based game.procedure
( standard-initial-side tbg)→Side
tbg:TBGIProduces the standard starting side for the given turn-based game, that is, the side that starts the game with their turn.
generic interface
A HandlerResult is one of:
– ( continue-turn TurnState )
– ( finish-turn MoveChoice )
procedure
game-statesidetbg:TBGGgame-state:GameStateside:Sideturn-state:TurnStateprocedure
game-statesidetbg:TBGGgame-state:GameStateside:Sideprocedure
( start-turn tbg)→TurnState
tbg:TBGGDetermines the initial state that every player starts their turn with. The first mouse event or key event of a turn will use the result of this method as the starting turn-state.procedure
game-statesideturn-statemouse-posntbg:TBGGgame-state:GameStateside:Sideturn-state:TurnStatemouse-posn:Posnmouse-event:MouseEventThis method handles mouse events, including "move" for mouse movements, "button-down" and "button-up" for mouse clicks, "drag" for dragging movements, and "enter" and "leave" for when the mouse enters and leaves the game canvas.Mouse scrolling motions are actually not handled as mouse events; they are handled as key events using handle-key .
When a mouse event happens, this method can either continue the turn with an updated turn-state using continue-turn , or finish the turn with a final MoveChoice, using finish-turn . If the mouse event is not relevant, it should continue the turn with the same turn-state as before.
For example, some games might require moving a piece by clicking on it and then clicking on the space to move it to. On the first click, the handle-mouse method should return (continue-turn piece-selection) where piece-selection is a TurnState representing which piece was clicked on to be moved. Then on the second click, the handle-mouse method should return (finish-turn move-choice) where move-choice is a MoveChoice representing which piece should be moved and where it should go. A rough sketch of the definition would look like this:
;;ASpacerepresentsthepositionofaspaceontheboard.;;AMoveChoiceisa(moveSpaceSpace);;representingmovingapiecefromthe`from`spacetothe`to`space.;;ATurnStateisoneof:;;-#false;beginningofturn;;-Space;thepieceonthisspacehasbeenselectedtobemoved;;handle-mouse:;;TBGGGameStateSideTurnStatePosnMouseEvent->HandlerResult(cond;;thisisthefirstclick;;selectthepieceatthisspacetobemoved;;otherwisejustastrayclickonanemptyspace[else;;thereisalreadyapieceselected;thisisthesecondclick;;thisisafinishedmovechoice;;otherwisethiswouldbeaninvalidmove....)])][else;;themouseeventisnotrelevantprocedure
game-statesideturn-statetbg:TBGGgame-state:GameStateside:Sideturn-state:TurnStatekey-event:KeyEventThis method handles key events. One-character strings like "a", "b", and "c" represent the "regular" keys like A, B, and C. This includes strings like " " for the Spacebar, "\r" for the Enter key, and "\t" for the Tab key.Other keys are represented with multi-character strings, such as "left", "right", "up", and "down" for the arrow keys, and "shift" and "rshift" for the two shift keys.
Mouse scrolling motions are also handled as key events, with "wheel-up" representing scrolling up, "wheel-down" representing scrolling down, and "wheel-left" and "wheel-right" representing scrolling left and right.
Just like with handle-mouse , when a key event happens, this method can either continue the turn with an updated turn-state using continue-turn , or finish the turn with a final MoveChoice using finish-turn .
A ComputerPlayer is an object that describes a strategy the computer will use to play a game. Some will be specific to a particular game, but some can be generic across all TBG instances, although for some they might be increbibly slow.
procedure
n:Natural
procedure
( start/computer game-desccomputer-players)→Void
game-desc:TBGGI