Last active
August 29, 2015 13:56
-
-
Save berlysia/8887740 to your computer and use it in GitHub Desktop.
MH4でざっくり武器をルーレットする
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# encoding: utf-8 | |
class MH4roulette | |
def initialize | |
@names = %w[player1 player2 player3 player4] | |
@slash = %w[片手剣 大剣 太刀 双剣 ランス ガンランス スラッシュアックス チャージアックス 操虫棍].freeze | |
@strike = %w[ハンマー 狩猟笛 操虫棍].freeze | |
@shoot = %w[弓 ライトボウガン ヘビィボウガン].freeze | |
@history = [] | |
@omit_same_weapon_threshold = 3 | |
loop do | |
puts '(人数:1..4) [dup, no-slash, no-strike, no-shoot]' | |
puts 'setname name1 name2 name3 name4' | |
puts '' | |
tmp = gets.split(' ') | |
if tmp[0] == 'setname' | |
hoge = tmp[1..-1] | |
hoge << nil while hoge.size < 4 | |
@names = hoge | |
puts '' | |
end | |
roulette(*tmp) if (1..4).include? tmp[0].to_i | |
end | |
end | |
def roulette(number, *flags) | |
number = number.to_i | |
history_watched = [] | |
(1..@omit_same_weapon_threshold).each do |i| | |
history_watched.push @history[-i] if @history[-i] | |
end | |
history_watched = history_watched.transpose | |
weapon_list = [] | |
weapon_list += @slash unless flags.include? 'no-slash' | |
weapon_list += @strike unless flags.include? 'no-strike' | |
weapon_list += @shoot unless flags.include? 'no-shoot' | |
weapon_list.flatten! | |
return puts 'we need weapons!' if weapon_list.empty? | |
chosen_weapons = [] | |
(1..number).each do |i| | |
pool = weapon_list - (history_watched[i-1] || []) | |
chosen = pool.sample | |
weapon_list.delete(chosen) unless flags.include? 'dup' | |
chosen_weapons << chosen | |
end | |
chosen_weapons << nil while chosen_weapons.size < 4 | |
@history.push chosen_weapons | |
puts [@names, chosen_weapons].transpose.map{|r|r.join(': ')} | |
puts '' | |
end | |
end | |
if __FILE__ == $0 | |
MH4roulette.new | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment