Click here to Skip to main content
15,881,801 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
My class spot takes in an x and y value to create coordinates on my board.
I have a function responsible for moving my chess piece from its current set of coordinates to a new set of coordinates by subtracting the starting x and ending x and the same for the starting y and ending y. The problem I am facing is I get an error when I take in duplicates of a class instance in the function arguments responsible for moving my chess piece from its current set of coordinates to a new set of coordinates.


class Spot:

    def __init__(self, x, y, piece):
        self.x = x
        self.y = y
        self.piece = piece



def canMove(self, board, spot start, spot end):
       pass


What I have tried:

I have tried passing in the names of the class instances instead of having it as a type followed by a name. If I do that, how would I distinguish the starting and ending coordinates? I also get a duplicate error for this
Posted
Updated 5-Aug-20 19:00pm
Comments
Afzaal Ahmad Zeeshan 4-Aug-20 21:33pm    
Not sure, but are you allowed to use spot start in the parameters? That should be an error.

Try changing that to:


def cavMove(self, board, start, end):
pass

This should work for you.
Richard MacCutchan 5-Aug-20 3:33am    
That is the solution. Ignoring the fact that the pass statement means the function does not do anything.
mohamaddibassy123 5-Aug-20 18:20pm    
Thank you, the pass keyword is included in this function because it is meant to be an abstract function.
mohamaddibassy123 5-Aug-20 18:22pm    
Thank you

1 solution

Hope the Below link is help.

stackoverflow.com/questions/23914583/python-classes-duplicate-instances
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900