Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 制作无法正常工作的阵列副本_Python_Arrays_Function_Copy - Fatal编程技术网

Python 制作无法正常工作的阵列副本

Python 制作无法正常工作的阵列副本,python,arrays,function,copy,Python,Arrays,Function,Copy,我有一个算法来绘制一个楼层的地图 def floor_room_IDs(): global floor_roomIDs rand_ID = [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25] r_y = 0 for Layer in floor_roomIDs: r_x = 0 for Tile in Layer:

我有一个算法来绘制一个楼层的地图

def floor_room_IDs():
    global floor_roomIDs
    rand_ID = [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]
    r_y = 0
    for Layer in floor_roomIDs:
        r_x = 0
        for Tile in Layer:
            floor_roomIDs[r_y][r_x] = floor_map[r_y][r_x]
            r_x += 1
        r_y += 1
    r_y = 0
    for Layer in floor_roomIDs:
        r_x = 0
        for Title in Layer:
            if floor_roomIDs[r_y][r_x] == '1':
                room_ID = rand_ID.pop(random.randint(0, len(rand_ID)-1))
                room_ID_level = globals()['r' + str(room_ID)]
                globals()['rc' + str(room_ID)] = room_ID_level.copy()   
                roomC_ID = 'rc' + str(room_ID)
                floor_roomIDs[r_y][r_x] = str(roomC_ID)
            if floor_roomIDs[r_y][r_x] == 2:
                floor_roomIDs[r_y][r_x] = 'r2'
            if floor_roomIDs[r_y][r_x] == '3':
                floor_roomIDs[r_y][r_x] = 'r3'            
            r_x += 1
        r_y += 1 
def floor_doors():
    global floor_map
    r_y = 0
    for Layer in floor_map:
        r_x = 0
        for Tile in Layer:
            if floor_map[r_y][r_x] == '1' or floor_map[r_y][r_x] == 2:
                door_right = False
                door_bottom = False
                door_left = False 
                door_top = False
                if r_x < 8:
                    if floor_map[r_y][r_x+1] != '/':
                        door_right = True
                if r_y < 8:
                    if floor_map[r_y+1][r_x] != '/':
                        door_bottom = True 
                if r_x > 0:
                    if floor_map[r_y][r_x-1] != '/':
                        door_left = True 
                if r_y > 0:
                    if floor_map[r_y-1][r_x] != '/':
                        door_top = True
                if door_top == True:
                    floor_map[r_y][r_x] = 'a'
                if door_left == True:
                    floor_map[r_y][r_x] = 'b'
                if door_bottom == True:
                    floor_map[r_y][r_x] = 'c'   
                if door_right == True:
                    floor_map[r_y][r_x] = 'd'     
                if door_top == True and door_left == True:
                    floor_map[r_y][r_x] = 'e' 
                if door_top == True and door_bottom == True:
                    floor_map[r_y][r_x] = 'f' 
                if door_top == True and door_right == True:
                    floor_map[r_y][r_x] = 'g'   
                if door_left == True and door_bottom == True:
                    floor_map[r_y][r_x] = 'h'
                if door_left == True and door_right == True:
                    floor_map[r_y][r_x] = 'i'  
                if door_bottom == True and door_right == True:
                    floor_map[r_y][r_x] = 'j'  
                if door_top == True and door_left == True and door_right == True:
                    floor_map[r_y][r_x] = 'k'   
                if door_top == True and door_bottom == True and door_right == True:
                    floor_map[r_y][r_x] = 'l'    
                if door_left == True and door_bottom == True and door_right == True:
                    floor_map[r_y][r_x] = 'm'
                if door_top == True and door_bottom == True and door_left == True:
                    floor_map[r_y][r_x] = 'n'
                if door_top == True and door_bottom == True and door_right == True and door_left == True:
                    floor_map[r_y][r_x] = 'o'                 
            r_x += 1        
        r_y += 1  
        
                            
                                
