Concepts
Wrapping your head around these concepts will mean you're ready to make full use of CentriFuGe.
State
CentriFuGe captures the state of a game through a game_state and context
class_name PartialGameState
extends Resource
@export var game_state: GameState
@export var ctx: Context
The state of the game at a given point in time. This is split up into two variables game_state and context. game_state is like taking a physical picture of the table you're playing the game at. It shows where every card currently is. The context is an engine-facing structure which holds the information about how the card game is changing. These are things not visible, such as whose turn it is, and who is going to play next.
Every game should have it's own GameState derrived class, which stores everything the board game has. Things like decks, discard piles, hands. Also player activities, like if a trap card was played this turn, and the next player's turn needs to respond.
Aside: Every variable within the GameState should be
@export'ed, as in@export var foo. This is so the variable is copied when the game state changes.
Events
Events are framework-controled actions that alter the context. Events are actions like end turn end phase and end game. These are often not called directly, but trigged by implementing the end_if() function of the phase/turn. When this end_if condition is true, the phase/turn ends and the next begins.
Moves
Moves are what you define as actions available for your game. Moves interact with the game_state, doing things like moving cards around the board. Consider a move as some complete action, one in which you can undo.
class_name UserMoveDraw
extends GameMove
## Any specific variables that this move can have as a variable
var num_to_draw := 1
func _to_string() -> String:
return "Draw Move"
func _init(player_id_: String, num_to_draw_ := num_to_draw) -> void:
super._init(player_id_)
num_to_draw = num_to_draw_
func execute(state: PartialGameState) -> bool:
Whatever you would like this move to do.
return newly altered game state
A benefit of this implementation is that move undo is a free activity. There is no need to program how to undo a move, it simply works. (Works by loading a previous game state.)
Phases
Phases are the broads strokes of how a card game progresses. Each phase can have a different set of moves available to play, and a different progression of turn ordering. Simple card games may only have a single type of phase. Others might include an initial 'draw' phase where cards are drawn from the deck, followed by a 'play' phase where those cards are placed onto the board.
Turns
Within a phase the players play out their turns. How the turns progress is controlled by the phase and/or context. During a turn only the player whose turn it is can act. Currently there is no way to have other players make moves during someone else's turn. However, stages, something within a turn, is planned to be implemented.