Ok this is the actual inital code... need to convert from mongo to sqlite...
This commit is contained in:
parent
8c856ce465
commit
8fa1664bcb
13 changed files with 1168 additions and 0 deletions
121
testground.rb
Normal file
121
testground.rb
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
# 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
|
||||
collection_name = "testground"
|
||||
grid_size = 25
|
||||
player_num = 20
|
||||
turns = 1000
|
||||
max_damage = 100
|
||||
|
||||
$ar = nil # ActigeRpg instance
|
||||
$bets = nil
|
||||
|
||||
# call this if you want to drop all of the DB.
|
||||
def reset_all()
|
||||
$ar.get_mc().collection.drop()
|
||||
$ar.get_mc().collection().indexes.create_one(_id: 1)
|
||||
end
|
||||
|
||||
# generates a line of given length.
|
||||
def get_line(len)
|
||||
line = Array.new(1+rand(len), ".").join
|
||||
end
|
||||
|
||||
# I want to find a way to make it a bit more dynamic in
|
||||
# adding bets here.... More variations
|
||||
def place_bet(player, target)
|
||||
chance = rand(1000)
|
||||
|
||||
if chance <= 2 then
|
||||
amount = 1+rand(10)
|
||||
puts $bets.place_bet(player, target, amount)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# start of simulator code
|
||||
|
||||
puts "Starting run in collection " + collection_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, collection_name)
|
||||
|
||||
puts "Grabbing bets..."
|
||||
$bets = $ar.get_bets()
|
||||
|
||||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue