Skip to content

Commit

Permalink
improved the remove matches from board algorithm so it does not take …
Browse files Browse the repository at this point in the history
…too much time
  • Loading branch information
ninetailsrabbit committed Jun 7, 2024
1 parent a3b17ed commit 6b328a6
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Match3Maker/src/components/Board.cs
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,15 @@ public void RemoveMatchesFromBoard() {

while (sequences.Count > 0) {
foreach (Sequence sequence in sequences) {
var cellsToChange = sequence.Cells.Take((sequence.Cells.Count / 3) + 1);
var pieceTypesToChange = cellsToChange.Select(cell => cell.Piece.Type);

foreach (GridCell currentCell in sequence.Cells) {
var availablePieces = AvailablePieces.Where(piece => !piece.Type.Shape.Equals(currentCell.Piece.Type.Shape)).ToList();
var availablePieces = AvailablePieces.Where(piece => {
return !pieceTypesToChange.Contains(piece.Type)
&& !pieceTypesToChange.Select(pieceType => pieceType.Shape).Contains(piece.Type.Shape);
}).ToList();

foreach (GridCell currentCell in cellsToChange) {
var newPiece = PieceGenerator.Roll(availablePieces, [currentCell.Piece.Type.GetType()]);

if (newPiece is not null) {
Expand Down

0 comments on commit 6b328a6

Please sign in to comment.