#!/usr/bin/env ruby require 'othello' require 'strategy' class Trainer def initialize(board_size, detail = false, strategy = Strategy::Boltzmann::new) # 戦略がBoltzmannだったらゲーム木生成をさぼる othello = Othello::new(board_size, (strategy.lazy? ? 1 : nil)) log = [] candidates = nil while !(othello.completed?) selected = strategy.select(othello) othello.mount!(selected, (strategy.lazy? ? 1 : nil)) log << othello.state p othello if detail puts end p othello puts "黒: #{othello.black_stones}, 白: #{othello.white_stones}" yield(log, [othello.black_stones, othello.white_stones]) if block_given? end end if $0 == __FILE__ then BOARD_SIZE = 6 Trainer::new(BOARD_SIZE, true) exit LOG_FILE_PREFIX = 'random2_1000' for i in (0...10) logs = [] for j in (0...1000) Trainer::new(BOARD_SIZE, true){|log, result| logs << [log, result]} end open("#{LOG_FILE_PREFIX}_#{i}.dat", 'w'){|file| file << Marshal::dump(logs)} end #strategy = Strategy::Greedy #Trainer::new(BOARD_SIZE, true, strategy){|log, result| p log, result} end