start real DFS

This commit is contained in:
Dan Ballard 2011-09-08 23:11:19 -07:00
parent 8270053048
commit 29b6987759
1 changed files with 26 additions and 4 deletions

View File

@ -233,11 +233,24 @@ class Board
return boards return boards
end 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 if team == TEAM_1
puts "TEAM_1's turn:" puts depth.to_s + ": TEAM_1's turn:"
else else
puts "TEAM_2'2 turn:" puts depth.to_s + ": TEAM_2's turn:"
end end
puts to_s #moves[0].to_s puts to_s #moves[0].to_s
if @stats[TEAM_1]['count'] == 0 if @stats[TEAM_1]['count'] == 0
@ -249,7 +262,16 @@ class Board
if moves == [] if moves == []
puts "NO MOVES AVAILABLE?" puts "NO MOVES AVAILABLE?"
else 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 end
end end