#!/usr/bin/env ruby require 'othello' require 'strategy' BOARD_SIZE = 6 othello = Othello::new(BOARD_SIZE) candidates = nil user_stone = Othello::State::FIRST_STONE print "人間=先手?([y]/n)... " if $stdin.gets =~ /n/ then user_stone = user_stone.reverse end strategy = Strategy::Greedy::new while !(othello.completed?) p othello candidates = othello.candidates if candidates.empty? then othello.order_skip! puts "おけるマスがないのでパスします" else #p candidates if othello.state.order == user_stone then # 人間ターン while true begin puts "候補 : #{candidates.keys.inspect}" print "手を入力してください... " $stdin.gets =~ /(\d+),\s*(\d+)/ puts "入力 : #{$1}, #{$2}" othello.mount!([$1.to_i, $2.to_i]) break rescue puts $! #$@ end end else # コンピュータターン # 次のゲーム木生成をさぼる othello.mount!(strategy.select(othello), 1) end end end puts 'END' p othello puts "黒: #{othello.black_stones}, 白: #{othello.white_stones}"