Exemple #1
0
    def playGameFromString(self,string, winner, print_positions=False, lineByLine=False):
        global fi
        self.board = [[5,3,4,1000,9,4,3,5],
        [1,1,1,1,1,1,1,1],
        [0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0],
        [-1,-1,-1,-1,-1,-1,-1,-1],
        [-5,-3,-4,-1000,-9,-4,-3,-5],]

        color=-1
        ep={-1:[], 1:[]}
        array=[]
        move=0
        for m in string.split(' '):
            print(m)
            i=input('press enter:')
            g=gs.gamestate(board, ep ,[],[])
            g.getPinnedSquares()
            g.pinPieces()
            g.getAllMoves()
            g.representBoard()

            color=color*-1

            new_move=MO(m)
            board=g.moveToInstruction(color,new_move)
            print('actual winner:', winner)
            print('Predicted winner', fi.evaluate(board,move))
            ep=g.enpassants

            ao=an(g)
            ao.analyze()
            arr=ao.produceStateArray()
            array.append(arr)

        g=gs.gamestate(board, {-1:[], 1:[]},[],[])

        g.getPinnedSquares()
        g.pinPieces()
        g.getAllMoves()

        return array
Exemple #2
0
def index():
    global gamestate
    global moveNum
    board = [[5,3,4,1000,9,4,3,5],
    [1,1,1,1,1,1,1,1],
    [0,0,0,0,0,0,0,0],
    [0,0,0,0,0,0,0,0],
    [0,0,0,0,0,0,0,0],
    [0,0,0,0,0,0,0,0],
    [-1,-1,-1,-1,-1,-1,-1,-1],
    [-5,-3,-4,-1000,-9,-4,-3,-5],]
    ep={-1:[], 1:[]}
    canCastle = {1000:{'queen':True, 'king':True}, -1000:{'queen':True, 'king':True}}
    hasCastled = {1000:False, -1000:False}
    gamestate = gs.gamestate(board, ep, canCastle, hasCastled)
    '''loads index page'''
    html = open('app/board.html','r').read()
    return html
Exemple #3
0
def playGame(string, winner, printStates=False,printStats=False,wait=False, printPredict=False):

    '''Plays through a game and returns an array of gamestate arrays.
    Optional parameters for printing information and making predictions'''
    global fi
    board = [[5,3,4,1000,9,4,3,5],
    [1,1,1,1,1,1,1,1],
    [0,0,0,0,0,0,0,0],
    [0,0,0,0,0,0,0,0],
    [0,0,0,0,0,0,0,0],
    [0,0,0,0,0,0,0,0],
    [-1,-1,-1,-1,-1,-1,-1,-1],
    [-5,-3,-4,-1000,-9,-4,-3,-5],]
    ep={-1:[], 1:[]}

    canCastle = {1000:{'queen':True, 'king':True}, -1000:{'queen':True, 'king':True}}
    hasCastled = {1000:False, -1000:False}

    color=-1
    ep={-1:[], 1:[]}
    array=[]
    move=0
    for m in string.split(' '):

        if wait:
            i=input('press enter:')
        g=gs.gamestate(board, ep ,canCastle,hasCastled)

        g.getPinnedSquares()
        g.pinPieces()
        g.getAllMoves()

        if move!=0:
            ao=an(state=g)
            ao.analyze()
            arr=ao.produceStateArray()
            array.append(arr)

        if printStates:
            g.representBoard()

        color=color*-1

        new_move=MO(m)

        board=g.moveToInstruction(color,new_move)

        #if printPredict:
            #print('actual winner:', winner)
            #print('Predicted winnger', fi.evaluate(board,move))
        ep=g.enpassants

        canCastle = g.canCastle
        hasCastled = g.hasCastled
        move+=1




    g=gs.gamestate(board, {-1:[], 1:[]},g.canCastle,g.hasCastled)

    g.getPinnedSquares()
    g.pinPieces()
    g.getAllMoves()
    ao=an(state=g)
    ao.analyze()
    arr=ao.produceStateArray()
    array.append(arr)

    return array
