0% found this document useful (0 votes)
6 views1 page

Chess World - 070638

Chess game using python

Uploaded by

kaushalsingh4227
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Chess World - 070638

Chess game using python

Uploaded by

kaushalsingh4227
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

print("HELLO BUDDY:,YOU ARE WELCOMED TO THE CHESS WORLD")

# Simple Text-Based Chess Game

class ChessBoard:
def __init__(self):
self.board = self.create_board()

def create_board(self):
board = [[" " for _ in range(8)] for _ in range(8)]
# Place pieces for player 1 (white)
board[0] = ["R", "N", "B", "Q", "K", "B", "N", "R"]
board[1] = ["P" for _ in range(8)]
# Place pieces for player 2 (black)
board[6] = ["p" for _ in range(8)]
board[7] = ["r", "n", "b", "q", "k", "b", "n", "r"]
return board

def print_board(self):
print(" a b c d e f g h")
for i, row in enumerate(self.board):
print(f"{8 - i} {' '.join(row)} {8 - i}")
print(" a b c d e f g h")

def move_piece(self, start, end):


start_row, start_col = 8 - int(start[1]), ord(start[0]) - ord('a')
end_row, end_col = 8 - int(end[1]), ord(end[0]) - ord('a')
piece = self.board[start_row][start_col]
self.board[start_row][start_col] = " "
self.board[end_row][end_col] = piece

def main():
chess_board = ChessBoard()
current_player = "White"

while True:
chess_board.print_board()
print(f"{current_player}'s turn")

start = input("Enter the start position (e.g., e2): ")


end = input("Enter the end position (e.g., e4): ")

chess_board.move_piece(start, end)

current_player = "Black" if current_player == "White" else "White"

if __name__ == "__main__":
main()

You might also like