def floor_validate(): 
    global room_amount
    room_amount = 0
    end_room = 0
    r_y = 0
    for Layer in floor_map:
        r_x = 0
        for Tile in Layer: 
            if floor_map[r_y][r_x] == '1':
                room_amount += 1
            if r_y == 0 or r_y == 1 or r_y == 8 or r_y == 7 or r_x == 0 or r_x == 1 or r_x == 8 or r_x == 7:
                if floor_map[r_y][r_x] == '1':
                    if end_room == 0:
                        if r_y == 8 and r_x != 8 and r_x != 0:
                            if floor_map[r_y-1][r_x] == '1':
                                end_room += 1
                            if floor_map[r_y][r_x+1] == '1':
                                end_room += 1
                            if floor_map[r_y][r_x-1] == '1':
                                end_room += 1
                        if r_y == 0 and r_x != 8 and r_x != 0:
                            if floor_map[r_y+1][r_x] == '1':
                                end_room += 1
                            if floor_map[r_y][r_x+1] == '1':
                                end_room += 1 
                            if floor_map[r_y][r_x-1] == '1':
                                end_room += 1         
                        if r_x == 0 and r_y != 8 and r_y != 0:
                            if floor_map[r_y+1][r_x] == '1':
                                end_room += 1
                            if floor_map[r_y-1][r_x] == '1':
                                end_room += 1 
                            if floor_map[r_y][r_x+1] == '1':
                                end_room += 1    
                        if r_x == 8 and r_y != 8 and r_y != 0:
                            if floor_map[r_y+1][r_x] == '1':
                                end_room += 1
                            if floor_map[r_y-1][r_x] == '1':
                                end_room += 1 
                            if floor_map[r_y][r_x-1] == '1':
                                end_room += 1                      
                        if r_y == 0 and r_x == 0:
                            if floor_map[r_y+1][r_x] == '1':
                                end_room += 1
                            if floor_map[r_y][r_x+1] == '1':
                                end_room += 1
                        if r_y == 0 and r_x == 8:
                            if floor_map[r_y+1][r_x] == '1':
                                end_room += 1
                            if floor_map[r_y][r_x-1] == '1':
                                end_room += 1 
                        if r_y == 8 and r_x == 0:
                            if floor_map[r_y-1][r_x] == '1':
                                end_room += 1
                            if floor_map[r_y][r_x+1] == '1':
                                end_room += 1      
                        if r_y == 8 and r_x == 8:
                            if floor_map[r_y-1][r_x] == '1':
                                end_room += 1
                            if floor_map[r_y][r_x-1] == '1':
                                end_room += 1    
                        if end_room > 1:
                            end_room = 0
                        if end_room == 1:
                            floor_map[r_y][r_x] = 2
                            
                        
            r_x += 1
        r_y += 1
    if room_amount < 18 or room_amount > 22 or end_room != 1:
        make_floor_outline()
    else:
        floor_room_IDs()
        floor_doors()
        
def make_floor_outline():
    global floor_map
    global floor_roomIDs
    read = [['/','/','/','/','/','/','/','/','/'],
            ['/','/','/','/','/','/','/','/','/'],
            ['/','/','/','/','/','/','/','/','/'],
            ['/','/','/','/','/','/','/','/','/'],
            ['/','/','/','/','/','/','/','/','/'],
            ['/','/','/','/','/','/','/','/','/'],
            ['/','/','/','/','/','/','/','/','/'],
            ['/','/','/','/','/','/','/','/','/'],
            ['/','/','/','/','/','/','/','/','/']]
    floor_map = [['/','/','/','/','/','/','/','/','/'],
             ['/','/','/','/','/','/','/','/','/'],
             ['/','/','/','/','/','/','/','/','/'],
             ['/','/','/','/','/','/','/','/','/'],
             ['/','/','/','/','3','/','/','/','/'],
             ['/','/','/','/','/','/','/','/','/'],
             ['/','/','/','/','/','/','/','/','/'],
             ['/','/','/','/','/','/','/','/','/'],
             ['/','/','/','/','/','/','/','/','/']]
    floor_roomIDs = [['/','/','/','/','/','/','/','/','/'],
             ['/','/','/','/','/','/','/','/','/'],
             ['/','/','/','/','/','/','/','/','/'],
             ['/','/','/','/','/','/','/','/','/'],
             ['/','/','/','/','3','/','/','/','/'],
             ['/','/','/','/','/','/','/','/','/'],
             ['/','/','/','/','/','/','/','/','/'],
             ['/','/','/','/','/','/','/','/','/'],
             ['/','/','/','/','/','/','/','/','/']]
    for i in range(0, 17):
        r_y = 0
        for Layer in floor_map:
            r_x = 0
            for Tile in Layer:
                if Tile == '3':
                    floor_map[r_y][r_x+1] = '1'
                    floor_map[r_y][r_x-1] = '1'
                    floor_map[r_y+1][r_x] = '1'
                    floor_map[r_y-1][r_x] = '1'
                if Tile == '1':
                    if read[r_y][r_x] == '/':
                        read[r_y][r_x] = '1'
                        if r_y < 8:
                            if floor_map[r_y+1][r_x] == '/':
                                random_roomcount = random.randint(0,3)
                                if random_roomcount == 1:
                                    floor_map[r_y+1][r_x] = '1'
                        if r_y > 0:
                            if floor_map[r_y-1][r_x] == '/':
                                random_roomcount = random.randint(0,3)
                                if random_roomcount == 1:
                                    floor_map[r_y-1][r_x] = '1'
                        if r_x < 8:
                            if floor_map[r_y][r_x+1] == '/':
                                random_roomcount = random.randint(0,3)
                                if random_roomcount == 1:
                                    floor_map[r_y][r_x+1] = '1' 
                        if r_x > 0:
                            if floor_map[r_y][r_x-1] == '/':    
                                random_roomcount = random.randint(0,3)
                                if random_roomcount == 1:
                                    floor_map[r_y][r_x-1] = '1'  
                    
                r_x += 1    
            r_y += 1  
    floor_validate()    
