public void Apply(Sweep sweep, IMessageLog log) { List <Slot> slotsToClear = new List <Slot>(); Tuple <Slot, Slot> bounds = sweep.Bounds; IEnumerable <Slot> searchSet = null; if (bounds.Item1.X == bounds.Item2.X) { searchSet = game.Board.Column(bounds.Item1.X); } else { searchSet = game.Board.Row(bounds.Item1.Y); } List <Slot> currentRun = new List <Slot>(); foreach (var slot in searchSet) { if (slot.Piece == null) { if (currentRun.Count >= Target) { slotsToClear.AddRange(currentRun); } currentRun.Clear(); } else { if (currentRun.Count > 0 && currentRun.First().Piece.Owner != slot.Piece.Owner) { if (currentRun.Count >= Target) { slotsToClear.AddRange(currentRun); } currentRun.Clear(); } currentRun.Add(slot); } } if (currentRun.Count >= Target) { slotsToClear.AddRange(currentRun); } foreach (var slot in slotsToClear) { log.RemovePiece(slot); slot.Piece.Owner.Score++; slot.Piece = null; } if (slotsToClear.Count > 0) { log.UpdateScores(game); } }
public void Apply(Sweep sweep, IMessageLog log) { List<Slot> slotsToClear = new List<Slot>(); Tuple<Slot, Slot> bounds = sweep.Bounds; IEnumerable<Slot> searchSet = null; if (bounds.Item1.X == bounds.Item2.X) searchSet = game.Board.Column(bounds.Item1.X); else searchSet = game.Board.Row(bounds.Item1.Y); List<Slot> currentRun = new List<Slot>(); foreach (var slot in searchSet) { if (slot.Piece == null) { if (currentRun.Count >= Target) slotsToClear.AddRange(currentRun); currentRun.Clear(); } else { if (currentRun.Count > 0 && currentRun.First().Piece.Owner != slot.Piece.Owner) { if (currentRun.Count >= Target) slotsToClear.AddRange(currentRun); currentRun.Clear(); } currentRun.Add(slot); } } if (currentRun.Count >= Target) slotsToClear.AddRange(currentRun); foreach (var slot in slotsToClear) { log.RemovePiece(slot); slot.Piece.Owner.Score++; slot.Piece = null; } if(slotsToClear.Count > 0) log.UpdateScores(game); }