Class: Tictactoe::Game

Inherits:
Object
  • Object
show all
Defined in:
lib/tictactoe/game.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(players_factory, board_size, x_type, o_type) ⇒ Game

Returns a new instance of Game.



10
11
12
13
14
15
16
# File 'lib/tictactoe/game.rb', line 10

def initialize(players_factory, board_size, x_type, o_type)
  self.players_factory = players_factory
  self.board_size = board_size
  self.x_type = x_type
  self.o_type = o_type
  reset
end

Instance Attribute Details

#board_sizeObject

Returns the value of attribute board_size.



8
9
10
# File 'lib/tictactoe/game.rb', line 8

def board_size
  @board_size
end

#current_playerObject

Returns the value of attribute current_player.



7
8
9
# File 'lib/tictactoe/game.rb', line 7

def current_player
  @current_player
end

#o_typeObject

Returns the value of attribute o_type.



8
9
10
# File 'lib/tictactoe/game.rb', line 8

def o_type
  @o_type
end

#stateObject

Returns the value of attribute state.



7
8
9
# File 'lib/tictactoe/game.rb', line 7

def state
  @state
end

#x_typeObject

Returns the value of attribute x_type.



8
9
10
# File 'lib/tictactoe/game.rb', line 8

def x_type
  @x_type
end

Instance Method Details

#availableObject



42
43
44
# File 'lib/tictactoe/game.rb', line 42

def available
  state.available_moves
end

#is_finished?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/tictactoe/game.rb', line 30

def is_finished?
  state.is_finished?
end

#marksObject



38
39
40
# File 'lib/tictactoe/game.rb', line 38

def marks
  state.marks
end

#ready_to_tick?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/tictactoe/game.rb', line 26

def ready_to_tick?
  !is_finished? && current_player.value.ready_to_move?
end

#tickObject



18
19
20
21
22
23
24
# File 'lib/tictactoe/game.rb', line 18

def tick
  move = get_move
  if is_valid?(move) && !is_finished?
    update_state(move)
    advance_player
  end
end

#winnerObject



34
35
36
# File 'lib/tictactoe/game.rb', line 34

def winner
  state.winner
end