Changeset - e7fafcf5b27a
[Not reviewed]
default
4 0 8
Laman - 9 years ago 2016-08-14 12:24:24

started testing
8 files changed with 63 insertions and 11 deletions:
0 comments (0 inline, 0 general)
src/diana/__init__.py
Show inline comments
 
new file 100644
src/diana/diana.py
Show inline comments
 
file renamed from src/diana.py to src/diana/diana.py
 
import sys
 
import os
 
import re
 
import go
 
import os
 
import sgf
 
import sys
 
 
import diana.sgf as sgf
 
import diana.go as go
 
 
if len(sys.argv)>1:
 
	files=sys.argv[1:]
 
else:
 
	sys.exit("no input file specified")
 
 
movesPerDiagram=75
 
minMovesPerDiagram=10
 
 
t=sys.stdout
 
c=28
 
padding=15
 
highNumbers=True
 
 
class Svg:
 
	content=""
 
	footer=""
 
	extension="svg"
 
 
	padding=15
 
	gridSize=28
 
	highNumbers=True
 
	
 
	def __init__(self):
 
		self.content='''<?xml version="1.0" standalone="no"?>
 
<svg width="{0}" height="{0}" version="1.1" xmlns="http://www.w3.org/2000/svg" alignment-baseline="center">
 
	<defs>
 
		<style type="text/css"><![CDATA[
 
		text{{font-family:"DejaVu Sans";text-anchor:middle;}}
 
		line{{stroke:black;stroke-width:0.7}}
 
		circle{{stroke:black}}
 
		.b{{fill:black}}
 
		.w{{fill:white}}
 
		]]></style>
 
	</defs>
 
	<rect width="{0}" height="{0}" x="0" y="0" style="fill:white;stroke:white"/>\n'''.format(2*self.padding+18*self.gridSize)
 
		self.footer="</svg>\n"
 
 
		grid='  <line x1="{0}" x2="{1}" y1="{2}" y2="{3}" />\n'
 
 
		# okraje desky
 
		for i in (0,18):
 
			self.content+='  <line x1="{0}" x2="{1}" y1="{2}" y2="{3}" style="stroke-width:1"/>\n'.format(self.padding, 18*self.gridSize+self.padding, self.gridSize*i+self.padding, self.gridSize*i+self.padding)
 
			self.content+='  <line x1="{0}" x2="{1}" y1="{2}" y2="{3}" style="stroke-width:1"/>\n'.format(self.gridSize*i+self.padding, self.gridSize*i+self.padding, self.padding, 18*self.gridSize+self.padding)
 
		
 
		# mřížka
 
		for i in range(1,18):
 
			self.content+=grid.format(padding, 18*c+padding, c*i+padding, c*i+padding)
src/diana/go.py
Show inline comments
 
file renamed from src/go.py to src/diana/go.py
src/diana/sgf.py
Show inline comments
 
file renamed from src/sgf.py to src/diana/sgf.py
 
@@ -445,99 +445,96 @@ def propValue(str):
 
 
class propValue:
 
	pass
 
 
def cValueType(str,start):
 
	matches=[real,number,double,color,simpleText]
 
	for f in matches:
 
		i,x=f(str,start)
 
		if x is not None: return i,x
 
	return 1/0
 
 
def number(str,start):
 
	r=re.compile(r"(\+|-|)\d+")
 
	m=r.match(str,start)
 
	if m is None: return (-1,None)
 
	x=int(m.group(0))
 
	return (m.end(),x)
 
 
def real(str):
 
	m=re.match(r"(\+|-|)\d+(\.\d+)?",str)
 
	if m is None: return -1
 
	return m.end()
 
 
def double(str):
 
	m=re.match(r"1|2",str)
 
	if m is None: return -1
 
	return m.end()
 
	
 
def color(str):
 
	m=re.match(r"B|W",str)
 
	if m is None: return -1
 
	return m.end()
 
	
 
def simpleText(str):
 
	res=r""
 
	esc=False
 
	for c in str:
 
		if esc:
 
			res+=c
 
			esc=False
 
		elif c=="\\":
 
			esc=True
 
		elif c=="]":
 
			break
 
		else:
 
			res+=c
 
	return res"""
 
 
sgf=open("in/1-Hora-Simara.sgf").read()
 
 
x=Collection(sgf)
 
 
# TODO:
 
# date
 
 
 
"""
 
