Class: XAndOs::GameMaster
- Inherits:
-
Object
- Object
- XAndOs::GameMaster
- Defined in:
- lib/x_and_os/game_master.rb
Instance Attribute Summary collapse
-
#board ⇒ Object
readonly
Returns the value of attribute board.
-
#marker ⇒ Object
readonly
Returns the value of attribute marker.
Instance Method Summary collapse
- #best_move(args = {}) ⇒ Object
-
#initialize(args = {}) ⇒ GameMaster
constructor
A new instance of GameMaster.
- #winning_lines ⇒ Object
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
#board ⇒ Object (readonly)
Returns the value of attribute board.
3 4 5 |
# File 'lib/x_and_os/game_master.rb', line 3 def board @board end |
#marker ⇒ Object (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_lines ⇒ Object
22 23 24 |
# File 'lib/x_and_os/game_master.rb', line 22 def winning_lines @winning_lines ||= build_winning_lines end |