예제 #1
0
def prdashPiece(mv, mvs):
    assert tag(mv) == "-"
    assert isPiece(manAt(osq(mv)))
    # simplest form - pln
    p = man.pr(manAt(osq(mv)))
    ln = square.pr(nsq(mv))
    s = "%s%s" % (p, ln)
    found = algebraic.find(s, mvs)
    if len(found) == 1:
        return s
    # disabiguate by file - pfln
    f = "abcdefgh"[col(osq(mv))]
    s = "%s%s%s" % (p, f, ln)
    found = algebraic.find(s, mvs)
    if (len(found)) == 1:
        return s
    # disambiguate by rank - prln
    r = "12345678"[row(osq(mv))]
    s = "%s%s%s" % (p, r, ln)
    found = algebraic.find(s, mvs)
    if (len(found)) == 1:
        return s
    # disambiguate by both -rare but possible - prfln
    s = "%s%s%s%s" % (p, r, f, ln)
    if (len(found)) == 1:
        return s
    # there should be no other cases given that move is legal
    assert False
예제 #2
0
def prcapturePiece(mv, mvs):
    assert tag(mv) in ["x", "x/", "xep"]
    assert isPiece(manAt(osq(mv)))
    # simplest form - pxln
    p = man.pr(manAt(osq(mv)))
    ln = square.pr(nsq(mv))
    s = "%sx%s" % (p, ln)
    found = algebraic.find(s, mvs)
    if len(found) == 1:
        return s
    # disambiguate by file - pfxln
    f = "abcdefgh"[col(osq(mv))]
    s = "%s%sx%s" % (p, f, ln)
    found = algebraic.find(s, mvs)
    if len(found) == 1:
        return s
    # disambiguate by rank - prxln
    r = "12345678"[row(osq(mv))]
    s = "%s%sx%s" % (p, r, ln)
    found = algebraic.find(s, mvs)
    if len(found) == 1:
        return s
    # disambiguate by both - prfxln
    s = "%s%s%sx%s" % (p, r, f, ln)
    found = algebraic.find(s, mvs)
    if len(found) == 1:
        return s
    # if move is legal there should be no other cases
    assert False
예제 #3
0
def prcapturePawn(mv, mvs):
    assert tag(mv) in ["x", "x/", "xep"]
    assert isPawn(manAt(osq(mv)))
    # simplest form - fxln
    f = "abcdefgh"[col(osq(mv))]
    ln = square.pr(nsq(mv))
    if tag(mv) == "x/":
        q = man.pr(pmn(mv))
        s = "%sx%s=%s" % (f, ln, q)
    else:
        s = "%sx%s" % (f, ln)
    found = algebraic.find(s, mvs)
    if len(found) == 1:
        return s
    # disambiguate by both - rfxln
    rf = square.pr(osq(mv))
    if tag(mv) == "x/":
        s = "%sx%s=%s" % (rf, ln, q)
    else:
        s = "%sx%s" % (rf, ln)
    found = algebraic.find(s, mvs)
    if len(found) == 1:
        return s
    # if move is legal there should be no other cases
    assert False
예제 #4
0
def trymv(s):
    mvs = legal.moves()
    found = algebraic.find(s, mvs)
    if len(found) == 0:
        print "not found"
    elif len(found) == 1:
        move.make(found[0])
        auto()
    elif len(found) > 1:
        print "ambiguous"
예제 #5
0
def trymv(s):
    assert playing
    mvs = legal.moves()
    found = algebraic.find(s, mvs)
    if len(found) == 0:
        put_illegalmove(s, "not found")
    elif len(found) == 1:
        move.make(found[0])
        reply()  # sends the random response
    elif len(found) > 1:
        put_illegalmove(s, "ambiguous")
예제 #6
0
def find(s):
    mvs = legal.moves()
    found = algebraic.find(s, mvs)
    if len(found) == 0:
        print " " * 13 + "no such move"
    if len(found) == 1:
        print " " * 13 + "found unique", san.pr(found[0], mvs)
    elif len(found) > 1:
        print " " * 13 + "ambiguous, choices are:"
        for mv in found:
            print " " * 17, san.pr(mv, mvs)
    return found
예제 #7
0
def prdashPawn(mv, mvs):
    assert tag(mv) == "-" or tag(mv) == "-/"
    assert isPawn(manAt(osq(mv)))
    # simplest form - ln
    ln = square.pr(nsq(mv))
    if tag(mv) == "-/":
        q = man.pr(pmn(mv))
        s = "%s=%s" % (ln, q)
    else:
        s = ln
    found = algebraic.find(s, mvs)
    if len(found) == 1:
        return s
예제 #8
0
def opponent_move(s):
    assert engineColor in ['white', 'black', None]
    assert board.colorToMove() != engineColor
    mvs = legal.moves()
    found = algebraic.find(s, mvs)
    if len(found) == 0:
        put_illegalmove(s, "not found")
    elif len(found) == 1:
        assert board.colorToMove() != engineColor
        assert move.color(found[0]) != engineColor
        move.make(found[0])
        if board.colorToMove() == engineColor:
            assert board.colorToMove() == engineColor
            reply()
    elif len(found) > 1:
        put_illegalmove(s, "ambiguous")