# move
 
B	move
 
KO	none
 
MN	number
 
W	move
 
 
# setup
 
AB	list of stone
 
AE	list of point
 
AW	list of stone
 
PL	color
 
 
# node annotation
 
C	text
 
DM	double
 
GB	double
 
GW	double
 
HO	double
 
N	simpleText
 
UC	double
 
V	real
 
 
# move annotation
 
BM	double
 
DO	none
 
IT	none
 
TE	double
 
 
# markup
 
AR	list of composed point:point
 
CR	list of point
 
DD	elist of point
 
LB	list of composed point:simpleText
 
LN	list of composed point:point
 
MA	list of point
 
SL	list of point
 
SQ	list of point
 
TR	list of point
 
 
# root
 
AP	composed simpleText:simpleText
 
CA	simpleText
src/diana/sgfParser.py
Show inline comments
 
file renamed from src/sgfParser.py to src/diana/sgfParser.py
 
@@ -385,100 +385,96 @@ def propValue(str):
 
 
class propValue:
 
	pass
 
 
def cValueType(str,start):
 
	matches=[real,number,double,color,simpleText]
 
	for f in matches:
 
		i,x=f(str,start)
 
		if x is not None: return i,x
 
	return 1/0
 
 
def number(str,start):
 
	r=re.compile(r"(\+|-|)\d+")
 
	m=r.match(str,start)
 
	if m is None: return (-1,None)
 
	x=int(m.group(0))
 
	return (m.end(),x)
 
 
def real(str):
 
	m=re.match(r"(\+|-|)\d+(\.\d+)?",str)
 
	if m is None: return -1
 
	return m.end()
 
 
def double(str):
 
	m=re.match(r"1|2",str)
 
	if m is None: return -1
 
	return m.end()
 
	
 
def color(str):
 
	m=re.match(r"B|W",str)
 
	if m is None: return -1
 
	return m.end()
 
	
 
def simpleText(str):
 
	res=r""
 
	esc=False
 
	for c in str:
 
		if esc:
 
			res+=c
 
			esc=False
 
		elif c=="\\":
 
			esc=True
 
		elif c=="]":
 
			break
 
		else:
 
			res+=c
 
	return res"""
 
 
sgf=open("in/1-Hora-Simara.sgf").read()
 
 
x=Collection(sgf)
 
 
# TODO:
 
# date
 
 
 
"""
 
# move
 
B	move
 
KO	none
 
MN	number
 
W	move
 
 
# setup
 
AB	list of stone
 
AE	list of point
 
AW	list of stone
 
PL	color
 
 
# node annotation
 
C	text
 
DM	double
 
GB	double
 
GW	double
 
HO	double
 
N	simpleText
 
UC	double
 
V	real
 
 
# move annotation
 
BM	double
 
DO	none
 
IT	none
 
TE	double
 
 
# markup
 
AR	list of composed point:point
 
CR	list of point
 
DD	elist of point
 
LB	list of composed point:simpleText
 
LN	list of composed point:point
 
MA	list of point
 
SL	list of point
 
SQ	list of point
 
TR	list of point
 
 
# root
 
AP	composed simpleText:simpleText
 
CA	simpleText
 
FF	number
src/diana/tests/__init__.py
Show inline comments
 
new file 100644
src/diana/tests/data/simple.sgf
Show inline comments
 
new file 100755
 
(;SZ[19]FF[3]
 
PW[Kobayashi Koichi]
 
WR[9d]
 
PB[Kato Masao]
 
BR[9d]
 
EV[15th Kisei Final]
 
RO[Game 1]
 
DT[1991-01-18,19]
 
PC[Caesar Park Hotel, Sao Paulo]
 
KM[5.5]
 
RE[B+1.5]
 
US[GoGoD95]
 
;B[qd];W[dp];B[cd];W[qp];B[oc];W[ed];B[ec];W[fc];B[dc];W[gd];B[cf];W[kc]
 
;B[oq];W[lp];B[oo];W[pn];B[pl];W[on];B[mo];W[nm];B[lo];W[jp];B[kp];W[kq]
 
;B[ko];W[iq];B[pi];W[pq];B[lq];W[lr];B[mq];W[qg];B[hc];W[gb];B[jc];W[jd]
 
;B[kd];W[lc];B[je];W[id];B[hd];W[ie];B[he];W[ic];B[ib];W[if];B[hb];W[jb]
 
;B[hf];W[ff];B[ig];W[jf];B[gh];W[fh];B[fi];W[gg];B[hg];W[gi];B[hh];W[eh]
 
;B[fj];W[di];B[dj];W[cj];B[ck];W[dk];B[ej];W[ci];B[cl];W[dg];B[fp];W[cn]
 
;B[em];W[eb];B[db];W[dm];B[dl];W[en];B[hp];W[fm];B[el];W[gn];B[fo];W[fn]
 
;B[jo];W[ip];B[ho];W[hj];B[hk];W[ik];B[hl];W[il];B[hm];W[hn];B[io];W[jj]
 
;B[gj];W[hi];B[kh];W[im];B[fl];W[da];B[ca];W[ea];B[ga];W[fb];B[ee];W[de]
 
;B[dd];W[fd];B[df];W[ef];B[bb];W[oi];B[mi];W[lh];B[ki];W[lk];B[lg];W[oh]
 
;B[nl];W[ok];B[ol];W[mj];B[md];W[mf];B[ng];W[mg];B[mh];W[lf];B[nh];W[nf]
 
;B[og];W[ph];B[nj];W[nk];B[ml];W[mk];B[of];W[kg];B[li];W[pj];B[rf];W[qf]
 
;B[qe];W[mm];B[in];W[dr];B[ll];W[lm];B[kl];W[km];B[kk];W[kj];B[lj];W[jl]
 
;B[rj];W[ri];B[qm];W[qk];B[rk];W[qj];B[ql];W[sj];B[rl];W[rg];B[rn];W[po]
 
;B[sm];W[rp];B[ro];W[jr];B[hr];W[ir];B[ls];W[ms];B[mr];W[ks];B[ns];W[nr]
 
;B[ls];W[jg];B[jh];W[ms];B[nn];W[om];B[ls];W[ii];B[ih];W[ms];B[cp];W[co]
 
;B[ls];W[so];B[sk];W[ms];B[jm];W[jn];B[ls];W[gl];B[gk];W[ms];B[do];W[cq]
 
;B[ls];W[nd];B[pr];W[qr];B[op];W[pp];B[ne];W[or];B[me];W[nb];B[ob];W[ld]
 
;B[kr];W[nc];B[od];W[lr];B[bg];W[ch];B[kr];W[gr];B[hq];W[lr];B[nq];W[ms]
 
;B[os];W[rr];B[ls];W[is];B[kr];W[hs];B[fr];W[lr];B[ji];W[ij];B[kr];W[fs]
 
;B[es];W[er];B[gs];W[lr];B[fs];W[kr];B[mc];W[mb];B[re];W[le];B[oe];W[bm]
 
;B[bl];W[eo];B[ni];W[qi];B[si];W[sg];B[eq];W[dq];B[bh];W[bi];B[cm];W[an]
 
;B[gm];W[fe];B[cg];W[ei];B[ds];W[cs];B[fq];W[lb];B[na];W[ma];B[oa];W[dn]
 
;B[gf];W[fg];B[sf];W[ce];B[be];W[ee];B[ah];W[mn];B[no];W[pf];B[pe];W[go]
 
;B[gp];W[qs];B[al];W[ps];B[am];W[bn];B[ep];W[br];B[or];W[sh];B[ja];W[ka]
 
;B[ia];W[lg];B[sj];W[ms]
 
)
src/diana/tests/sgfParser.py
Show inline comments
 
new file 100644
 
import unittest
 
from unittest import TestCase
 
import os
 

	
 
from ..sgfParser import Collection
 

	
 

	
 
dataDir=os.path.join(os.path.dirname(__file__), "data")
 

	
 
class TestCollection(TestCase):
 
	def testEmptySgf(self):
 
		Collection("(;)")
 

	
 
	def testSimpleSgf(self):
 
		with open(os.path.join(dataDir, "simple.sgf")) as f:
 
			Collection(f.read())
 

	
 
if __name__ == '__main__':
 
	unittest.main()
0 comments (0 inline, 0 general)