adding some max pruning... not working past depth 25?
This commit is contained in:
parent
5617e7f82b
commit
34bccf463f
29
checkers.rb
29
checkers.rb
|
@ -226,7 +226,7 @@ class Board
|
|||
moves.each { |move|
|
||||
board = dup()
|
||||
board.do_move(x, y, move, team(x, y))
|
||||
boards.push(board)
|
||||
boards.push( { "board" => board, "move" => move})
|
||||
}
|
||||
end
|
||||
end
|
||||
|
@ -247,18 +247,19 @@ class Board
|
|||
end
|
||||
|
||||
def search(team)
|
||||
@top_depth = 10
|
||||
search_do(team, @top_depth, 100.0, 0.0, "R")
|
||||
@top_depth = 26
|
||||
search_do(team, @top_depth, 100.0, 0.0, "R", {TEAM_1 => -100, TEAM_2 => -100})
|
||||
end
|
||||
|
||||
def search_do(team, depth, percent, last_percent, location)
|
||||
def search_do(team, depth, percent, last_percent, location, maxs)
|
||||
#puts location
|
||||
if depth == 0
|
||||
#puts "DONE"
|
||||
return score(team)
|
||||
end
|
||||
max = -100
|
||||
|
||||
if score(team) < maxs[team]
|
||||
return score(team)
|
||||
end
|
||||
#if team == TEAM_1
|
||||
# puts depth.to_s + ": TEAM_1's turn:"
|
||||
#else
|
||||
|
@ -277,26 +278,30 @@ class Board
|
|||
puts "NO MOVES AVAILABLE?"
|
||||
return score(team)
|
||||
else
|
||||
jumps = moves.find_all { |item| item['move'][0].is_a?(Array)}
|
||||
if jumps.length > 0
|
||||
moves = jumps
|
||||
end
|
||||
done = 0.0
|
||||
item_percent = percent/moves.length
|
||||
|
||||
for i in 0..moves.length-1 do
|
||||
#moves.each { |move|
|
||||
move = moves[i]
|
||||
move = moves[i]['board']
|
||||
#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
|
||||
if done >= 0.0001
|
||||
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
|
||||
end
|
||||
#puts "Score: " + sub_score.to_s
|
||||
if sub_score > max
|
||||
max = sub_score
|
||||
if sub_score > maxs[team]
|
||||
maxs[team] = sub_score
|
||||
end
|
||||
end
|
||||
return max
|
||||
return maxs[team]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue