Пример #1
0
def umkdash(mv):
    assert tag(mv) in ["-", "x"]
    assert not tag(mv) == "-" or man.isEmpty(cmn(mv))
    assert not tag(mv) == "x" or man.isMan(cmn(mv))
    assert man.isMan(board.theBoard[nsq(mv)])
    assert board.valid()

    # maintain KingAt and Men sets
    if color(mv) == 'white':
        board.whiteMen.remove(nsq(mv))
        board.whiteMen.add(osq(mv))
        if board.theBoard[nsq(mv)] == man.king:
            board.whiteKingAt = osq(mv)
    else:
        board.blackMen.remove(nsq(mv))
        board.blackMen.add(osq(mv))
        if board.theBoard[nsq(mv)] == -man.king:
            board.blackKingAt = osq(mv)

    # update the board
    zobrist.PlaceMan(osq(mv), board.theBoard[nsq(mv)])
    #board.theBoard[osq(mv)] = board.theBoard[nsq(mv)]
    assert not tag(mv) == "-" or man.isEmpty(cmn(mv))
    assert not tag(mv) == "x" or man.isMan(cmn(mv))
    zobrist.PlaceMan(nsq(mv), cmn(mv))
    #board.theBoard[nsq(mv)] = cmn(mv)

    # maintain history
    del board.history[hmc(mv)]
    assert not tag(mv) == "-" or board.valid()
Пример #2
0
def mkdashpromote(mv):
    assert tag(mv) in ["-/", "x/"]
    assert man.isPawn(board.manAt(osq(mv)))
    assert board.manAt(nsq(mv)) == cmn(mv)
    assert not color(mv) == 'white' or man.whiteQRBN(pmn(mv))
    assert not color(mv) == 'black' or man.blackQRBN(pmn(mv))
    assert not color(mv) == 'white' or board.manAt(osq(mv)) == man.pawn
    assert not color(mv) == 'black' or board.manAt(osq(mv)) == -man.pawn
    assert not tag(mv) == "-/" or cmn(mv) == 0
    assert not tag(mv) == "x/" or cmn(mv) != 0
    assert board.valid()
    # update board
    zobrist.PlaceMan(osq(mv), 0)
    #board.theBoard[osq(mv)] = 0
    zobrist.PlaceMan(nsq(mv), pmn(mv))
    #board.theBoard[nsq(mv)] = pmn(mv)
    # maintain Men
    if color(mv) == 'white':
        board.whiteMen.remove(osq(mv))
        board.whiteMen.add(nsq(mv))
    else:
        board.blackMen.remove(osq(mv))
        board.blackMen.add(nsq(mv))
    board.history[hmc(mv)] = mv
    assert not tag(mv) == "-" or board.valid()
Пример #3
0
def addMan(m, sq):
    global theBoard, whiteKingAt, blackKingAt, whiteMen, blackMen
    if not man.isMan(m):
        print "addman: bad value for man: %s" % m
    elif not square.isq(sq):
        print "addman: bad value for square: %s" % sq
    elif man.isPawn(m) and (square.lastrank(sq) or square.firstrank(sq)):
        print "addman: pawns not allowed on rank" % rank(sq)
    elif occupied(sq):
        print "addman: square %s is occupied" % sq
    elif man.isWhiteKing(m) and not (whiteKingAt == 999):
        print "addman: only one white king allowed"
    elif man.isBlackKing(m) and not (blackKingAt == 999):
        print "addman: only one black king allowed"
    else:
        #assert hash == zobrist.hashBoard()
        if man.isWhite(m):
            if man.isKing(m):
                whiteKingAt = sq
            whiteMen.add(sq)
        else:
            if man.isKing(m):
                blackKingAt = sq
            blackMen.add(sq)
        zobrist.PlaceMan(sq, m)
