LoopholeAbuser
@rules = {
'L' => %w[V P],
'P' => %w[V R],
'R' => %w[L S],
'S' => %w[P L],
'V' => %w[R S]
}
@moves = @rules.keys
def defeats?(move1, move2)
@rules[move1].include?(move2)
end
def score(move1, move2)
if move1 == move2
0
elsif defeats?(move1, move2)
1
else
-1
end
end
def move
player, opponent = ARGV
case player.to_s.size
when 0
'P'
when 1
'R'*100
when 2
'L'
when 3
'S'
when 4
'V'
else
extrapolate(player, opponent)
end
end
def extrapolate(player,opponent)
likelihoods = Hash.new {0}
opponent_last_move = opponent[-1]
@moves.each { |m| likelihoods[m] += opponent.scan(opponent_last_move + m).size }
my_last_move = player[-1]
reactions = player.chars.zip(opponent.chars.drop(1))
@moves.each { |m| likelihoods[m] += reactions.count([my_last_move, m]) }
@moves.shuffle.max_by do |m|
likelihoods.map{ |n,c| score(m,n) * c }.reduce(:+)
end
end
puts move
Just doing these because for once I want to get to the loopholes before other people. If you consider this to be legal (it doesn't throw an error or cause an opponent to throw an error, but it does forfeit a round), run with ruby loophole_abuser.rb
.