def floor\u room\u IDs():
全球楼层客房
rand_ID=[4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]
r_y=0
对于楼层\房间ID中的图层:
r_x=0
对于层中的瓷砖:
楼层室友[r_y][r_x]=楼层地图[r_y][r_x]
r_x+=1
r_y+=1
r_y=0
对于楼层\房间ID中的图层:
r_x=0
对于图层中的标题:
如果楼层室友[r\u y][r\u x]='1':
room_ID=rand_ID.pop(random.randint(0,len(rand_ID)-1))
房间ID级别=全局()['r'+str(房间ID)]
globals()['rc'+str(room_ID)]=room_ID_level.copy()
房间标识='rc'+str(房间标识)
楼层房间标识[r_y][r_x]=str(房间标识)
如果楼层室友[r_y][r_x]==2:
楼层室友[r_y][r_x]=“r2”
如果楼层室友[r\u y][r\u x]=='3':
楼层室友[r_y][r_x]=“r3”
r_x+=1
r_y+=1
def地板_门():
全球地面地图
r_y=0
对于楼层地图中的图层:
r_x=0
对于层中的瓷砖:
如果楼层地图[r_y][r_x]='1'或楼层地图[r_y][r_x]==2:
门右=假
门底部=假
门左=假
门顶部=假
如果r_x<8:
如果楼层地图[r_y][r_x+1]!='/':
门右=正确
如果r_y<8:
如果楼层地图[r_y+1][r_x]!=“/”:
门底部=正确
如果r_x>0:
如果楼层地图[r_y][r_x-1]!=“/”:
门左=真
如果r_y>0:
如果楼层地图[r_y-1][r_x]!=“/”:
门顶部=正确
如果door_top==真:
楼层地图[r_y][r_x]=“a”
如果门左=真:
楼层地图[r_y][r_x]=“b”
如果door_bottom==真:
楼层地图[r_y][r_x]=“c”
如果门右==真:
楼层地图[r_y][r_x]=“d”
如果door_top==真,door_left==真:
楼层地图[r_y][r_x]=“e”
如果门顶部==真,门底部==真:
楼层地图[r_y][r_x]=“f”
如果door_top==真,door_right==真:
楼层地图[r_y][r_x]=“g”
如果门左==真,门底==真:
楼层地图[r_y][r_x]=“h”
如果门左==真,门右==真:
楼层地图[r_y][r_x]=“我”
如果door_bottom==真,door_right==真:
楼层地图[r_y][r_x]=“j”
如果door_top==真,door_left==真,door_right==真:
楼层地图[r_y][r_x]=“k”
如果door_top==真,door_bottom==真,door_right==真:
楼层地图[r_y][r_x]=“l”
如果门左==真,门下==真,门右==真:
楼层地图[r_y][r_x]=“m”
如果门顶部==真,门底部==真,门左侧==真:
楼层地图[r_y][r_x]=“n”
如果door_top==真,door_bottom==真,door_right==真,door_left==真:
楼层地图[r_y][r_x]=“o”
r_x+=1
r_y+=1
def floor_validate():
全球房间面积
房间数量=0
结束房间=0
r_y=0
对于楼层地图中的图层:
r_x=0
对于层中的瓷砖:
如果楼层地图[r_y][r_x]=“1”:
房间数量+=1
如果r_y==0或r_y==1或r_y==8或r_y==7或r_x==0或r_x==1或r_x==8或r_x==7:
如果楼层地图[r_y][r_x]=“1”:
如果end_room==0:
如果r_y==8且r_x!=8和r_x!=0:
如果楼层地图[r_y-1][r_x]=“1”:
结束_房间+=1
如果楼层地图[r_y][r_x+1]=“1”:
结束_房间+=1
如果楼层地图[r_y][r_x-1]=“1”:
结束_房间+=1
如果r_y==0且r_x!=8和r_x!=0:
如果楼层地图[r_y+1][r_x]=“1”:
结束_房间+=1
如果楼层地图[r_y][r_x+1]=“1”:
结束_房间+=1
如果楼层地图[r_y][r_x-1]=“1”:
结束_房间+=1
如果r_x==0且r_y!=8和r_y!=0:
如果楼层地图[r_y+1][r_x]=“1”:
结束_房间+=1
如果楼层地图[r_y-1][r_x]=“1”:
结束_房间+=1
如果楼层地图[r_y][r_x+1]=“1”:
结束_房间+=1
如果r_x==8且r_y!=8和r_y!=0:
如果楼层地图[r_y+1][r_x]=“1”:
结束_房间+=1
如果楼层地图[r_y-1][r_x]=“1”:
结束_房间+=1
如果楼层地图[r_y][r_x-1]=“1”:
结束_房间+=1
如果r_y==0且r_x==0:
如果楼层地图[r_y+1][r_x]=“1”:
结束_房间+=1
如果楼层地图[r_y][r_x+1]=“1”:
>>> import copy
>>> l = [1, 2, 3]
>>> lc = copy.deepcopy(l)
>>> lc
[1, 2, 3]
>>> lc.append(4)
>>> l
[1, 2, 3]
>>> lc
[1, 2, 3, 4]