Пример #4
0
def mkdash(mv):
    assert tag(mv) in ["-", "x"]
    assert not tag(mv) == "-" or man.isEmpty(cmn(mv))
    assert not tag(mv) == "x" or man.isMan(cmn(mv))
    assert man.isMan(board.manAt(osq(mv)))
    assert board.valid()

    # maintain allow flags
    if color(mv) == 'white':
        if osq(mv) == e1 and board.manAt(e1) == man.king:
            board.whiteAllowOO = False
            board.whiteAllowOOO = False
        elif osq(mv) == h1 and board.manAt(h1) == man.rook:
            board.whiteAllowOO = False
        elif osq(mv) == a1 and board.manAt(a1) == man.rook:
            board.whiteAllowOOO = False
    else:
        if osq(mv) == e8 and board.manAt(e8) == -man.king:
            board.blackAllowOO = False
            board.blackAllowOOO = False
        elif osq(mv) == h8 and board.manAt(h8) == -man.rook:
            board.blackAllowOO = False
        elif osq(mv) == a8 and board.manAt(a8) == -man.rook:
            board.blackAllowOOO = False

    # maintain KingAt and Men sets
    if color(mv) == 'white':
        board.whiteMen.remove(osq(mv))
        board.whiteMen.add(nsq(mv))
        if board.manAt(osq(mv)) == man.king:
            board.whiteKingAt = nsq(mv)
    else:
        board.blackMen.remove(osq(mv))
        board.blackMen.add(nsq(mv))
        if board.manAt(osq(mv)) == -man.king:
            board.blackKingAt = nsq(mv)

    # update board
    zobrist.PlaceMan(nsq(mv), board.theBoard[osq(mv)])
    zobrist.PlaceMan(osq(mv), 0)

    #board.theBoard[nsq(mv)] = board.theBoard[osq(mv)]
    #board.theBoard[osq(mv)] = 0

    # update history
    board.history[hmc(mv)] = mv
    assert not tag(mv) == "-" or board.valid()
Пример #5
0
def mkxep(mv):
    assert tag(mv) == "xep"
    assert board.manAt(nsq(mv)) == 0
    if color(mv) == 'white':
        assert board.manAt(osq(mv)) == man.pawn
        assert board.manAt(bak(nsq(mv))) == -man.pawn
        zobrist.PlaceMan(osq(mv), 0)
        #board.theBoard[osq(mv)]=0
        zobrist.PlaceMan(nsq(mv), man.pawn)
        #board.theBoard[nsq(mv)]=man.pawn
        zobrist.PlaceMan(bak(nsq(mv)), 0)
        #board.theBoard[bak(nsq(mv))]=0
        board.whiteMen.remove(osq(mv))
        board.whiteMen.add(nsq(mv))
        board.blackMen.remove(bak(nsq(mv)))
    else:
        assert board.manAt(osq(mv)) == -man.pawn
        assert board.manAt(fwd(nsq(mv))) == man.pawn
        zobrist.PlaceMan(osq(mv), 0)
        #board.theBoard[osq(mv)]=0
        zobrist.PlaceMan(nsq(mv), -man.pawn)
        #board.theBoard[nsq(mv)]= -man.pawn
        zobrist.PlaceMan(fwd(nsq(mv)), 0)
        #board.theBoard[fwd(nsq(mv))]=0
        board.blackMen.remove(osq(mv))
        board.blackMen.add(nsq(mv))
        board.whiteMen.remove(fwd(nsq(mv)))
    board.history[hmc(mv)] = mv
Пример #6
0
def umkdashpromote(mv):
    assert tag(mv) in ["-/", "x/"]
    assert board.manAt(osq(mv)) == 0
    assert board.manAt(nsq(mv)) == pmn(mv)
    assert not color(mv) == 'white' or man.whiteQRBN(pmn(mv))
    assert not color(mv) == 'black' or man.blackQRBN(pmn(mv))
    assert not tag(mv) == "-/" or cmn(mv) == 0
    assert not tag(mv) == "x/" or cmn(mv) != 0
    assert board.valid()
    zobrist.PlaceMan(nsq(mv), cmn(mv))
    #board.theBoard[nsq(mv)] = cmn(mv)
    if color(mv) == 'white':
        zobrist.PlaceMan(osq(mv), man.pawn)
        #board.theBoard[osq(mv)] = man.pawn
        board.whiteMen.remove(nsq(mv))
        board.whiteMen.add(osq(mv))
    else:
        zobrist.PlaceMan(osq(mv), -man.pawn)
        #board.theBoard[osq(mv)] = -man.pawn
        board.blackMen.remove(nsq(mv))
        board.blackMen.add(osq(mv))
    del board.history[hmc(mv)]
    assert not tag(mv) == "-" or board.valid()
Пример #7
0
def mkOO(mv):
    assert tag(mv) == "OO"
    assert board.valid()
    if color(mv) == 'white':
        assert osq(mv) == e1
        assert board.whiteAllowOO
        zobrist.PlaceMan(e1, 0)
        #board.theBoard[e1] = 0
        zobrist.PlaceMan(f1, man.rook)
        #board.theBoard[f1] = man.rook
        zobrist.PlaceMan(g1, man.king)
        #board.theBoard[g1] = man.king
        zobrist.PlaceMan(h1, 0)
        #board.theBoard[h1] = 0
        board.whiteMen.remove(e1)
        board.whiteMen.add(f1)
        board.whiteMen.add(g1)
        board.whiteMen.remove(h1)
        board.whiteKingAt = g1
        board.whiteAllowOO = False  # not need since board.popFlags()  will fix
        board.whiteAllowOOO = False  # not need since board.popFlags()  will fix
    else:
        assert color(mv) == 'black'
        assert osq(mv) == e8
        assert board.blackAllowOO
        zobrist.PlaceMan(e8, 0)
        #board.theBoard[e8] = 0
        zobrist.PlaceMan(f8, -man.rook)
        #board.theBoard[f8] = -man.rook
        zobrist.PlaceMan(g8, -man.king)
        #board.theBoard[g8] = -man.king
        zobrist.PlaceMan(h8, 0)
        #board.theBoard[h8] = 0
        board.blackMen.remove(e8)
        board.blackMen.add(f8)
        board.blackMen.add(g8)
        if not h8 in board.blackMen:
            print "move.271:"
            board.dump()
        board.blackMen.remove(h8)
        board.blackKingAt = g8
        board.blackAllowOO = False  # not need since board.popFlags()  will fix
        board.blackAllowOOO = False  # not need since board.popFlags()  will fix
    board.history[hmc(mv)] = mv
    assert board.valid()
Пример #8
0
def umkOOO(mv):
    assert tag(mv) == "OOO"
    assert board.valid()
    if color(mv) == 'white':
        assert osq(mv) == e1
        assert not board.whiteAllowOO
        assert not board.whiteAllowOOO
        zobrist.PlaceMan(e1, man.king)
        #board.theBoard[e1] = man.king
        zobrist.PlaceMan(d1, 0)
        #board.theBoard[d1] = 0
        zobrist.PlaceMan(c1, 0)
        #board.theBoard[c1] =  0
        zobrist.PlaceMan(a1, man.rook)
        #board.theBoard[a1] = man.rook
        board.whiteMen.add(e1)
        board.whiteMen.remove(d1)
        board.whiteMen.remove(c1)
        board.whiteMen.add(a1)
        board.whiteKingAt = e1
        board.whiteAllowOOO = True  # not need since board.popFlags()  will fix
    else:
        assert osq(mv) == e8
        assert not board.blackAllowOO
        assert not board.blackAllowOOO
        zobrist.PlaceMan(e8, -man.king)
        #board.theBoard[e8] = -man.king
        zobrist.PlaceMan(d8, 0)
        #board.theBoard[d8] = 0
        zobrist.PlaceMan(c8, 0)
        #board.theBoard[c8] = 0
        zobrist.PlaceMan(a8, -man.rook)
        #board.theBoard[a8] = -man.rook
        board.blackMen.add(e8)
        board.blackMen.remove(d8)
        board.blackMen.remove(c8)
        board.blackMen.add(a8)
        board.blackKingAt = e8
        board.blackAllowOOO = True  # not need since board.popFlags()  will fix
    del board.history[hmc(mv)]
    assert board.valid()
