--------------010203080703070805000705
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Here is my history based solution. It tries to guess the most probable
choice based on the last few rounds and then counters that.
--------------010203080703070805000705
Content-Type: text/plain; x-mac-type="0"; x-mac-creator="0";
name
r_pattern_player.rb"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename
r_pattern_player.rb"
class DRPatternPlayer < Player
MAX_PATTERN_LENGTH
def initialize(opponent)
super
@stat }
@history ]
end
def choose
paper ock cissors
(1..MAX_PATTERN_LENGTH).each do |i|
break if i > @history.size*2
stat stat[@history[0, i*2]]
next unless stat
p tat[:paper]
r tat[:rock]
s tat[:scissors]
count p + r + s).to_f
sig p, r, s].max / count - 1.0 / 3
f ig * (1 - 1/count)
p / ount
r / ount
s / ount
if p > 0.4 && r > 0.4
r +
p
s
end
if r > 0.4 && s > 0.4
s +
r
p
end
if s > 0.4 && p > 0.4
p +
s
r
end
paper + * f
rock + * f
scissors + * f
end
case rand(3)
when 0: paper + .2
when 1: rock + .2
when 2: scissors + .2
end
paper * and()
rock * and()
scissors * and()
return :scissors if paper > rock && paper > scissors
return :paper if rock > scissors
return :rock
end
def result(you, them, result)
(1..MAX_PATTERN_LENGTH).each do |i|
break if i > @history.size*2
key history[0, i*2]
@stat[key] || :paper 0, :rock 0, :scissors 0}
@stat[key][them] +
end
@history [you, them] + @history)[0, MAX_PATTERN_LENGTH*2]
end
end
--------------010203080703070805000705--