プログラミングのお題スレ Part12at TECH
プログラミングのお題スレ Part12 - 暇つぶし2ch712:デフォルトの名無しさん
18/11/24 14:02:53.32 S/Hnk7Kr.net
>>687 Ruby
def input(message, cond); begin; puts message; end while cond.call; end
def janken
  hand_type = %w[g v w]
  input('Input the number of opponents.', proc{gets.to_i < 1})
  opp_number, hand, hands = $_.to_i
  loop do
    input('Input your hand.', proc{gets; false})
    hand = hand_type.index($_.chomp!)
    hands = opp_number.times.map{rand(3)}.unshift(hand)
    p hands.map.with_index{|h, i| i == 0 ? ['You', $_] : ["PC#{i}", hand_type[h]]}
    hand && hands.uniq.size == 2 ? break : puts('Draw')
  end
  puts %w[You\ Win! You\ Lose.][3 * hand / hands.uniq.sum / 2]
end
janken
# => Input the number of opponents.
1
Input your hand.
choki
[["You", "choki"], ["PC1", "g"]]
Draw
Input your hand.
w
[["You", "w"], ["PC1", "v"]]
You Lose.


次ページ
続きを表示
1を表示
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch