How would I do this?

J

John Doe

Hey guys,

I;m working on making a chess program and I hit a wall. I have no idea how to get the position of the chess pieces. I have the chess board 1-8 and A-Hfor black as well as 1-8 and a-h for white. i just have to figure out how to declare those positions for the actual pieces so like the row of pawns for black would be B1-B8 as well as be able to replace the other coordinateswith the piece when they move there like if I moved a black pawn from B1 to C1 B1 would be empty and then C1 would have it.

I'm sorry if that's confusing but I can't seem to figure out how to do it.... Any help is greatly appreciated and thank you in advance!
 
I

Ian Kelly

Hey guys,

I;m working on making a chess program and I hit a wall. I have no idea how to get the position of the chess pieces. I have the chess board 1-8 and A-H for black as well as 1-8 and a-h for white. i just have to figure out how to declare those positions for the actual pieces so like the row of pawnsfor black would be B1-B8 as well as be able to replace the other coordinates with the piece when they move there like if I moved a black pawn from B1to C1 B1 would be empty and then C1 would have it.

I'm sorry if that's confusing but I can't seem to figure out how to do it.... Any help is greatly appreciated and thank you in advance!

The usual way to do this would be to represent the board as an 8x8
list of lists, with each item of the inner lists representing one
space on the board and denoting its contents. For example, you might
have board[1][4] = 'P', indicating that E2 (1, 4 in zero-based
row-column coordinates) holds a white pawn.
 
H

h4ck3rpr0n3

Thank you for the quick reply. Unfortunately I'm still a little confused... How might I implement that into my current code?

def Make_Board():
Col = "+--+"
Row = "| |"
Col2 = "--+"
Row2 = " |"
print(" ", Col + Col2 + Col2 + Col2 + Col2 + Col2 + Col2 + Col2)
print("1", Row + Row2 + Row2 + Row2 + Row2 + Row2 + Row2 + Row2, "1")
print(" ", Col + Col2 + Col2 + Col2 + Col2 + Col2 + Col2 + Col2)
print("2", Row + Row2 + Row2 + Row2 + Row2 + Row2 + Row2 + Row2, "2")
print(" ", Col + Col2 + Col2 + Col2 + Col2 + Col2 + Col2 + Col2)
print("3", Row + Row2 + Row2 + Row2 + Row2 + Row2 + Row2 + Row2, "3")
print(" ", Col + Col2 + Col2 + Col2 + Col2 + Col2 + Col2 + Col2)
print("4", Row + Row2 + Row2 + Row2 + Row2 + Row2 + Row2 + Row2, "4")
print(" ", Col + Col2 + Col2 + Col2 + Col2 + Col2 + Col2 + Col2)
print("5", Row + Row2 + Row2 + Row2 + Row2 + Row2 + Row2 + Row2, "5")
print(" ", Col + Col2 + Col2 + Col2 + Col2 + Col2 + Col2 + Col2)
print("6", Row + Row2 + Row2 + Row2 + Row2 + Row2 + Row2 + Row2, "6")
print(" ", Col + Col2 + Col2 + Col2 + Col2 + Col2 + Col2 + Col2)
print("7", Row + Row2 + Row2 + Row2 + Row2 + Row2 + Row2 + Row2, "7")
print(" ", Col + Col2 + Col2 + Col2 + Col2 + Col2 + Col2 + Col2)
print("8", Row + Row2 + Row2 + Row2 + Row2 + Row2 + Row2 + Row2, "8")
print(" ", Col + Col2 + Col2 + Col2 + Col2 + Col2 + Col2 + Col2)

def Col_Label():
Col_Label_Black = " A B C D E F G H"
print(Col_Label_Black)

def Col_Label2():
Col_Label_White = " A B C D E F G H"
Col_Label_White = Col_Label_White.lower()
print(Col_Label_White)

def Board():
Col_Label()
Make_Board()
Col_Label2()

Board()



Thanks again for your help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,871
Messages
2,569,919
Members
46,172
Latest member
JamisonPat

Latest Threads

Top