Neumann_Janos_Verseny/fordulo_3/Program/Virus.cs
2025-03-14 09:18:00 +01:00

68 lines
1.8 KiB
C#

using System;
using System.Collections.Generic;
namespace Program
{
public class Virus
{
public int Name { get; set; }
public Virus Parent { get; set; }
public List<Virus> Infected { get; private set; }
public int InfectionTurn { get; set; }
public Virus(int name, int infectionTurn = 0)
{
Name = name;
Infected = new List<Virus>();
InfectionTurn = infectionTurn;
}
public Virus(int name, Virus parent, int infectionTurn = 0) : this(name, infectionTurn)
{
Parent = parent;
}
public void Infect(Virus virus)
{
virus.Parent = this;
Infected.Add(virus);
}
public void PrintInfectionTree(string indent = "")
{
Console.WriteLine($"{indent}Virus {Name}");
foreach (var infected in Infected)
{
infected.PrintInfectionTree(indent + " ");
}
}
public void PrintInfectionTreeWithDepth(int maxDepth, int currentDepth = 0, string indent = "")
{
if (currentDepth > maxDepth) return;
Console.WriteLine($"{indent}Virus {Name}");
foreach (var infected in Infected)
{
infected.PrintInfectionTreeWithDepth(maxDepth, currentDepth + 1, indent + " ");
}
}
public int CountInfectedInDepthRange(int minDepth, int maxDepth, int currentDepth = 0)
{
int count = 0;
if (currentDepth >= minDepth && currentDepth <= maxDepth)
{
count++;
}
foreach (var infected in Infected)
{
count += infected.CountInfectedInDepthRange(minDepth, maxDepth, currentDepth + 1);
}
return count;
}
}
}