GameOfGame/src/game/climate_change.cr

78 lines
2.0 KiB
Crystal

require "../*"
# require "../ai/*"
require "../rules_set/climate"
include GameOfGame
ROUNDS = 1000
all_ai = [] of Ai
2.times do
add_ai = [
Climate::FullProd.new,
Climate::FullProd.new,
Climate::LinearReducer.new(zero_net: ROUNDS * 2.0),
Climate::LinearReducer.new(zero_net: ROUNDS * 2.0),
Climate::LinearReducer.new(zero_net: ROUNDS * 1.0),
Climate::LinearReducer.new(zero_net: ROUNDS * 1.0),
Climate::LinearReducer.new(zero_net: ROUNDS * 1.0),
Climate::LinearReducer.new(zero_net: ROUNDS * 1.0),
Climate::LinearReducer.new(zero_net: ROUNDS * 0.9),
Climate::LinearReducer.new(zero_net: ROUNDS * 0.9),
Climate::LinearReducer.new(zero_net: ROUNDS * 0.9),
Climate::LinearReducer.new(zero_net: ROUNDS * 0.5),
Climate::LinearReducer.new(zero_net: ROUNDS * 0.5),
Climate::LinearReducer.new(zero_net: ROUNDS * 0.2),
Climate::FullNature.new,
] of Ai
all_ai += add_ai
end
raise "Empty players set" if all_ai.empty?
puts "Playing with:"
all_ai.each { |player| puts "#{player.name}" }
puts
total_scoring = Hash(Ai, Float64).new
all_ai.each { |player| total_scoring[player] = 0.0 }
total_victories = Hash(Ai, Int32).new
all_ai.each { |player| total_victories[player] = 0 }
GAMES = 1000
GAMES.times do
game = Game.new(
players: all_ai,
rules: Climate::Version01.new(rounds_amount: ROUNDS, players: all_ai),
verbose: false,
)
ROUNDS.times do |i|
# puts "Play round #{i}"
game.play
end
results = game.rounds.total.to_a.sort_by {|t| -t[1]}
winner = results[0][0]
game.rounds.total.each { |player, score| total_scoring[player] += score }
total_victories[winner] += 1
# puts
# puts "Winner is #{winner.name}, scores:"
# results.each do |tuple|
# puts "#{tuple[0].name}: #{tuple[1]}"
# end
end
puts
puts "=== Score by victories ==="
total_victories.to_a.sort_by {|t| -t[1]}.each.with_index do |t, i|
puts "#{i}. #{t[0].name}: #{t[1]}"
end
puts
puts "=== Score by points ==="
total_scoring.to_a.sort_by {|t| -t[1]}.each.with_index do |t, i|
puts "#{i}. #{t[0].name}: #{t[1]}"
end