#!/usr/bin/env ruby # -*- coding: utf-8 -*- print "あなたは先手にしますか後手にしますか?(先手=1 後手=2)" answer = gets.chomp.to_i if answer == 1 then match = 15 print "1から3本の範囲でマッチ棒を取ります。最後の1本を取った方の負け!\n" while match > 0 printf("あなたの番: マッチ棒が%d本あります\n", match) print "何本取りますか?(1..3): " toru = gets.chomp.to_i if toru < 1 || toru > 3 then print "1から3の範囲で取って下さい.\n" redo end match -= toru if match < 1 then print "最後の1本を取りました。あなたの負けです! \n" break end printf("わたしの番: マッチ棒が%d本あります\n", match) com_toru = 3-toru+1 printf("私は%d本取りました。\n", com_toru) match -= com_toru if match < 1 then print "最後の1本を取りました。わたしの負けです!\n" break end end elsif answer == 2 match = 17 print "1から3本の範囲でマッチ棒を取ります。最後の1本を取った方の負け!\n" print"私コンピュータが1本取ります\n" while match > 0 printf("あなたの番: マッチ棒が%d本あります\n", match) print "何本取りますか?(1..3): " toru = gets.chomp.to_i if toru < 1 || toru > 3 then print "1から3の範囲で取って下さい.\n" redo end match -= toru if match < 1 then print "最後の1本を取りました。あなたの負けです! \n" break end printf("わたしの番: マッチ棒が%d本あります\n", match) com_toru = 3-toru+1 printf("私は%d本取りました。\n", com_toru) match -= com_toru if match < 1 then print "最後の1本を取りました。わたしの負けです!\n" break end end else print "ちゃんと選んでね\n"