bug-gnubg
[Top][All Lists]
Advanced

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

[Bug-gnubg] Re: python script for exporting bad moves


From: Joseph Heled
Subject: [Bug-gnubg] Re: python script for exporting bad moves
Date: Sun, 17 Aug 2003 10:11:40 +1200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030624


This is how the script might look. You need the most recent version from today ...


import gnubg
import os.path

def skillBad(s) :
  return s and (s == "very bad" or s == "bad" or s == "doubtful")

def exportBad(baseName) :
  """ For current analyzed match, export all moves/cube decisions marked
  doubtful or bad"""

  # get current match
  m = gnubg.match()

  # go to match start
  gnubg.navigate()

  # Skill of previous action, to avoid exporting double actions twice
  prevSkill = None

  # exported position number, used in file name
  poscount = 0

  for game in m["games"] :
    for action in game["game"] :

      analysis = action.get("analysis", None)
      if analysis :
        type = action["action"]
        skill = analysis.get("skill", None)
        bad = skillBad(skill)

        if type == "move" :
          if skillBad(analysis.get("cube-skill", None)) :
            bad = True
        elif type == "take" or type == "drop" :
          if badSkill(prevSkill) :
            # already exported
            bad = False

        if bad :
exportfile = "%s__%d.html" % (os.path.splitext(baseName)[0],poscount)
          gnubg.command("export position html " + "\"" + exportfile + "\"")
          poscount += 1
      # advance to next record
      gnubg.navigate(1)

    # advance to next game
    gnubg.navigate(game=1)

address@hidden wrote:
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....






reply via email to

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