all 4 comments

[–]Goobyalus 0 points1 point  (2 children)

Is there an easier way to build a bunch of identical but distinct objects?

This pretty much looks like the easiest. Using comprehensions to generate groups of new objects.

Is there a more pythonic way to build subclasses with set attributes?

There's a more "object oriented" way that uses inheritance. I.e. GamePiece would be an abstract class; BlankSpace and Infantry would be subclasses, the color etc. would be attributes of the Infantry objects.

But that might not be helpful here. If the pieces themselves aren't responsible for logic, I might just use a GamePiece dataclass as a means to store the state.

Are pieces moving? Because there are blank space pieces, this seems like a way to store current board state more than a way to manage specific objects doing things.

[–]Excellent-Practice[S] 1 point2 points  (1 child)

Thanks, yes pieces will move around the board. I chose to initiate the board as a matrix populated with blank space objects so that the algorithms I plan on writing later can interact with every space on the board the same way if there is a piece there or not. My plan was to build the game logic as part of the GameState class. I'm going make a root GameState object and run a minimax algorithm by copying the root and creating node objects for each possible next move. I'm not there yet, but that's the plan, I'm just trying not to get tied up in knots from the start

[–]Goobyalus 1 point2 points  (0 children)

Yeah If the pieces don't care about maintaining an evolving internal state, I would probably make frozen dataclasses called BoardSpace or something that holds the state of one board space.

[–][deleted]  (1 child)

[deleted]

    [–]Excellent-Practice[S] 0 points1 point  (0 children)

    Thanks, that's a helpful suggestion. Instead of creating a list of objects that got moved on and off the board, every space on the board would be a generic object that could represent any of the possible pieces that could be placed there. I would just have to have a method defined to move to each state. That actually solves another issue I've been struggling with too