Class: XO::Engine
- Inherits:
-
StateDesignPattern::StateMachine
- Object
- StateDesignPattern::StateMachine
- XO::Engine
- Defined in:
- lib/xo/engine.rb
Overview
The Engine encapsulates the game logic for Tic-tac-toe.
It is controlled by 4 actions:
-
start
-
stop
-
play
-
continue_playing
Each action may or may not change the state of the engine. This is important because it is the state of the engine that determines when the above actions can be called.
The engine can be in 1 of 3 states:
The engine begins life in the Init state.
Here’s a table showing which actions can be called in a given state:
State | Actions
----------------------------------
Init | start
Playing | play, stop
GameOver | continue_playing, stop
Each action is defined in their respective state class.
Instance Method Summary collapse
Instance Method Details
#evaluator ⇒ Object
50 51 52 |
# File 'lib/xo/engine.rb', line 50 def evaluator Evaluator.instance end |
#initial_context ⇒ Object
46 47 48 |
# File 'lib/xo/engine.rb', line 46 def initial_context GameContext.new(:nobody, Grid.new) end |
#start_state ⇒ Object
42 43 44 |
# File 'lib/xo/engine.rb', line 42 def start_state Init end |