bug-gnubg
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-gnubg] (no subject)


From: daniel . zetterman
Subject: [Bug-gnubg] (no subject)
Date: Mon, 11 Aug 2003 01:20:13 +0200 (MEST)

Hi,

I've been fiddeling around with python to try to come up with some batch
script to import, analyse and export bad moves all in one go - here is the
result. Thought I would post the script here if someone need an example. At the
same time maybe I can get some questions answered....

After setting the default paths, I still can't get the commands to work
without full path for the filename.
What am I doing wrong?

I need a way to get the player on roll name, like "show turn", but how do I
read it from python... maybe it isn't supported yet? Any suggestions on how I
can use "show turn" to get the name anyway?

Is it possible to get more information about the analysis, like lost equity
for a move etc?

Thanks for a great program!

----------------------------
----------------------------

# 
# Batch import and analysis, written in python
#    by Daniel Zetterman (DaZe on gamesgrid)
#               address@hidden
#
# This script will:
#
# for all sgg-files in the import_path:
# 1. Import the sgg-file
# 2. Analyse it
# 3. Export all bad moves/cube descisions to html.
# 4. Save the analysed match to sgf-format
# 5. Move the sgg-file to a backup dir
#


import os

# ----- GLOBALS ---------------------

gnubg_path      = "d:/program files/gnubg"
import_path     = "d:/backgammongames/matches_to_be_analysed/"
match_path      = "d:/backgammongames/matches_analysed/"
badmoves_path   = "d:/backgammongames/exported_positions/"
backup_path     = "d:/backgammongames/backup/"
chequer_plies   = "0"
cube_plies      = "0"
priority        = "idle"
confirm_new     = "off"
confirm_save    = "off"
sound_enable    = "off"

# ----- CHECK -----------------------

def checkdir(dir):
        if not os.path.isdir(dir):
                print "Missing path - '" + dir + "', please check your settings 
and try
again."

checkdir(import_path)
checkdir(match_path)
checkdir(badmoves_path)
checkdir(backup_path)

# ----- INIT ------------------------

gnubg.command("set path sgg " + import_path) #can't get these to work
gnubg.command("set path sgf " + match_path)
gnubg.command("set path html " + badmoves_path)

gnubg.command("set priority " + priority)
gnubg.command("set analysis chequerplay evaluation plies " + chequer_plies)
gnubg.command("set analysis cubedecision evaluation plies " + cube_plies)

gnubg.command("set confirm new " + confirm_new)
gnubg.command("set confirm save " + confirm_save)
gnubg.command("set sound enable " + sound_enable)

# ----- PROCESS MATCH ---------------

for importfile in os.listdir(import_path):

        if os.path.splitext(importfile)[1] != ".sgg":
                continue

        prevpos = gnubg.positionid()
        os.chdir(import_path)
        gnubg.command("import sgg " + "\"" + importfile + "\"")
        gnubg.command("analyse clear session")
        gnubg.command("analyse match")
        os.chdir(gnubg_path) # this is needed for the record command (???)
        gnubg.command("record add match")
        gnubg.command("first game")
        gnubg.command("next marked")
        pos = gnubg.positionid()
        poscount = 0
        while pos != prevpos:
                while pos != prevpos:
                        if 1:
                                # TODO: only export pos if I made the bad move
                                os.chdir(badmoves_path)
                                exportfile = os.path.splitext(importfile)[0] + 
"__" + str(poscount) +
".html"
                                gnubg.command("export position html " + "\"" + 
exportfile + "\"") 
                        gnubg.command("next marked")
                        prevpos = pos
                        pos = gnubg.positionid()
                        poscount = poscount + 1
                gnubg.command("next game")
                gnubg.command("next marked")
                prevpos = pos
                pos = gnubg.positionid()

        os.chdir(match_path)
        matchfile = os.path.splitext(importfile)[0] + ".sgf"
        gnubg.command("save match " + "\"" + matchfile + "\"")
        if os.path.isfile(backup_path + importfile):
                os.remove(backup_path + importfile)
        os.rename(import_path + importfile, backup_path + importfile)

-- 
COMPUTERBILD 15/03: Premium-e-mail-Dienste im Test
--------------------------------------------------
1. GMX TopMail - Platz 1 und Testsieger!
2. GMX ProMail - Platz 2 und Preis-Qualitätssieger!
3. Arcor - 4. web.de - 5. T-Online - 6. freenet.de - 7. daybyday - 8. e-Post





reply via email to

[Prev in Thread] Current Thread [Next in Thread]