Class: TicTacToe::Player::Human

Inherits:
Object
  • Object
show all
Includes:
MoveJson
Defined in:
lib/tic_tac_toe/players/human_player.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MoveJson

#move_json

Constructor Details

#initialize(params) ⇒ Human

Returns a new instance of Human.



11
12
13
14
# File 'lib/tic_tac_toe/players/human_player.rb', line 11

def initialize(params)
  @letter, @move = (params['letter'] || params[:letter]), 
    (params['move'] || params[:move])
end

Instance Attribute Details

#letterObject (readonly)

Returns the value of attribute letter.



8
9
10
# File 'lib/tic_tac_toe/players/human_player.rb', line 8

def letter
  @letter
end

#move=(value) ⇒ Object (writeonly)

Sets the attribute move

Parameters:

  • value

    the value to set the attribute move to.



9
10
11
# File 'lib/tic_tac_toe/players/human_player.rb', line 9

def move=(value)
  @move = value
end

Instance Method Details

#get_move(_board) ⇒ Object



16
17
18
19
20
# File 'lib/tic_tac_toe/players/human_player.rb', line 16

def get_move(_board)
  move = @move
  @move = nil
  move
end

#has_next_move?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/tic_tac_toe/players/human_player.rb', line 22

def has_next_move?
  !!@move
end

#typeObject



26
27
28
# File 'lib/tic_tac_toe/players/human_player.rb', line 26

def type
  Player::HUMAN
end