adding some max pruning... not working past depth 25?

This commit is contained in:
Dan Ballard 2011-09-12 13:44:19 -07:00
parent 5617e7f82b
commit 34bccf463f
1 changed files with 17 additions and 12 deletions

View File

@ -226,7 +226,7 @@ class Board
moves.each { |move| moves.each { |move|
board = dup() board = dup()
board.do_move(x, y, move, team(x, y)) board.do_move(x, y, move, team(x, y))
boards.push(board) boards.push( { "board" => board, "move" => move})
} }
end end
end end
@ -247,18 +247,19 @@ class Board
end end
def search(team) def search(team)
@top_depth = 10 @top_depth = 26
search_do(team, @top_depth, 100.0, 0.0, "R") search_do(team, @top_depth, 100.0, 0.0, "R", {TEAM_1 => -100, TEAM_2 => -100})
end end
def search_do(team, depth, percent, last_percent, location) def search_do(team, depth, percent, last_percent, location, maxs)
#puts location #puts location
if depth == 0 if depth == 0
#puts "DONE" #puts "DONE"
return score(team) return score(team)
end end
max = -100 if score(team) < maxs[team]
return score(team)
end
#if team == TEAM_1 #if team == TEAM_1
# puts depth.to_s + ": TEAM_1's turn:" # puts depth.to_s + ": TEAM_1's turn:"
#else #else
@ -277,26 +278,30 @@ class Board
puts "NO MOVES AVAILABLE?" puts "NO MOVES AVAILABLE?"
return score(team) return score(team)
else else
jumps = moves.find_all { |item| item['move'][0].is_a?(Array)}
if jumps.length > 0
moves = jumps
end
done = 0.0 done = 0.0
item_percent = percent/moves.length item_percent = percent/moves.length
for i in 0..moves.length-1 do for i in 0..moves.length-1 do
#moves.each { |move| #moves.each { |move|
move = moves[i] move = moves[i]['board']
#puts "SEARCH" #puts "SEARCH"
sub_score = move.search_do(opposite_team(team), depth -1, item_percent, last_percent+done, location + "." +i.to_s ) sub_score = move.search_do(opposite_team(team), depth -1, item_percent, last_percent+done, location + "." +i.to_s, maxs.dup )
done += item_percent done += item_percent
if done >= 0.0001 if done >= 0.0001
last_percent += done; last_percent += done;
puts "%.5f" % last_percent + "% depth: " + depth.to_s + " max: " + max.to_s puts "%.5f" % last_percent + "% depth: " + depth.to_s + " max: " + maxs.to_s
done = 0.0 done = 0.0
end end
#puts "Score: " + sub_score.to_s #puts "Score: " + sub_score.to_s
if sub_score > max if sub_score > maxs[team]
max = sub_score maxs[team] = sub_score
end end
end end
return max return maxs[team]
end end
end end
end end