如何在 Python 控制台棋盘中找到中间的方块

问题描述 投票:0回答:1

我做了8×8的棋盘,每块棋子都是3*3(由9个方格组成)。每个图块中的平均正方形被标记为次要的,中间的应该被标记为主要的

print("""
Chess



Press Enter to Start...
""")
noneed = input()
if noneed== "":
    line = []
    chessboard = ""
    changeColorAllowed = False
    lineQueue = False
    queue = 0
    
    for linecount in range(24):
        for i in range(24):
            

                
            
                if (linecount // 3) % 2 == (i // 3) % 2:
                    line.append([queue,"white", "a" + str(i//3), "primary", "none"])
                else:
                    line.append([queue,"black", "a" + str(i//3), "primary", "none"])



    for i in line:
        if len(chessboard)%25==0:
            chessboard+="\n"
        if i[1] == "white":
            chessboard += "⬜"
        else: 
            chessboard += "⬛"
        
            
    print(chessboard)
    
        
        

如何找到中间的方块并将其标记为主要

python python-3.x console chess
1个回答
0
投票

可以添加内联 if 来判断单元格是否为

primary

    for linecount in range(24):
        for i in range(24):
            line.append([
                queue,
                "white" if (linecount // 3) % 2 == (i // 3) % 2 else "black",
                "a" + str(i//3),
                "primary" if (linecount%3 == 1) and (i%3 == 1) else "secondary",
                "none"])
© www.soinside.com 2019 - 2024. All rights reserved.