So I am trying to write a board typeish "game" in python. So I have a function place_piece that places a piece at a row and column and then I have another function that checks if a row and column is free or not. It works but if I try to place 2 pieces the second piece overrides the first piece so I can only place one piece at a time. I want to be able to place an unlimited amount of pieces without them overriding each other.
Here's my code: I say that board = new_board() in the beginning before running the functions
def new_board():
board = {}
return board
def is_free(board, x, y):
x = x
y = y
if board["x"] == x and board["y"] == y:
return False
else:
return True
def place_piece(board, x, y, player):
board["x"] = x
board["y"] = y
board["player"] = player
return True
So basically I want to to be able to say place_piece(board,100,200,"player1") and place_piece(board,300,400,"player1") and then I want to check if these places are free with is_free(board,100,200) and is_free(board,100,200) and I want both of them to return False as they aren't free.
Can I somehow save each dictionary in a list or something?