Created
August 10, 2012 01:40
-
-
Save tomykaira/3310166 to your computer and use it in GitHub Desktop.
parser for WTHOR file (othello, reversi)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# parser for WTHOR file | |
# Copyrihgt (c) tomykaira 2012 | |
# Lisence: MIT | |
filenames = ARGV.length == 0 ? ["WTH_2000/WTH_2000.WTB"] : ARGV | |
CLEAN = true | |
filenames.each do |fn| | |
outputfile = fn.sub(/\.wtb$/i, ".txt") | |
next if File.exist?(outputfile) | |
File.open(fn, "rb") do |f| | |
puts fn | |
File.open(outputfile, "w") do |out| | |
header = f.read(16) | |
hands = header[4...8].unpack("L")[0] | |
hands.times do | |
game = f.read(68) | |
break if game.size < 68 | |
theo, act = game[6...8].unpack("C*") | |
hands = game[8...68].unpack("C*") | |
begin | |
line = hands.map { |h| "_ABCDEFGH"[h % 10] + (h / 10).to_s }.join('').gsub(/(_0)+\Z/, '') | |
if !CLEAN || !line.include?("_0") | |
out.puts line | |
end | |
rescue => e | |
p "error in file, ignoreing", hands | |
break | |
end | |
end | |
end | |
end | |
end |
Thanks ... runs smoothly.... good code
thank you, it really helpful 💯
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
WTHOR形式のファイルの開き方が分からなくて、困っていたのですごく助かりました!ありがとうございます