Newer
Older
vqmj_randomhand / vqmj_randomhand.rb
# 麻雀牌の山を作る
require 'bundler'
Bundler.require

piType = [
    (1..9).map { |i| "man#{i}" }, # 萬子
    (1..9).map { |i| "pin#{i}" }, # 筒子
    (1..9).map { |i| "sou#{i}" }, # 索子
    (1..4).map { |i| "ji#{i}" }, # 東南西北
    (5..7).map { |i| "ji#{i}" }  # 發白中
].flatten

piMnt = []
4.times do |i|
    piMnt += piType.dup
end
piMnt.shuffle!

hand = []
14.times do |i|
    hand << piMnt[i]
end

# 数牌と字牌をそれぞれ取り出してソートする
numberTiles = hand.select { |item| item.match?(/\A(man|pin|sou)/) }.sort
honorTiles = hand.select { |item| item.match?(/\Aji/) }.sort

# 数牌と字牌を結合し、並び順を整えた手牌を作る
sortedHand = numberTiles + honorTiles

imgList = sortedHand.map do |item|
    "pai-images/#{item}-66-90-l.png"
end

image = Magick::ImageList.new(*imgList)
image = image.append(false)

t = Time.now
image.write("result#{t.strftime("%Y%m%d_%H_%M_%S")}.png")