Skip to content

Conversation

@Fayti1703
Copy link
Owner

Currently, you can inadvertently modify a GameState by messing with its GameBoard. GameState is meant to be an immutable snapshot of a game state, so this is problematic.


Includes some other refactoring that may be pulled in separately.

@Fayti1703 Fayti1703 added correctness incorrect behavior z-project: engine something in the engine itself labels Jan 7, 2025
public readonly struct GameState {
public readonly int turnCounter;
public readonly GameBoard board;
public readonly IReadOnlyList<IEnumerable<Card>> board;
Copy link
Owner Author

@Fayti1703 Fayti1703 Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be an IReadOnlyList<IReadOnlyList<Card>> instead. Question is whether serialization overhead from CardList <-> ImmutableList<Card> is going to be a problem (I'd hope no).

}
}

public CardList(IList<Card> cards) {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be weakened to ICollection<Card> (possibly outside this branch) to allow ImmutableList<Card>-to-CardList conversions.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Figure out why we didn't do this earlier. CreateListFromCollection is basically the constructor minus the FAIL_FAST_INVALID checks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

correctness incorrect behavior z-project: engine something in the engine itself

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants