How do i put the chess pieces in a python chessboard grid?

Viewed 73

I am a begginer working on a college project and i need to make a chess game that works in the python console(can´t use the chess import), i just completed the board but now i have no idea how to put the pieces in,can someone help?(they can be represented by letters like Pawn=P )

this is what i did so far


def create_grid(): 
""" Creates the grid return=an array that represents the grid """
 
    tab = []
    for i in range(GRID_SIZE - 1):
        tab.append([]) 
        for j in range(GRID_SIZE):
            tab[i].append('')
    return tab
 
def print_grid(tab):
 """ prints the grid """ 

  print( ' 1','2','3','4','5','6','7','8') 
  for i in range(GRID_SIZE - 1): 
      print("{} ".format(i+1), end="")
      for j in range(GRID_SIZE):
          print(" {}".format(tab[i][j]), end="")
          if j < GRID_SIZE: 
             print("|", end="")

      if i < GRID_SIZE:
         print()

print_grid(create_grid)
1 Answers

Try this and improve as needed. I considered @G.C's comment to print unicodes.

GRID_SIZE = 8


def create_grid():
    """Creates the grid return=an array that represents the grid"""

    tab = []
    for i in range(GRID_SIZE):
        tab.append([])
        for j in range(GRID_SIZE):
            tab[i].append("")
    return tab


def print_grid(tab):
    """prints the grid"""

    print(" 1", "2", "3", "4", "5", "6", "7", "8")
    for i in range(GRID_SIZE):
        print("{} ".format(i + 1), end="")
        for j in range(GRID_SIZE):
            print("\u2654{}".format(tab[i][j]), end="")
            if j < GRID_SIZE:
                print("|", end="")

        if i < GRID_SIZE:
            print()


print_grid(create_grid())

It will print something like this

 1 2 3 4 5 6 7 8
1 ♔|♔|♔|♔|♔|♔|♔|♔|
2 ♔|♔|♔|♔|♔|♔|♔|♔|
3 ♔|♔|♔|♔|♔|♔|♔|♔|
4 ♔|♔|♔|♔|♔|♔|♔|♔|
5 ♔|♔|♔|♔|♔|♔|♔|♔|
6 ♔|♔|♔|♔|♔|♔|♔|♔|
7 ♔|♔|♔|♔|♔|♔|♔|♔|
8 ♔|♔|♔|♔|♔|♔|♔|♔|
Related