示例#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 hashBoard():
    h = 0
    for sq in board.whiteMen:
        if not man.isMan(board.theBoard[sq]):
            print "sq=", sq
            board.dump()
        assert man.isMan(board.theBoard[sq])
        h = XOR(h, board.theBoard[sq], sq)
    for sq in board.blackMen:
        assert man.isMan(board.theBoard[sq])
        h = XOR(h, board.theBoard[sq], sq)
    #print "hashBoard=",h
    return h
示例#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 PlaceMan(sq, mn):
    assert square.isq(sq)
    assert man.isMan(mn) or mn == 0
    #print "hash:sq=%s mn=%s hash %s" % (sq,mn,board.hash),
    # hash away the old contents
    board.hash = XOR(board.hash, board.theBoard[sq], sq)
    # do the assignment
    board.theBoard[sq] = mn
    # hash in the new contents
    board.hash = XOR(board.hash, mn, sq)
示例#6
0
def umkdash(mv):
    assert tag(mv) in ["-", "x"]
    assert man.isMan(board.theBoard[nsq(mv)])
    board.theBoard[osq(mv)] = board.theBoard[nsq(mv)]
    board.theBoard[nsq(mv)] = 0
    if color(mv) == 'white':
        board.whiteMen.remove(nsq(mv))
        board.whiteMen.add(osq(mv))
        if man.isKing(board.theBoard[osq(mv)]):
            board.whiteKingAt = osq(mv)
    else:
        board.blackMen.remove(nsq(mv))
        board.blackMen.add(osq(mv))
        if man.isKing(board.theBoard[nsq(mv)]):
            board.blackKingAt = nsq(mv)
    del board.history[hmc(mv)]
示例#7
0
def umkcapture(mv):
    assert tag(mv) == "x"
    assert man.isMan(mn(mv))
    assert not color(mv) == 'white' or man.isBlack(mn(mv))
    assert not color(mv) == 'black' or man.isWhite(mn(mv))
    assert board.valid()
    umkdash(mv)
    # board.theBoard[nsq(mv)] = cmn(mv)  # WHAT ???
    # note the theBoard will be invalid at this point
    if color(mv) == 'white':
        assert man.isBlack(board.manAt(nsq(mv)))
        board.blackMen.add(nsq(mv))
    else:
        assert man.isWhite(board.manAt(nsq(mv)))
        board.whiteMen.add(nsq(mv))
    # after the above board maintennance it will be valid again
    assert board.valid()
示例#8
0
def prPieceData():
    cnt = 0
    d = ""
    for r in xrange(7,-1,-1):
        for f in xrange(0,8):
            sq = r*8 + f
            m = board.manAt(sq)
            if man.isMan(m):
                if cnt>0:
                    d = d + str(cnt)
                    cnt = 0
                d = d+sym[m]
            else:
                assert man.isEmpty(m)
                cnt = cnt+1
        if r>0:
            d = d + "/"
    return d