Draft
Conversation
GameState is meant to be an immutable structure and GameBoard is very, very mutable
Fayti1703
commented
Jan 7, 2025
| public readonly struct GameState { | ||
| public readonly int turnCounter; | ||
| public readonly GameBoard board; | ||
| public readonly IReadOnlyList<IEnumerable<Card>> board; |
Owner
Author
There was a problem hiding this comment.
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).
| @@ -54,9 +57,7 @@ public CardList(IEnumerable<Card> cards) { | |||
| } | |||
|
|
|||
| public CardList(IList<Card> cards) { | |||
Owner
Author
There was a problem hiding this comment.
This can be weakened to ICollection<Card> (possibly outside this branch) to allow ImmutableList<Card>-to-CardList conversions.
Owner
Author
There was a problem hiding this comment.
TODO: Figure out why we didn't do this earlier. CreateListFromCollection is basically the constructor minus the FAIL_FAST_INVALID checks.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently, you can inadvertently modify a
GameStateby messing with itsGameBoard.GameStateis meant to be an immutable snapshot of a game state, so this is problematic.Includes some other refactoring that may be pulled in separately.