private bool IsOpponentInCell(Pac pac, Cell currentCell) { var open = new List <Cell> { currentCell }; var seen = new HashSet <Cell> { currentCell }; var count = 0; var maxCount = 2; while (open.Any()) { var tempCell = open.First(); open.RemoveAt(0); var opponentPac = GetPacInCell(tempCell, _game.OpponentPlayer.Pacs); if (opponentPac != null) { if (pac.CanBeEaten(opponentPac.Type)) { return(true); } } if (count < maxCount) { foreach (var(_, neighbour) in currentCell.Neighbours) { if (seen.Add(neighbour)) { open.Add(neighbour); } } } count++; } return(false); }