Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ketszemelyesV1
- {
- class Csucs
- {
- public int szulosorszam;
- public int sorszam;
- public String nev;
- public int letezik;
- public List<int> gyerekekInt = new List<int>();
- public List<String> gyerekekString = new List<string>();
- public Csucs(int szulosorszam, int sorszam, String nev)
- {
- this.szulosorszam = szulosorszam;
- this.sorszam = sorszam;
- this.nev = nev;
- }
- }
- class Program
- {
- static void treeSetup(List<Csucs> lista)
- {
- /*
- * A
- * B C
- * D E F G H
- * I J K L
- *
- */
- lista.Add(new Csucs(0, 1, "A"));
- lista.Add(new Csucs(1, 2, "B"));
- lista.Add(new Csucs(1, 3, "C"));
- lista.Add(new Csucs(2, 4, "D"));
- lista.Add(new Csucs(2, 5, "E"));
- lista.Add(new Csucs(2, 6, "F"));
- lista.Add(new Csucs(3, 7, "G"));
- lista.Add(new Csucs(3, 8, "H"));
- lista.Add(new Csucs(4, 9, "I"));
- lista.Add(new Csucs(4, 10, "J"));
- lista.Add(new Csucs(6, 11, "K"));
- lista.Add(new Csucs(8, 12, "L"));
- /**/
- foreach (Csucs item in lista)
- {
- foreach (Csucs item2 in lista)
- {
- if (item.sorszam != item2.sorszam && item.sorszam == item2.szulosorszam)
- {
- item.gyerekekInt.Add(item2.sorszam);
- item.gyerekekString.Add(lista.Where(x => x.sorszam == item2.sorszam).First().nev);
- }
- }
- item.letezik = 1;
- }
- }
- static void kiirFullLista(List<Csucs> lista)
- {
- Console.WriteLine();
- foreach (Csucs item in lista)
- {
- if (item.letezik == 1)
- {
- Console.Write(item.sorszam + ".\t" + item.nev + "\t(szulo: " + item.szulosorszam + " gyerekei:");
- if (item.gyerekekInt.Count != 0)
- {
- foreach (int item2 in item.gyerekekInt)
- {
- Console.Write(" " + item2 + "(" + lista.Find(x => x.sorszam == item2).nev + ")");
- }
- }
- else
- Console.Write(" level elem");
- Console.WriteLine(")");
- }
- }
- }
- static void csucsGyerekeiTorlese(List<Csucs> lista)
- {
- hiba: Console.WriteLine();
- int sorszam = int.Parse(Console.ReadLine());
- if (lista.Find(x => x.sorszam == sorszam).gyerekekInt.Count() == 0)
- {
- Console.WriteLine("Nincs gyereke a csucsnak, minimum egy gyereket torolni kell, valasszon ujra!");
- goto hiba;
- }
- else
- {
- Csucs szulo = lista.Find(x => x.sorszam == sorszam);
- // unoka.szulosorszam updateje
- List<int> gyerekek = new List<int>();
- foreach (Csucs gyerek in lista.Where(x => x.szulosorszam == sorszam))
- foreach (int unoka in gyerek.gyerekekInt)
- gyerekek.Add(unoka);
- foreach (Csucs item in lista)
- if (gyerekek.Contains(item.sorszam) && item.letezik == 1)
- item.szulosorszam = sorszam;
- // szülő gyerekeinek torlese
- foreach (int item in szulo.gyerekekInt)
- {
- foreach (var item2 in lista)
- {
- if (item2.sorszam == item)
- lista.Find(x => x == item2).letezik = 0;
- }
- }
- // szülő.gyerekei update
- lista.Find(x => x.sorszam == sorszam).gyerekekInt.Clear();
- lista.Find(x => x.sorszam == sorszam).gyerekekString.Clear();
- foreach (Csucs item in lista)
- {
- if (item.szulosorszam == sorszam && item.letezik == 1)
- {
- lista.Find(x => x.sorszam == sorszam).gyerekekInt.Add(item.sorszam);
- lista.Find(x => x.sorszam == sorszam).gyerekekString.Add(item.nev);
- }
- }
- }
- }
- static void singlePlayer(List<Csucs> lista)
- {
- while (lista.Count() != 1)
- {
- int elem = 0;
- foreach (var item in lista)
- {
- if (item.letezik == 1)
- elem++;
- }
- if (elem == 1) break;
- csucsGyerekeiTorlese(lista);
- kiirFullLista(lista);
- }
- }
- static void multiPlayer(List<Csucs> lista, int player)
- {
- if (lista.Where(x => x.letezik == 1).Count() != 1)
- {
- for (int i = 1; i <= lista.Count(); i++)
- {
- List<Csucs> listacopy = new List<Csucs>();
- foreach (Csucs csucs in lista.Where(x => x.letezik == 1))
- {
- listacopy.Add(new Csucs(csucs.szulosorszam, csucs.sorszam, csucs.nev));
- foreach (var item in csucs.gyerekekInt)
- listacopy.Find(x => x.sorszam == csucs.sorszam).gyerekekInt.Add(item);
- foreach (var item in csucs.gyerekekString)
- listacopy.Find(x => x.sorszam == csucs.sorszam).gyerekekString = csucs.gyerekekString;
- listacopy.Find(x => x.sorszam == csucs.sorszam).letezik = csucs.letezik;
- }
- /*
- Console.WriteLine("i: " + i);
- listacopy.ForEach(delegate (Csucs s)
- {
- if (s.letezik == 1)
- Console.Write(" " + s.nev + "(" + s.sorszam +", " + (s.letezik == 1 ? "live" : "nem letezik") + ", " + s.gyerekekInt.Count() + " child)");
- });
- Console.WriteLine();
- */
- int sorszam = i;
- if (listacopy.Where(x => x.sorszam == sorszam).Count() == 0)
- continue;
- else if(listacopy.Find(x => x.sorszam == sorszam).letezik != 1 || listacopy.Find(x => x.sorszam == sorszam).gyerekekInt.Count == 0)
- continue;
- else
- {
- Csucs szulo = listacopy.Find(x => x.sorszam == sorszam);
- // unoka.szulosorszam updateje
- List<int> gyerekek = new List<int>();
- foreach (Csucs gyerek in listacopy.Where(x => x.szulosorszam == sorszam))
- foreach (int unoka in gyerek.gyerekekInt)
- gyerekek.Add(unoka);
- foreach (Csucs item in listacopy)
- if (gyerekek.Contains(item.sorszam) && item.letezik == 1)
- item.szulosorszam = sorszam;
- // szülő gyerekeinek logikai törlése
- foreach (int item in szulo.gyerekekInt)
- {
- foreach (var item2 in listacopy)
- {
- if (item2.sorszam == item)
- {
- listacopy.Find(x => x == item2).letezik = 0;
- listacopy.Find(x => x == item2).gyerekekInt.Clear();
- listacopy.Find(x => x == item2).gyerekekString.Clear();
- }
- }
- }
- // szülő gyerekeinek updateje
- listacopy.Find(x => x.sorszam == sorszam).gyerekekInt.Clear();
- listacopy.Find(x => x.sorszam == sorszam).gyerekekString.Clear();
- foreach (Csucs item in listacopy)
- {
- if (item.szulosorszam == sorszam && item.letezik == 1)
- {
- listacopy.Find(x => x.sorszam == sorszam).gyerekekInt.Add(item.sorszam);
- listacopy.Find(x => x.sorszam == sorszam).gyerekekString.Add(item.nev);
- }
- }
- }
- if (player == 1)
- multiPlayer(listacopy, 2);
- if (player == 2)
- multiPlayer(listacopy, 1);
- }
- }
- else if (lista.Where(x => x.letezik == 1).Count() == 1 && player == 2)
- lehetsegesEredmenyek.Add(1);
- else if (lista.Where(x => x.letezik == 1).Count() == 1 && player == 1)
- lehetsegesEredmenyek.Add(-1);
- else lehetsegesEredmenyek.Add(0);
- }
- /*class Eredmenyek
- {
- public int eredmeny;
- public int sorszam;
- }*/
- public static List<int> lehetsegesEredmenyek = new List<int>();
- //public static int num;
- static void check(List<Csucs> lista)
- {
- List<Csucs> listacopy = lista;
- if (listacopy.Count() != 0)
- {
- listacopy.ForEach(delegate (Csucs a)
- {
- Console.Write(" " + a.nev);
- });
- Console.WriteLine();
- listacopy.Remove(listacopy.Find(x => x.sorszam == listacopy.Max(y => y.sorszam)));
- check(listacopy);
- }
- }
- static void Main(string[] args)
- {
- List<Csucs> lista = new List<Csucs>();
- treeSetup(lista);
- //kiirFullLista(lista);
- //singlePlayer(lista);
- multiPlayer(lista, 1);
- if (lehetsegesEredmenyek.Contains(1))
- Console.WriteLine("win");
- else
- Console.WriteLine("lose");
- lehetsegesEredmenyek.ForEach(delegate (int a)
- {
- Console.Write(" " + a);
- });
- //check(lista);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement