Class: Checkers::Game::Engine
- Inherits:
-
Object
- Object
- Checkers::Game::Engine
- Defined in:
- lib/checkers/game/engine.rb
Instance Method Summary collapse
-
#initialize(state, ai_engine) ⇒ Engine
constructor
A new instance of Engine.
- #play ⇒ Object
Constructor Details
#initialize(state, ai_engine) ⇒ Engine
Returns a new instance of Engine.
6 7 8 9 |
# File 'lib/checkers/game/engine.rb', line 6 def initialize(state, ai_engine) @state = state @ai = ai_engine end |
Instance Method Details
#play ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/checkers/game/engine.rb', line 11 def play return if @state.winner || @state.tie if @state.turn == :ai new_board = @ai.next_board(@state.board) turn = if new_board.jumped new_board.any_jump_moves?(player: :ai) ? :ai : :human else :human end @state.set_state(board: new_board, turn: turn) end end |