Skip to content

Commit 42340a3

Browse files
committed
Copied the selected fields to prevent every move holding references to the same fields / pegs.
1 parent 8d4460e commit 42340a3

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/Codebreaker.ViewModels/Pages/GamePageViewModel.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ private async Task MakeMoveAsync(CancellationToken cancellationToken)
8585
{
8686
var response = await gamesClient.SetMoveAsync(Game.Id, Game.PlayerName, GameType.Game6x4, Game.Moves.Count + 1, serializedFields);
8787

88-
var newMove = new Move(SelectedFields, response.Results);
88+
// It is necessary to copy the fields to avoid every move having the same reference to the same fields
89+
var copiedFields = SelectedFields.Select(f => new Field(f.Color, f.Shape)).ToArray();
90+
var newMove = new Move(copiedFields, response.Results);
8991
Game.Moves.Add(newMove);
9092
WeakReferenceMessenger.Default.Send(new MakeMoveMessage(newMove));
9193

0 commit comments

Comments
 (0)