Skip to content

Commit

Permalink
delete partial solution and try a new apporach
Browse files Browse the repository at this point in the history
  • Loading branch information
IanDCarroll committed Jul 3, 2017
1 parent 4a92363 commit 61f3ad3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 364 deletions.
45 changes: 4 additions & 41 deletions lib/ai/minimax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,52 +23,15 @@ def available_spaces

# recursion dependent ==v

def score_spaces(spaces = @spaces)
@recursion_depth += 1
scored_spaces = spaces
available_spaces.each do |space|
scored_spaces[space] = score_space(space)
end
@recursion_depth -= 1
scored_spaces
end

def score_space(space)
scenario = report(space)
if scenario == @const.winner(@const.players[1]) then return 1
elsif scenario == @const.winner(@const.players[0]) then return -1
elsif scenario == @const.draw then return 0
else 2 end
end

def report(space)
@judge.report({ space: space,
board: trial_spaces(space) })
end

def trial_spaces(space)
trial_spaces = @spaces.dup
trial_spaces[space] = appropriate_player
trial_spaces
end

def appropriate_player
@recursion_depth.odd? ? @const.players[1] : @const.players[0]
end

# recursion_dependent ==^

def make_ultimate_choice(scored_spaces)
ultimate_choice = "no ultimate choice made"
best_score_so_far = -1
scored_spaces.each do |space|
unless space.instance_of?(String)
if space >= best_score_so_far
best_score_so_far = space
ultimate_choice = scored_spaces.index(space)
end
end
end
ultimate_choice


def appropriate_player
@recursion_depth.odd? ? @const.players[1] : @const.players[0]
end
end
Loading

0 comments on commit 61f3ad3

Please sign in to comment.