def survey(filename,surveyname):
    surveyList = miscFunctions.importList(surveyname,[HEX_FILTER])
    fileList = miscFunctions.importList(filename,[HEX_FILTER,
                                                  HEX_FILTER,
                                                  HEX_FILTER,
                                                  HEX_FILTER])

    for i in range(0,len(surveyList)):
        surveyList[i] = int("0x" + surveyList[i],16)

    for i in range(0,len(fileList)):
        if int(fileList[i][2],0) in surveyList:
            print i+1
        elif int(fileList[i][3],0) + int("0x70000",0) in surveyList:
            print i+1
示例#2
0
def sort(fileName, index, tie):
    roomArray = miscFunctions.importList(
        fileName, [HEX_FILTER, HEX_FILTER, HEX_FILTER, HEX_FILTER])
    roomArray = sorted(roomArray, key=operator.itemgetter(index, tie))
    data = open(fileName, "w")
    for i in roomArray:
        data.write(i[0] + "\t" + i[1] + "\t" + i[2] + "\t" + i[3] + "\n")

    data.close()
def swapDoors(source,fileName,seed,easy=True,perc=100):
    # initialize seed
    random.seed(seed)

    # create new file
    data = open(source,"rb")
    dest = open(fileName,"wb")
    dest.write(data.read())
    dest.close()
    data.close()
    
    # read door lists
    leftDoorArray = miscFunctions.importList("doors-left.txt",
                                             [HEX_FILTER,HEX_FILTER])
    rightDoorArray = miscFunctions.importList("doors-right.txt",
                                              [HEX_FILTER,HEX_FILTER])
    upDoorArray = miscFunctions.importList("doors-up.txt",
                                           [HEX_FILTER,HEX_FILTER])
    downDoorArray = miscFunctions.importList("doors-down.txt",
                                             [HEX_FILTER,HEX_FILTER])

    if perc != 100:
        # filter a sublist
        leftCount = len(leftDoorArray)
        shuffleArray = permuteList(leftCount)
        shuffleArray = shuffleArray[:(leftCount*perc/100)]
        leftDoorArray = percolate(leftDoorArray,shuffleArray)
        rightDoorArray = percolate(rightDoorArray,shuffleArray)

        # filter a sublist
        downCount = len(downDoorArray)
        shuffleArray = permuteList(downCount)
        shuffleArray = shuffleArray[:(downCount*perc/100)]
        downDoorArray = percolate(downDoorArray,shuffleArray)
        upDoorArray = percolate(upDoorArray,shuffleArray)
        

    swapDoorList(fileName,leftDoorArray,rightDoorArray,easy)
    swapDoorList(fileName,upDoorArray,downDoorArray,easy)
def printDoors():
    roomArray = miscFunctions.importList("doorlist.txt",
                                         [HEX_FILTER,
                                          HEX_FILTER,
                                          NUM_FILTER])
    # print roomArray
    data = open("doors.txt","w")
    dataLeft = open("doors-left.txt","w")
    dataRight = open("doors-right.txt","w")
    dataUp = open("doors-up.txt","w")
    dataDown = open("doors-down.txt","w")

    for i in roomArray:
        # get door pointer
        doorArrayPointer = hex(int("0x70000",0)
                               + int("0x" + i[1],0)
                               + headerSize)

        for j in range(0,int(i[2])+1):
            doorPointer = hexMethods.getHalfword("clean-rom.smc",
                                                 hex(int(doorArrayPointer,0)
                                                     + 2*j))
            doorPointer2 = hex(int(doorPointer,0) + headerSize + int("0x10000",0))
            destPointer = hexMethods.getHalfword("clean-rom.smc",
                                                 hex(int(doorPointer2,0)))
            #destPointer = hex(int("0x70000",0)
            #                   + int(destPointer,0)
            #                   + headerSize)
            direction = hexMethods.getByte("clean-rom.smc",
                                           hex(int(doorPointer2,0) + 3))
            
            # write the following data:
            # pointer to door
            # pointer to the door array source
            # pointer to room
            # room door goes to
            # door direction
            if int(direction,0) < 8:
                direction = DIRECTION[int(direction,0)]
                data.write(doorPointer
                           + "\t" + hex(int(doorArrayPointer,0) + 2*j)
                           + "\t0x" + i[0]
                           + "\t" + destPointer
                           + "\t" + direction
                           + "\n")
                if direction is "UP":
                    dataUp.write(doorPointer
                                 + "\t" + hex(int(doorArrayPointer,0) + 2*j)
                                 + "\t0x" + i[0]
                                 + "\t" + destPointer
                                 + "\n")
                if direction is "DOWN":
                    dataDown.write(doorPointer
                                   + "\t" + hex(int(doorArrayPointer,0) + 2*j)
                                   + "\t0x" + i[0]
                                   + "\t" + destPointer
                                   + "\n")
                if direction is "LEFT":
                    dataLeft.write(doorPointer
                                   + "\t" + hex(int(doorArrayPointer,0) + 2*j)
                                   + "\t0x" + i[0]
                                   + "\t" + destPointer
                                   + "\n")
                if direction is "RIGHT":
                    dataRight.write(doorPointer
                                    + "\t" + hex(int(doorArrayPointer,0) + 2*j)
                                    + "\t0x" + i[0]
                                    + "\t" + destPointer
                                    + "\n")
            else:
                data.write(doorPointer
                           + "\t" + hex(int(doorArrayPointer,0) + 2*j)
                           + "\t0x" + i[0]
                           + "\t" + destPointer
                           + "\t" + direction
                           + "\n")
        

    data.close()
    dataUp.close()
    dataDown.close()
    dataLeft.close()
    dataRight.close()
    sort("doors-right.txt",3,2)
    sort("doors-up.txt",3,2)
    sort("doors-left.txt",2,3)
    sort("doors-down.txt",2,3)
def swapDoorsLocal(source,fileName,seed,easy = True,perc=100):
    # initialize seed + debug message.
    random.seed(seed)

    # create new file
    data = open(source,"rb")
    dest = open(fileName,"wb")
    dest.write(data.read())
    dest.close()
    data.close()

    locaArray1 = ["brinstar",
                  "crateria",
                  "maridia",
                  "norfair",
                  "wreck"]

    locaArray2 = ["itemsA",
                  "itemsB",
                  "lower",]
    
    folder = "local-data/doors-"
    
    # read doors by location (up/down and left right)
    for i in locaArray1:
        leftDoorArray = miscFunctions.importList(folder + i + "-left.txt",
                                                 [HEX_FILTER,HEX_FILTER])
        rightDoorArray = miscFunctions.importList(folder + i + "-right.txt",
                                                  [HEX_FILTER,HEX_FILTER])
        downDoorArray = miscFunctions.importList(folder + i + "-down.txt",
                                                 [HEX_FILTER,HEX_FILTER])
        upDoorArray = miscFunctions.importList(folder + i + "-up.txt",
                                               [HEX_FILTER,HEX_FILTER])

        if perc != 100:
            # filter a sublist
            leftCount = len(leftDoorArray)
            shuffleArray = permuteList(leftCount)
            shuffleArray = shuffleArray[:(leftCount*perc/100)]
            leftDoorArray = percolate(leftDoorArray,shuffleArray)
            rightDoorArray = percolate(rightDoorArray,shuffleArray)

            # filter a sublist
            downCount = len(downDoorArray)
            shuffleArray = permuteList(downCount)
            shuffleArray = shuffleArray[:(downCount*perc/100)]
            downDoorArray = percolate(downDoorArray,shuffleArray)
            upDoorArray = percolate(upDoorArray,shuffleArray)
        

        swapDoorList(fileName,leftDoorArray,rightDoorArray,easy)
        swapDoorList(fileName,upDoorArray,downDoorArray,easy)

    # read doors by location (left right only)
    for i in locaArray2:
        leftDoorArray = miscFunctions.importList(folder + i + "-left.txt",
                                                 [HEX_FILTER,HEX_FILTER])
        rightDoorArray = miscFunctions.importList(folder + i + "-right.txt",
                                                  [HEX_FILTER,HEX_FILTER])

        if perc != 100:
            # filter a sublist
            leftCount = len(leftDoorArray)
            shuffleArray = permuteList(leftCount)
            shuffleArray = shuffleArray[:(leftCount*perc/100)]
            leftDoorArray = percolate(leftDoorArray,shuffleArray)
            rightDoorArray = percolate(rightDoorArray,shuffleArray)
        
        swapDoorList(fileName,leftDoorArray,rightDoorArray,easy)