コード例 #1
0
def countTotalMoves(board,colour):
    moves = 0
    for row in range(Board.getMinRowSize(board), Board.getMaxRowSize(board)+1):
        for col in range(Board.getMinColSize(board), Board.getMaxColSize(board)+1):
            if not(Board.comaprePieceat(board,col,row, "E")):
                if not(Board.comaprePieceat(board,col,row, colour)):
                    moves += countMoves(board,row, col)

    return moves
コード例 #2
0
def getSuccessors(board, colour, needCord, type, oppo_colour):

    Successors=[]
    cord=[]
    #if its the placing phase then get states for that phase
    if (type=="PP"):

        #if you want the board as the output
        if(colour == "W"):
            for col in range (0,8):
                for row in range (0,6):
                    if (Board.comaprePieceat(board,col,row, "E")):
                        #make a copy of the board that will represent a new state
                        tempBoard=copy.deepcopy(board)
                        Board.placePiece(tempBoard,col,row,"W")
                        #check if after placing the piece there is something
                        # that can be eliminated from the board and remove it
                        #from the board
                        Game.removeKills(tempBoard, colour, oppo_colour)
                        Successors.append(tempBoard)
                        if (needCord):
                            cord.append((col, row))

        if(colour == "B"):
            for col in range (0,8):
                for row in range (2,8):
                    if (Board.comaprePieceat(board,col,row, "E")):
                        #make a copy of the board that will represent a new state
                        tempBoard=copy.deepcopy(board)
                        Board.placePiece(tempBoard,col,row,"B")
                        # check if after placing the piece there is something
                        # that can be eliminated from the board and remove it
                        #from the board
                        Game.removeKills(tempBoard, colour, oppo_colour)
                        Successors.append(tempBoard)
                        if (needCord):
                            cord.append((col, row))

    # if its in the moving phase then get states for that phase
    if (type=="MP"):
        #check all the possible moves peices of our colour can make and return states
        for row in range(Board.getMinRowSize(board), Board.getMaxRowSize(board)+1):
            for col in range(Board.getMinColSize(board), Board.getMaxColSize(board)+1):
                if (Board.comaprePieceat(board,col,row, colour )):
                    temp=checkMove(board,col, row)
                    for pos in temp:
                        #make a copy of the board that will represent a new state
                        tempBoard=copy.deepcopy(board)
                        #move the peice to the new location
                        Board.movePiece(tempBoard,col,row,pos[0],pos[1])
                        #remove kills
                        Game.removeKills(tempBoard, colour,oppo_colour )
                        Successors.append(tempBoard)
                        if (needCord):
                            cord.append((col,row,pos[0],pos[1]))

    return (cord,Successors)
コード例 #3
0
    def getSuccessors(board, colour, output, type):

        Successors = []
        #if its in the placing phase then get states for that phase
        if (type == "PP"):

            #if you want the board as the output
            if (output == "boards"):
                if (colour == "W"):
                    for col in range(0, 8):
                        for row in range(0, 6):
                            if (Board.comaprePieceat(board, col, row, "E")):
                                tempBoard = copy.deepcopy(
                                    board
                                )  #make a copy of the board that will represent a new state
                                Board.placePiece(tempBoard, col, row, "W")
                                Game.removeKills(
                                    tempBoard
                                )  # check if after placing the piece there is something
                                # that can be eliminated from the board and remove it from the board
                                Successors.append(tempBoard)

                if (colour == "B"):
                    for col in range(0, 8):
                        for row in range(2, 8):
                            if (Board.comaprePieceat(board, col, row, "E")):
                                tempBoard = copy.deepcopy(
                                    board
                                )  #make a copy of the board that will represent a new state
                                Board.placePiece(tempBoard, col, row, "B")
                                Game.removeKills(
                                    tempBoard
                                )  # check if after placing the piece there is something
                                # that can be eliminated from the board and remove it from the board
                                Successors.append(tempBoard)
            #if you want the output as coordinates
            else:
                if (colour == "W"):
                    for col in range(0, 8):
                        for row in range(0, 6):
                            if (Board.comaprePieceat(board, col, row, "E")):
                                Successors.append((col, row))

                if (colour == "B"):
                    for col in range(0, 8):
                        for row in range(2, 8):
                            if (Board.comaprePieceat(board, col, row, "E")):
                                Successors.append((col, row))

        # if its in the moving phase then get states for that phase
        if (type == "MP"):
            if (output == "boards"):
                for row in range(Board.getMinRowSize(board),
                                 Board.getMaxRowSize(board) + 1):
                    for col in range(Board.getMinColSize(board),
                                     Board.getMaxColSize(board) + 1):
                        if (Board.comaprePieceat(board, col, row, colour)):
                            temp = Player.checkMove(board, col, row)
                            for pos in temp:
                                tempBoard = copy.deepcopy(
                                    board
                                )  #make a copy of the board that will represent a new state
                                Board.movePiece(tempBoard, col, row, pos[0],
                                                pos[1])
                                Game.removeKills(tempBoard)
                                Successors.append(tempBoard)

            else:
                for row in range(Board.getMinRowSize(board),
                                 Board.getMaxRowSize(board) + 1):
                    for col in range(Board.getMinColSize(board),
                                     Board.getMaxColSize(board) + 1):
                        if (Board.comaprePieceat(board, col, row, colour)):
                            temp = Player.checkMove(board, col, row)
                            for pos in temp:
                                Successors.append((col, row, pos[0], pos[1]))

        return Successors