Exemple #4
0
    board = [
        [5, 3, 4, 1000, 9, 4, 3, 5],
        [1, 1, 1, 1, 1, 1, 1, 1],
        [0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0],
        [-1, -1, -1, -1, -1, -1, -1, -1],
        [-5, -3, -4, -1000, -9, -4, -3, -5],
    ]
    ep = {-1: [], 1: []}

    canCastle = {
        1000: {
            'queen': True,
            'king': True
        },
        -1000: {
            'queen': True,
            'king': True
        }
    }
    hasCastled = {1000: False, -1000: False}

    color = -1
    ep = {-1: [], 1: []}

    state = gs.gamestate(board, ep, canCastle, hasCastled)

    print(think.rootthink(state, 1, 1))
Exemple #5
0
def FENtoGS(FENstring,board, color, hasCastled, canCastle):


    new_board = [[0 for x in range(8)] for y in range(8)]

    keys={'r':-5, 'R':5, 'k':-1000, 'K':1000, 'q':-9, 'Q':9, 'p':-1, 'P':1, 'b':-4, 'B':4, 'n':-3, 'N':3}
    arr = FENstring.split('/')

    ep={-1:[], 1:[]}
    for x in range(7, -1, -1):

        count=0
        for y in range(len(arr[x])-1, -1, -1):

            if arr[x][y] in keys:
                new_board[7-x][count]=keys[arr[x][y]]
                count+=1
            else:
                count+=int(arr[x][y])


    #compare boards
    differences = []
    for x in range(8):

        for y in range(8):

            if board[x][y]!=new_board[x][y]:

                differences.append({'pos':[x,y], 'newValue':new_board[x][y], 'oldValue':board[x][y]})

    if len(differences) == 2:

        for difference in differences:
            if difference['newValue']==0:
                d1=difference
            else:
                d2=difference
        if abs(d1['oldValue'])==1000:
            print('kingmove')
            if abs(d1['pos'][0] - d2['pos'][0]) > 1 or abs(d1['pos'][1]-d2['pos'][1]>0):
                return None


        if color==1 and d2['newValue']==1:
            if d1['pos'][0]==1 and d2['pos'][0]==3:
                ep[1].append(d2['pos'])
        elif color==-1 and d2['newValue']==-1:
            if d1['pos'][0]==6 and d2['pos'][0]==4:
                ep[-1].append(d2['pos'])

        elif abs(d2['newValue'])==1000:

            canCastle[color*1000]['queen']=False
            canCastle[color*1000]['king']=False

        elif abs(d1['oldValue']==5):
            pieceColor = int(d1['oldValue']/abs(d1['oldValue']))
            if d1['pos'] == [0,0]:
                canCastle[pieceColor]['king']=False

            elif d1['pos'] == [7,7]:
                canCastle[pieceColor]['queen']=False

            elif d2['pos']== [7,0]:
                canCastle[pieceColor]['king']=False

            elif d1['pos']== [0,7]:
                canCastle[pieceColor]['queen']=False



        #just check for enpassants if this is the case

    else:
        for difference in differences:

            if difference['pos']==[0, 4]:
                hasCastled[1]=True
            elif difference['pos']==[7,4]:
                hasCastled[-1]=True


    return gs.gamestate(new_board, ep, canCastle, hasCastled)
Exemple #6
0
move=0
canCastle = {1000:{'queen':True, 'king':True}, -1000:{'queen':True, 'king':True}}
hasCastled = {1000:False, -1000:False}
board = [[5,3,4,1000,9,4,3,5],
[1,1,1,1,1,1,1,1],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[-1,-1,-1,-1,-1,-1,-1,-1],
[-5,-3,-4,-1000,-9,-4,-3,-5],]
while True:

    moveNumber+=1
    color=color*-1
    g=gamestate(board, ep, canCastle, hasCastled)
    g.getPinnedSquares()
    g.pinPieces()
    g.getAllMoves()
    g.representBoard()
    print(g.castles)
    b=copy.copy(g.board[:])
    print(b)
    node1 = rootNode(g, moveNumber, forestmodel)
    new_move = node1.search(color)
    print(new_move)
    origin=new_move['origin']
    destination = new_move['destination']
    b[destination[0]][destination[1]]=b[origin[0]][origin[1]]
    b[origin[0]][origin[1]]=0
    print(b)