From 78afdda3f0faba6037e88d7f6299ca25294a40b4 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Mon, 12 Sep 2011 18:08:23 -0700 Subject: [PATCH] doc changes to search function --- checkers.rb | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/checkers.rb b/checkers.rb index d76f9cb..6bd7517 100644 --- a/checkers.rb +++ b/checkers.rb @@ -247,25 +247,20 @@ class Board end def search(team) - @top_depth = 26 - search_do(team, @top_depth, 100.0, 0.0, "R", {TEAM_1 => -100, TEAM_2 => -100}) + search_do(team, 0, 10, 100.0, 0.0, "R", {TEAM_1 => -100, TEAM_2 => -100}) end - def search_do(team, depth, percent, last_percent, location, maxs) + # team - current player this turn + # current depth - counting up to max_depth + # max_depth - when we should stop our search + # my_percent - the percent range this work covers + # done_percent - the percent of work already done + # maxs - + def search_do(team, current_depth, max_depth, my_percent, done_percent, maxs) #puts location if depth == 0 - #puts "DONE" return score(team) end - if score(team) < maxs[team] - return score(team) - end - #if team == TEAM_1 - # puts depth.to_s + ": TEAM_1's turn:" - #else - # puts depth.to_s + ": TEAM_2's turn:" - #end - #puts to_s #moves[0].to_s if @stats[TEAM_1]['count'] == 0 puts "TEAM_2 WON!" return score(team) @@ -291,7 +286,7 @@ class Board #puts "SEARCH" 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 + if done >= 0.01 last_percent += done; puts "%.5f" % last_percent + "% depth: " + depth.to_s + " max: " + maxs.to_s done = 0.0 @@ -305,5 +300,6 @@ class Board end end end + end