Change sgf to use c++ streams instead of FILE, add a unit test.