-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make GameState
more read-only
#30
base: trunk
Are you sure you want to change the base?
Conversation
GameState is meant to be an immutable structure and GameBoard is very, very mutable
@@ -5,15 +5,15 @@ namespace BinaryMatrix.Engine; | |||
|
|||
public readonly struct GameState { | |||
public readonly int turnCounter; | |||
public readonly GameBoard board; | |||
public readonly IReadOnlyList<IEnumerable<Card>> board; |
There was a problem hiding this comment.
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<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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Currently, you can inadvertently modify a
GameState
by messing with itsGameBoard
.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.