# This is a very bodged together wrapper that lets you spin up an # instance of ActiveRpg in its own little sandbox. Randomly generates # lots of potential turns/players/monsters/bets/whatevers load "active_rpg.rb" #configgy bits db_name = "testground" grid_size = 25 player_num = 20 turns = 1000 max_damage = 100 $ar = nil # ActigeRpg instance # call this if you want to drop all of the DB. def reset_all() puts "Trying to null out the players/entities tables..." sql = $ar.get_sql_connect puts sql.inspect sql.query("DROP TABLE IF EXISTS players;") sql.query("DROP TABLE IF EXISTS entities;") sql.query("CREATE TABLE players(id INT PRIMARY KEY, name TEXT NOT NULL UNIQUE);") sql.query("CREATE TABLE entities(id INT PRIMARY KEY);") end # generates a line of given length. def get_line(len) line = Array.new(1+rand(len), ".").join end # start of simulator code puts "Starting run in collection " + db_name + ", " + grid_size.to_s + " grid." puts player_num.to_s + " players, " + turns.to_s + " turns, " + max_damage.to_s + " max damage." puts "Creating ActiveRpg" $ar = ActiveRpg.new(grid_size, db_name) puts "Dropping and building index on the collection" reset_all() players = [] puts "Creating players..." for x in 1..player_num do # this should be the basis of aw.take_turn()... players.push(name = (0...8).map { (65 + rand(26)).chr }.join) end puts players.inspect puts "Starting turns..." for t in 1..turns do players.each do |p| res = $ar.take_turn(p, get_line(max_damage)) if res.to_s != "" then puts res end place_bet(p, players.sample) end end # end of simluation code. Below prints out a summary of it. puts "FINISHED!\n\n" print "SUMMARY for " + collection_name + ", grid=" + grid_size.to_s + ". " print player_num.to_s + " players, " + turns.to_s + " turns, " + max_damage.to_s + " max damage!" puts final_players = $ar.get_mc().collection().find({"type" => :player}) puts "Players: " + final_players.count.to_s final_players.each do |p| puts p['name'] + ": " + p['location'].inspect + "; " + p['exp'].to_s + "xp; last_line: " + p['last_line'] end puts final_monsters = $ar.get_mc().collection().find({"type" => :monster}) puts "Monsters: " + final_monsters.count.to_s puts final_bosses = $ar.get_mc().collection().find({"type" => :boss}) puts "Bosses: " + final_bosses.count.to_s final_bosses.each do |b| puts b['name'] + ": " + b['location'].inspect + "; " + b['exp'].to_s + "xp; " + b['last_line'] + "; " + b['spawned_by'] end puts final_events = $ar.get_mc().collection().find({"type" => :random_event}) puts "Events: " + final_events.count.to_s final_events.each do |e| puts e['name'] + ": " + e['location'].inspect end puts open_bets = 0 raw_bets = [] final_players.each do |p| player_bets = $bets.get_player_bets(p['name']) open_bets = open_bets + player_bets.count raw_bets.push(player_bets) end puts raw_bets.inspect puts "Open bets: " + open_bets.to_s