start real DFS
This commit is contained in:
parent
8270053048
commit
29b6987759
30
checkers.rb
30
checkers.rb
|
@ -233,11 +233,24 @@ class Board
|
|||
return boards
|
||||
end
|
||||
|
||||
def run_1st_path(team)
|
||||
def search(team)
|
||||
@top_depth = 100
|
||||
search_do(team, @top_depth)
|
||||
end
|
||||
|
||||
def search_do(team, depth)
|
||||
if depth == 0
|
||||
puts "DONE"
|
||||
return {TEAM_1 => @stats[TEAM_1]['count'], TEAM_2 => @stats[TEAM_2]['count']}
|
||||
end
|
||||
|
||||
max = @stats[team]['count']
|
||||
min = 0
|
||||
|
||||
if team == TEAM_1
|
||||
puts "TEAM_1's turn:"
|
||||
puts depth.to_s + ": TEAM_1's turn:"
|
||||
else
|
||||
puts "TEAM_2'2 turn:"
|
||||
puts depth.to_s + ": TEAM_2's turn:"
|
||||
end
|
||||
puts to_s #moves[0].to_s
|
||||
if @stats[TEAM_1]['count'] == 0
|
||||
|
@ -249,7 +262,16 @@ class Board
|
|||
if moves == []
|
||||
puts "NO MOVES AVAILABLE?"
|
||||
else
|
||||
moves[0].run_1st_path(opposite_team(team))
|
||||
results = moves[0].search_do(opposite_team(team), depth -1)
|
||||
if results[opposite_team(team)] == 0
|
||||
return {team => max, opposite_team(team) => 0}
|
||||
elsif results[team] == max
|
||||
return {team => max, opposite_team(team) => results[opposite_team(team)]}
|
||||
else
|
||||
if results[team] > min
|
||||
min = results[team]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue