Class: XAndOs::GameMaster

Inherits:
Object
  • Object
show all
Defined in:
lib/x_and_os/game_master.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ GameMaster

Returns a new instance of GameMaster.



4
5
6
7
8
# File 'lib/x_and_os/game_master.rb', line 4

def initialize(args = {})
  @board      = args[:board]
  @marker     = args[:marker]
  @move_args  = {}
end

Instance Attribute Details

#boardObject (readonly)

Returns the value of attribute board.



3
4
5
# File 'lib/x_and_os/game_master.rb', line 3

def board
  @board
end

#markerObject (readonly)

Returns the value of attribute marker.



3
4
5
# File 'lib/x_and_os/game_master.rb', line 3

def marker
  @marker
end

Instance Method Details

#best_move(args = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/x_and_os/game_master.rb', line 10

def best_move(args={})
  @move_args = args
  move = win || block || fork_move || force_block || block_fork
  return move if move

  if first_move
    1
  else
    center || corner || available_moves.sample
  end
end

#winning_linesObject



22
23
24
# File 'lib/x_and_os/game_master.rb', line 22

def winning_lines
  @winning_lines ||= build_winning_lines
end