The following are the references for turn_based_game.
Game* = ref object of RootObj player_count*: int players*: seq[Player] current_player_number*: int # 1, 2, 3,... but 0 is never used winner_player_number*: int # 0=no winner; -1=stalemate; n=winnersource line: 142
The game object to inherit from and then apply rules.
For example:
type GameOfThai21 = ref object of Game pile*: int
Player* = ref object of RootObj name*: stringsource line: 159
The default player object. If used directly, the Player object is simply the end user playing the game from the OS's text console.
When integrating with another framework, such as a GUI or an AI, have the framework's player inherit from Player.
method current_player*(self: Game) : Player {.base.} =source line: 247
Return the Player whose turn it is to play
method default_setup*(self: Game, players: seq[Player]) {.base.} =source line: 348
This is the default setup for Game. You are welcome to call it when writing the
setup
method.The code is:
self.players = players self.player_count = len(self.players) self.current_player_number = 1 self.winner_player_number = 0
method determine_winner*(self: Game) {.base.} =source line: 303
Given the current state of the game, determine who the winner is, if there is a winner.
If running a game manually (avoiding the .play method), it is expected that this method is run BEFORE the turn finishes. If a winning condition is detected, the current player is generally assumed to be the winner that caused that condition.
See: https://github.com/JohnAD/turn_based_game/wiki/Game-Object-Methods#determine_winner
method finish_turn*(self: Game) {.base.} =source line: 269
Cleanup anything in the current turn and start the next turn.
By default, this simply changes the player number. Override this method if the game needs more to happen.
method get_move*(self: Player, game: Game): string {.base.} =source line: 191
method get_state*(self: Game): string {.base.} =source line: 324
Returns a string that is encoded to represent the current game, including who the current player is.
This method is not actually used by this library; but is used by some external AI libraries.
method is_over*(self: Game): bool {.base.} =source line: 288
Return whether or not the game is over.
method make_move*(self: Game, move: string): string {.base.} =source line: 277
Given a move (from
set_possible_moves
), apply that move to the game.This is where most of the rules of the game are coded. This method MUST be overridden.
See: https://github.com/JohnAD/turn_based_game/wiki/Game-Object-Methods#make_move
method next_player_number*(self: Game): int {.base.} =source line: 264
Return the number to the next player.
method play*(self: Game) : seq[string] {.base discardable.} =source line: 367
Start and run the game. Unless this method is overriden, this plays the game from the text console.
method restore_state*(self: Game, state: string): void {.base.} =source line: 333
Decodes the string to reset the game to the state encoded in the string.
This method is not actually used by this library; but is used by some external AI libraries.
method scoring*(self: Game): float {.base.} =source line: 316
Return a score reflecting the advantage to the current player.
This method is not actually used by this library; but is used by some external AI libraries.
method set_possible_moves*(self: Game, moves: var OrderedTable[string, string]) {.base.} =source line: 241
Set the current possible moves of the game. See https://github.com/JohnAD/turn_based_game/wiki/Game-Object-Methods#set_possible_moves
method set_possible_moves*(self: Game, moves: var seq[string]) {.base.} =source line: 235
Set the current possible moves of the game. See https://github.com/JohnAD/turn_based_game/wiki/Game-Object-Methods#set_possible_moves
method setup*(self: Game, players: seq[Player]) {.base.} =source line: 341
Setup the board; resetting all state for a new game.
See https://github.com/JohnAD/turn_based_game/wiki/Game-Object-Methods#setup
method status*(self: Game): string {.base.} =source line: 293
Return a status of the game overrall. By default, it simply returns either "game is over" or "game is active". Override this method for something more sophisticated.
method winning_player*(self: Game) : Player {.base.} =source line: 252
Return the Player who is the winner. If there is no winner, a "false" Player is returned with the name "NO WINNER YET" or "STALEMATE OR TIE"