Skip to content

Commit

Permalink
remove spam, and the sys.exit line. Seems I forgot to commit this ear…
Browse files Browse the repository at this point in the history
…lier :-P
  • Loading branch information
hughperkins committed Jan 31, 2015
1 parent be8fe33 commit b5604ef
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
11 changes: 8 additions & 3 deletions kgs_dataset_preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def addToDataFile( datafile, color, move, goBoard ):
datafile.write('GO') # write something first, so we can sync/validate on reading
datafile.write(chr(row)) # write the move
datafile.write(chr(col))
# print( 'writing move: ' + str(row) + "," + str(col))
for row in range( 0, goBoard.boardSize ):
for col in range( 0, goBoard.boardSize ):
thisbyte = 0
Expand All @@ -149,6 +150,9 @@ def addToDataFile( datafile, color, move, goBoard ):
thisbyte = thisbyte | 64
thisbyte = thisbyte | 128
datafile.write( chr(thisbyte) )
#print ( str( thisbyte - 128 ) + ' ', end= '')
#print ( '')
#print ( '')

def walkthroughSgf( datafile, sgfContents ):
sgf = gomill.sgf.Sgf_game.from_string( sgfContents )
Expand All @@ -171,14 +175,14 @@ def walkthroughSgf( datafile, sgfContents ):
#print move
goBoard.applyMove( 'b', move )
#sys.exit(-1)
#print 'handicap: ' + str(numhandicap)
# print( 'handicap: ' + str(numhandicap) )
doneFirstMove = True
#sys.exit(-1)
moveIdx = 0
for it in sgf.main_sequence_iter():
(color,move) = it.get_move()
#print 'color ' + str(color)
#print move
# print( 'color ' + str(color) )
# print( move )
if color != None and move != None:
(row,col) = move
if doneFirstMove and datafile != None:
Expand Down Expand Up @@ -233,6 +237,7 @@ def processZip( sDirectoryName, sZipfilename ):
contents = thiszip.read( name )
#print( contents )
walkthroughSgf( datafile, contents )
# sys.exit(-1)
#break
datafile.write('END')
datafile.close()
Expand Down
47 changes: 47 additions & 0 deletions scan_sizes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/python
#
# Copyright Hugh Perkins 2015 hughperkins at gmail
#
# This Source Code Form is subject to the terms of the Mozilla Public License,
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
# obtain one at http://mozilla.org/MPL/2.0/.

from __future__ import absolute_import, division, print_function

import sys,os,time, os.path
import zipfile

mydir = os.path.dirname(os.path.abspath(__file__))
print( mydir )
sys.path.append(mydir + '/gomill' )
import gomill
import gomill.sgf
#import gomill.handicap_layout

import kgs_dataset_preprocessor

def scanZip( zipfilepath ):
thiszip = zipfile.ZipFile( zipfilepath )
for name in thiszip.namelist():
#print( name )
if name.endswith('.sgf'):
sgfContents = thiszip.read( name )
#sgf = gomill.sgf.Sgf_game.from_string( sgfContents )
#print( sgfContents )
try:
size = sgfContents.split("\nSZ[")[1].split("]")[0]
if size != "19":
print( size )
except:
print( "[not known]" )
#sys.exit(-1)

def go( sTargetDirectory ):
for sZipfilename in os.listdir( sTargetDirectory ):
if sZipfilename.endswith('.zip'):
scanZip( sTargetDirectory + '/' + sZipfilename )

if __name__ == '__main__':
sTargetDirectory = 'data'
go( sTargetDirectory )

0 comments on commit b5604ef

Please sign in to comment.