pythonpython-3.xconsolechess

How to Find the middle square in a Python Console Chessboard


I made 8×8 chessboard with each tile being 3*3 (consists of 9 squares). An average square in each tile is marked as secondary, and the middle one is supposed to be marked as primary

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)
    
        
        

How do I find the middle square and mark it as primary


Solution

  • You can add an inline if to determine if the cell is 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"])