Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This can move function checks if your piece(comprised of two coordinates on the board created from a class called spot) is on the board(8 by 8 matrix), intended landing spot/area is unoccupied and if it is occupied then it must be by the opposing color.

Below is the spot class I have created.


class spot:

    def spot(self, x, y ,Piece piece):
        self.setX(x)
        self.setY(y)
        self.setPiece(piece)

    def getX(self):
        return self.x

    def getY(self):
        return self.y

    def getPiece(self):
        return self.piece

    def setX(self, x):
        self.x = x

    def setY(self, y):
        self.y = y

    def setPiece(self, piece):
        self.piece = piece


What I have tried:

I have started this function but can't seem to figure out if I should take in one spot or two spots in my function argument. I can't figure out how I'll be able to determine if the piece on the intended landing spot is of the opposing color.
Posted
Updated 1-Jul-20 13:42pm

1 solution

I am not a Python programmer, so I can't help you with code. However, a few observations.

- You need to know the color of the piece that occupies a square.
- You need two flags for each side, to indicate whether O-O and O-O-O are legal.
- You need to know if an en passant capture is allowed. This could simply be inserted, when it arises, as the first candidate move for whoever is to move next.

If you want to make this efficient

- Get rid of the (x,y) indexing
- Just assign each square a number (a single index)
- Build (when your program initializes) a list of all the squares which a given type of piece, starting on a particular square, could move to on an open board, in the order that those squares would be visited (there will be more than one such list for each type of piece)

You can take it from there.
 
Share this answer
 
v2

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