Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding in a chicken version of fool

  • Loading branch information...
commit 7d620afb0412ccec5ac421248c1a7a387fac3175 1 parent d190a70
Hampton Catlin authored
View
4 README
@@ -1,4 +1,4 @@
-=== 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.
@@ -6,7 +6,7 @@ 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
2  bots/fool.rb
@@ -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
2  bots/iocaine_powder.rb
@@ -4,7 +4,7 @@
# Written by Wes
#
class IocainePowder
- include RSP::Bot
+ include RPS::Bot
FOOL_THRESHOLD = 0.5
DIE_THRESHOLD = 0.66
View
2  bots/randomizer.rb
@@ -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
2  bots/simple.rb
@@ -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
2  bots/stubborn.rb
@@ -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
15 bots/yellow_fool.rb
@@ -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
6 lib/bot.rb
@@ -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
12 lib/game.rb
@@ -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
6 lib/move.rb
@@ -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
2  lib/round.rb
@@ -1,4 +1,4 @@
-module RSP
+module RPS
class Round
attr_reader :first_player, :second_player, :first_player_move, :second_player_move, :winner
View
2  lib/rsp.rb → lib/rps.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.