Blogs

writing an opening analyzer

PeterArt
| 3

i'm trying to write an statistics opening analyzer for my saved games.
So far i've managed to convert the game archive into a python list
In which each entry contains a single game, as i'm new to python.
This is allready quite something for me, but i'm not sure if it is the rightway to go because still i have to sort the games (did i win, and with what kind of opening)

I've included allready a function to determine won or lost games, but i'm not using it for the moment.

i'm not sure if lists (or maybe multiple lists for black and white wins) are the rightway to tackle this problem, but at least its a start.

if someone has some good ideas on how to tackle this let me now.

 

(i'm using portable  python 2.6)

-----------------------------code below here--------------------------------

import string
import re

#DIW did i win ?
# player white win = 1
# player black win = -1
# player loosing = 0
def DIW(game,userid):

    win = 0
    if string.find(game,'[White "'+userid+'"') and string.find(game,'[Result "1-0"]')
        win =  1
    if string.find(game,'[Black "'+userid+'"') and string.find(game,'[Result "0-1"]')
        win = -1
    return win

mylist=[]
s=""

# change to your own chess.com userID
userid='PeterArt'

#location to your chess.com archived games   
file1 = open('C:\ISO\portable\chess.com.pgn','r')
filelist = file1.readlines()

print 'Note this program isnt that fast just wait a while
'

for line in filelist:
    if string.find(line,'[Event') > -1:      
        mylist.append(s)
        s=""
    if string.find(line,'[') > -1:
        s = s + line.rstrip("
") + '|'
    else:
        if re.search("[0-9]", line):
            s = s + line.rstrip("
")
sortmewinning(userid)


# for testing print my list

print "".join( mylist)

file1.close()