#๐Ÿ”’ Terminal based chess game

23 messages ยท Page 1 of 1 (latest)

fringe orbit
#

I'm making a chess terminal based game. For each player, do you think I should have a dictionary containing ids that map to each piece I create. So I can use the id's to access each piece and get each of their available moves?

frail anvilBOT
#

@fringe orbit

Python help channel opened

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.

minor geyser
#

why use IDs when you can just use "the piece"

fringe orbit
minor geyser
#
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

fringe orbit
#

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

fringe orbit
minor geyser
#

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 :)

fringe orbit
minor geyser
#

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 shrug . Never got a chance to upload it to github.

#

it's meant to work with this GUI frontend

fringe orbit
minor geyser
#

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

fringe orbit
#

haha yeah I was thinking about that. Lot of edge cases

frail anvilBOT
#
Python help channel closed

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.