Permalink
Browse files

adding in a chicken version of fool

  • Loading branch information...
1 parent d190a70 commit 7d620afb0412ccec5ac421248c1a7a387fac3175 Hampton Catlin committed Aug 2, 2008
Showing with 38 additions and 23 deletions.
  1. +2 −2 README
  2. +1 −1 bots/fool.rb
  3. +1 −1 bots/iocaine_powder.rb
  4. +1 −1 bots/randomizer.rb
  5. +1 −1 bots/simple.rb
  6. +1 −1 bots/stubborn.rb
  7. +15 −0 bots/yellow_fool.rb
  8. +3 −3 lib/bot.rb
  9. +6 −6 lib/game.rb
  10. +3 −3 lib/move.rb
  11. +1 −1 lib/round.rb
  12. +1 −1 lib/{rsp.rb → rps.rb}
  13. +2 −2 run.rb
View
4 README
@@ -1,12 +1,12 @@
-=== Official Ruby RSP Library ===
+=== Official Ruby RPS Library ===
So, I decided to build a Ruby library to facilitate Rock, Scissors, Paper tournaments
between Ruby bots.
The API for building your own bot is extremely simple.
Look at Randomizer and Stubborn for what you need to implement. Its as simple as including
-RSP::Bot and then implementing a #next method. History of rounds is available through #history.
+RPS::Bot and then implementing a #next method. History of rounds is available through #history.
The code is ugly, but whatever. It runs. I built this in an hour.
View
@@ -6,7 +6,7 @@
# Created by Hampton Catlin (hcatlin@gmail.com)
#
class Fool
- include RSP::Bot
+ include RPS::Bot
def next
if history.any?
View
@@ -4,7 +4,7 @@
# Written by Wes
#
class IocainePowder
- include RSP::Bot
+ include RPS::Bot
FOOL_THRESHOLD = 0.5
DIE_THRESHOLD = 0.66
View
@@ -5,7 +5,7 @@
#
class Randomizer
- include RSP::Bot
+ include RPS::Bot
def next
# Gets an array of the history of the rounds so far
View
@@ -4,7 +4,7 @@
# Written by Wes
#
class Simple
- include RSP::Bot
+ include RPS::Bot
TENDANCY_THRESHOLD = 0.6
GIVE_UP_THRESHOLD = 0.66
View
@@ -4,7 +4,7 @@
# Created by Hampton Catlin (hcatlin@gmail.com)
#
class Stubborn
- include RSP::Bot
+ include RPS::Bot
def next
# good ol' rock... nothin' beats that!
View
@@ -0,0 +1,15 @@
+class YellowFool
+ include RPS::Bot
+
+ def next
+ if history.size > 100 && (history.size / game.losses(self)) > 0.5
+ if history.any?
+ history.last.other_player_move(self).beaten_by
+ else
+ moves.first
+ end
+ else
+ moves[rand(moves.size)]
+ end
+ end
+end
View
@@ -1,11 +1,11 @@
-module RSP
+module RPS
module Bot
attr_accessor :game
attr_accessor :wins, :losses
def self.included(klass)
- RSP.add(klass)
+ RPS.add(klass)
end
def initialize(game)
@@ -18,7 +18,7 @@ def history
end
def moves
- RSP::MOVES
+ RPS::MOVES
end
def to_s
View
@@ -1,9 +1,9 @@
-module RSP
+module RPS
class Game
attr_reader :history, :first_player, :second_player, :first_player_wins, :second_player_wins, :ties
def initialize(first_player_klass, second_player_klass, options = {})
- @rounds_to_run = options[:rounds_to_run] || 2500
+ @rounds_to_run = options[:rounds_to_run] || 1000
@verbose = options[:verbose] || false
@first_player, @second_player = first_player_klass.new(self), second_player_klass.new(self)
@first_player_wins, @second_player_wins, @ties = 0, 0, 0
@@ -13,14 +13,14 @@ def execute
@history = []
@rounds_to_run.times do |count|
puts "------- ROUND #{count + 1} ------------" if @verbose
- round = RSP::Round.new(@first_player, @second_player)
- @history << round
+ round = RPS::Round.new(first_player, second_player)
+ history << round
if round.winner == first_player
@first_player_wins += 1
elsif round.winner == second_player
@second_player_wins += 1
else
- @ties = ties + 1
+ @ties += 1
end
puts round if @verbose
@@ -39,7 +39,7 @@ def losses(player)
end
def winner
- must_win_by = (0.02 * @rounds_to_run).to_i
+ must_win_by = (0.05 * @rounds_to_run).to_i
if (first_player_wins - must_win_by) > second_player_wins
first_player
elsif first_player_wins < (second_player_wins - must_win_by)
View
@@ -1,4 +1,4 @@
-module RSP
+module RPS
class Move
include Comparable
@@ -9,11 +9,11 @@ def initialize(name, beaten_by_sym)
end
def beats
- @beats ||= (RSP::MOVES.find { |m| m.beaten_by_sym == self.name })
+ @beats ||= (RPS::MOVES.find { |m| m.beaten_by_sym == self.name })
end
def beaten_by
- @beats ||= (RSP::MOVES.find { |m| m.name == self.beaten_by_sym })
+ @beats ||= (RPS::MOVES.find { |m| m.name == self.beaten_by_sym })
end
def to_s
View
@@ -1,4 +1,4 @@
-module RSP
+module RPS
class Round
attr_reader :first_player, :second_player, :first_player_move, :second_player_move, :winner
@@ -1,6 +1,6 @@
require 'lib/move'
-module RSP
+module RPS
MOVES = [Move.new(:rock, :paper), Move.new(:scissors, :rock), Move.new(:paper, :scissors)].freeze
@@bots = []
View
4 run.rb
@@ -1,5 +1,5 @@
#!/usr/bin/env ruby
-require 'lib/rsp'
+require 'lib/rps'
require 'lib/bot'
require 'lib/move'
require 'lib/round'
@@ -10,4 +10,4 @@
end
-RSP.run ARGV
+RPS.run ARGV

0 comments on commit 7d620af

Please sign in to comment.