bug-gnubg
[Top][All Lists]
Advanced

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

Re: [Bug-gnubg] Python function movetupletostring committed to revision


From: Michael Petch
Subject: Re: [Bug-gnubg] Python function movetupletostring committed to revision control / Windows test executables created.
Date: Thu, 25 Oct 2012 18:23:14 -0600
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20120614 Thunderbird/13.0.1

On 2012-10-25 17:17, Michael Petch wrote:
> Let me know if you have problems.

I have realized that this fix is a bit inconsistent or at least part of
our interface is inconsistent. Please consider this executable a work in
progress and the function may change. The function acts on a tuple that
is flattened. I created it based on the results from gnubg.findbestmove.
Unfortunately gnubg.parsemove returns a tuple that contains tuples.

So gnubg.parsemove("24/20 10/9*) returns something like:

((24,20), (10/9))

gnubg.findbestmove() would return something like:

(24, 20, 10, 9)

If I change findbestmove() to return a flattened tuple then I break
programs currently using findbestmove()

The best way is to modify movetupletostring to support the first
argument as either of the two formats as an argument.

For the time being results from parsemove would have to be flattened
prior to passing to movetupletostring . This is a bit of overkill but
this function would suffice as a temporary solution:

import types

def isTuple(x): return type(x) == types.TupleType
def flatten(T):
    if not isTuple(T): return (T,)
    elif len(T) == 0: return ()
    else: return flatten(T[0]) + flatten(T[1:])


then you could do:

flattenedmovetuple = flatten(gnubg.parsemove("24/20 10/9*"))

For simple tuples there are much easier ways of flattening them if they
only have a depth of 1.

-- 
Michael Petch
CApp::Sysware Consulting Ltd.
OpenPGP FingerPrint=D81C 6A0D 987E 7DA5 3219 6715 466A 2ACE 5CAE 3304





reply via email to

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