Пример #9
0
def mkOOO(mv):
    assert tag(mv) == "OOO"
    assert board.valid()
    if color(mv) == 'white':
        assert osq(mv) == e1
        assert board.whiteAllowOOO
        zobrist.PlaceMan(e1, 0)
        #board.theBoard[e1] = 0
        zobrist.PlaceMan(d1, man.rook)
        #board.theBoard[d1] = man.rook
        zobrist.PlaceMan(c1, man.king)
        #board.theBoard[c1] = man.king
        zobrist.PlaceMan(a1, 0)
        #board.theBoard[a1] = 0
        board.whiteMen.remove(e1)
        board.whiteMen.add(d1)
        board.whiteMen.add(c1)
        board.whiteMen.remove(a1)
        board.whiteKingAt = c1
        board.whiteAllowOO = False
        board.whiteAllowOOO = False
    else:
        assert osq(mv) == e8
        assert board.blackAllowOOO
        zobrist.PlaceMan(e8, 0)
        #board.theBoard[e8] = 0
        zobrist.PlaceMan(d8, -man.rook)
        #board.theBoard[d8] = -man.rook
        zobrist.PlaceMan(c8, -man.king)
        #board.theBoard[c8] = -man.king
        zobrist.PlaceMan(a8, 0)
        #board.theBoard[a8] = 0
        board.blackMen.remove(e8)
        board.blackMen.add(d8)
        board.blackMen.add(c8)
        board.blackMen.remove(a8)
        board.blackKingAt = c8
        board.blackAllowOO = False
        board.blackAllowOOO = False
    board.history[hmc(mv)] = mv
    assert board.valid()
Пример #10
0
def umkOO(mv):
    assert tag(mv) == "OO"
    assert board.valid()
    if color(mv) == 'white':
        assert osq(mv) == e1
        assert not board.whiteAllowOO
        assert not board.whiteAllowOOO
        zobrist.PlaceMan(e1, man.king)
        #board.theBoard[e1] = man.king
        zobrist.PlaceMan(f1, 0)
        #board.theBoard[f1] = 0
        zobrist.PlaceMan(g1, 0)
        #board.theBoard[g1] = 0
        zobrist.PlaceMan(h1, man.rook)
        #board.theBoard[h1] = man.rook
        board.whiteMen.add(e1)
        board.whiteMen.remove(f1)
        board.whiteMen.remove(g1)
        board.whiteMen.add(h1)
        board.whiteKingAt = e1
        board.whiteAllowOO = True  # not need since board.popFlags()  will fix
    else:
        assert osq(mv) == e8
        assert not board.blackAllowOO
        assert not board.blackAllowOOO
        zobrist.PlaceMan(e8, -man.king)
        #board.theBoard[e8] = -man.king
        zobrist.PlaceMan(f8, 0)
        #board.theBoard[f8] = 0
        zobrist.PlaceMan(g8, 0)
        #board.theBoard[g8] = 0
        zobrist.PlaceMan(h8, -man.rook)
        #board.theBoard[h8] = -man.rook
        board.blackMen.add(e8)
        board.blackMen.remove(f8)
        board.blackMen.remove(g8)
        board.blackMen.add(h8)
        board.blackKingAt = e8
        board.blackAllowOO = True  # not need since board.popFlags()  will fix
    del board.history[hmc(mv)]
    assert board.valid()
Пример #11
0
def umkxep(mv):
    assert tag(mv) == "xep"
    if color(mv) == 'white':
        zobrist.PlaceMan(osq(mv), man.pawn)
        #board.theBoard[osq(mv)] = man.pawn
        zobrist.PlaceMan(nsq(mv), 0)
        #board.theBoard[nsq(mv)] = 0
        zobrist.PlaceMan(bak(nsq(mv)), -man.pawn)
        #board.theBoard[bak(nsq(mv))]= -man.pawn
        board.whiteMen.add(osq(mv))
        board.whiteMen.remove(nsq(mv))
        board.blackMen.add(bak(nsq(mv)))
    else:
        zobrist.PlaceMan(osq(mv), -man.pawn)
        #board.theBoard[osq(mv)] = -man.pawn
        zobrist.PlaceMan(nsq(mv), 0)
        #board.theBoard[nsq(mv)] = 0
        zobrist.PlaceMan(fwd(nsq(mv)), man.pawn)
        #board.theBoard[fwd(nsq(mv))] = man.pawn
        board.blackMen.add(osq(mv))
        board.blackMen.remove(nsq(mv))
        board.whiteMen.add(fwd(nsq(mv)))
    del board.history[hmc(mv)]