#๐ Terminal based chess game
23 messages ยท Page 1 of 1 (latest)
@fringe orbit
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
why use IDs when you can just use "the piece"
I'm creating a class for each piece so I wanted some way to associate the piece to the player
class King(Piece):
... # implement king functionality
class Queen(Piece):
... # implement queen functionality
# ... etc.
board = [
[Rook(), Night(), Bishop(), King(), Queen(), Bishop(), Night(), Rook()],
[Pawn(), Pawn(), Pawn(), Pawn(), Pawn(), Pawn(), Pawn(), Pawn()],
[EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,]
[EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,]
[EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,]
[EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,]
[Pawn(), Pawn(), Pawn(), Pawn(), Pawn(), Pawn(), Pawn(), Pawn()],
[Rook(), Night(), Bishop(), Queen(), King(), Bishop(), Night(), Rook()],
]
This seems like a good way to do it
and you can pass in Pawn(Black) or whatever
or Pawn("black") or Pawn(2) or Pawn(Color.BLACK) or however you want to do it
Yeah but when I switch players I want them to have limited access to the pieces. It seems cleaner than checking all pieces to see if it contains a certain color attribute
oh so maybe store each piece in each users array? and then when it's their turn I can go through that array and get each of their available moves?
you could do that
but it's quite nice to be able to do stuff like ```py
if piece1.color == piece2.color:
print("that location is occupied already")
else:
print(f"congrats, your {piece1} has captured your enemy's {piece2}")
you could always just do both - store a list of pieces for each team and set an attribute to keep track of the color of the piece
When I made my chess game I didn't need to store a list of pieces for each color, but there's no reason that it has to be that way. Do it however you want :)
hmm, good notes, thanks! Here's my Github if you ever want to check out the progress or have a couple matches on chess.com lol
If you're curious, here's the chess program I made a couple of years ago. Might be useful or at least interesting to cross reference
. Never got a chance to upload it to github.
it's meant to work with this GUI frontend
cool! Going to try to think my way through the design a little more before I look lol
yeah definitely
I share it pretty much just because it has coverage of some strange chess situations like en passant and castling into check etc. which might be tricky to implement correctly
but yeah definitely get your own thing setup
haha yeah I was thinking about that. Lot of edge cases
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.