Class: NeuroGammon::BaseNeuralPlayer

Inherits:
BasePlayer show all
Defined in:
lib/neuro_gammon/base_neural_player.rb

Direct Known Subclasses

FannPlayer

Instance Attribute Summary collapse

Attributes inherited from BasePlayer

#id, #name

Instance Method Summary collapse

Constructor Details

#initializeBaseNeuralPlayer

Returns a new instance of BaseNeuralPlayer.



14
15
16
17
# File 'lib/neuro_gammon/base_neural_player.rb', line 14

def initialize
  super
  init_net
end

Instance Attribute Details

#hidden_layersObject (readonly)

Returns the value of attribute hidden_layers.



12
13
14
# File 'lib/neuro_gammon/base_neural_player.rb', line 12

def hidden_layers
  @hidden_layers
end

#learning_rateObject (readonly)

Returns the value of attribute learning_rate.



11
12
13
# File 'lib/neuro_gammon/base_neural_player.rb', line 11

def learning_rate
  @learning_rate
end

#n_inputsObject (readonly)

Returns the value of attribute n_inputs.



9
10
11
# File 'lib/neuro_gammon/base_neural_player.rb', line 9

def n_inputs
  @n_inputs
end

#n_outputsObject (readonly)

Returns the value of attribute n_outputs.



10
11
12
# File 'lib/neuro_gammon/base_neural_player.rb', line 10

def n_outputs
  @n_outputs
end

Instance Method Details

#suggest_move(board, dice, colour) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/neuro_gammon/base_neural_player.rb', line 19

def suggest_move board,dice,colour
  moves=board.valid_moves(colour, dice)
  best_move=nil
  best_score=-99
  moves.each do |move|
    new_board_state=board.move(move,colour)
    inp=generate_input_pattern(new_board_state)
    out=run_net(inp)
    score=evaluate_output(out,board,dice,colour)
    if score>best_score
      best_move=move
      best_score=score
    end
  end
  return best_move
end