Skip to content

Instantly share code, notes, and snippets.

@tomykaira
Created August 10, 2012 01:40
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomykaira/3310166 to your computer and use it in GitHub Desktop.
Save tomykaira/3310166 to your computer and use it in GitHub Desktop.
parser for WTHOR file (othello, reversi)
#!/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
@nwtgck
Copy link

nwtgck commented Apr 25, 2016

WTHOR形式のファイルの開き方が分からなくて、困っていたのですごく助かりました!ありがとうございます

@ayushmaan
Copy link

Thanks ... runs smoothly.... good code

@lin-nguyen
Copy link

thank you, it really helpful 💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment