Module: NeuroGammon::BoardTools

Included in:
FannPlayer
Defined in:
lib/neuro_gammon/board_tools.rb

Instance Method Summary collapse

Instance Method Details

#reverse_state(state) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/neuro_gammon/board_tools.rb', line 10

def reverse_state state
  #first reverse all the colours (except the bar)
  new_state=[]
  new_state[0]=[]
  new_state[1]=[]
  state[0].each_index do |i|
    new_state[0] << state[0][i]*-1
  end
  
  state[1].each_index do |i|
    new_state[1] << state[1][i]
  end
  
  new_state[0].reverse!
  new_state[1].reverse!
  return new_state
end

#test_for_gammon(state, colour) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/neuro_gammon/board_tools.rb', line 28

def test_for_gammon state,colour
  on_bar= (colour==Board::WHITE ? state[1][0] != 0 : state[1][1] != 0)
  on_board= state[0].find() {|x| x*colour>0}
  return false if (on_board or on_bar)
  blank=state.flatten.find {|x| x!=0}.nil?
  return false if blank 
  if state[1].find() {|x| x!=0}
    return false if colour==Board::WHITE ? state[1][0]!=0 : state[1][1]!=0
  end
  
  range=colour==Board::WHITE ? (18..23) : (0..5)
  return range.find(){|x| state[0][x]*(-colour) > 0} == nil
  
end