Skip to content

Commit

Permalink
multi run and results
Browse files Browse the repository at this point in the history
  • Loading branch information
Reed Law committed Apr 12, 2012
1 parent 2f24b4c commit 085f657
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 19 deletions.
23 changes: 22 additions & 1 deletion README.md
Expand Up @@ -25,6 +25,12 @@ The `select` is to ensure the player is not fighting itself.

There is also a method `alive` that returns false if the player is dead.

Rules
-----

1. No cheating by overriding classes or instance variables.
2. Cheating players will be moved to the cheaters/ directory.

Running the simulation
----------------------

Expand All @@ -33,4 +39,19 @@ Running the simulation
Winning
-------

The player with the highest level and experience wins.
The player with the highest level and experience wins.

Winners
-------

The game can be run 1000 times using `./multi_run.rb`

On it's last run these were the results:

Eric the Kill Steal won 272 times
strax won 247 times
A Tabby Cat won 226 times
Ian Terrell won 185 times
Valentin won 39 times
Izidor won 21 times
*No rest for the wicked* won 10 times
21 changes: 3 additions & 18 deletions engine.rb
@@ -1,22 +1,16 @@
#!/usr/bin/env ruby
require 'debugger'



#This creates the require_dir method that is used for requiring the engine, players, and monsters directories below
def require_dir(dir)
Dir["#{dir}/*.rb"].each do |file|
require File.join(File.dirname(__FILE__), file )
end
end


#This requires the engine directory
require_dir("engine")



#I don't know what this does
modules = []
ObjectSpace.each_object(Module) {|m| modules << m.name } #Traverses all objects that are modules or subclasses of modules
#And adds them to the modules array
Expand All @@ -27,29 +21,23 @@ def require_dir(dir)
player_modules << m.name unless modules.include?(m.name)
end


#IThis imports the monsters directory
require_dir("monsters")


#This creates a new Game object
game = Game.new



player_modules.each do |m|
constant = Object
player = Player.new
game.players << player #adds each player to the game's player array


p = PlayerProxy.new(player) #I'm not sure what the player proxy is
p.extend constant.const_get(m)
player.proxy = p
game.proxies << p
end


#This generates new monsters
20.times do
monster = Monster.new
Expand All @@ -60,16 +48,13 @@ def require_dir(dir)
game.proxies << r
end


#Rreceive the round count, and does something with a regex for any other command line arguments
if ARGV.size > 1 and ARGV[0] == "-r" and ARGV[1] =~ /^[1-9]\d*$/
ARGV.shift
rount_count = ARGV.shift.to_i
round_count = ARGV.shift.to_i
else
rount_count = 10
round_count = 10
end



#This iterates the rounds
game.round(rount_count)
game.round(round_count)
18 changes: 18 additions & 0 deletions multi_run.rb
@@ -0,0 +1,18 @@
#!/usr/bin/env ruby

last_line = []

1000.times do
output = `ruby ./engine.rb`
last_line.push output.split("\n").last
end

winners = Hash.new(0)

last_line.each do |val|
winners[val] += 1
end

winners.sort_by{|winner, times| -times}.each do |winner, times|
puts "#{winner.gsub(' is the winner!', '')} won #{times} times"
end

0 comments on commit 085f657

Please sign in to comment.