Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Bulls_and_Cows_12._08._19
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.Write("Please enter your number: ");
- int enterNum = int.Parse(Console.ReadLine());
- List<int> myNum = new List<int>();
- while (enterNum > 0)
- {
- myNum.Add(enterNum % 10);
- enterNum /= 10;
- }
- myNum.Reverse();
- var compNum = new List<int>(4);
- var cowList = new List<int>(4);
- var bullList = new List<int>(4);
- Random compRndNum = new Random();
- compNum.Add(compRndNum.Next(0, 10));
- compNum.Add(compRndNum.Next(0, 10));
- compNum.Add(compRndNum.Next(0, 10));
- compNum.Add(compRndNum.Next(0, 10));
- int cowCount = 0;
- while (cowList.Count < 4)
- {
- while ((compNum[0] == 0) || (compNum[0] == compNum[1] || compNum[0] == compNum[2] || compNum[0] == compNum[3] ||
- compNum[1] == compNum[0] || compNum[1] == compNum[2] || compNum[1] == compNum[3] ||
- compNum[2] == compNum[0] || compNum[2] == compNum[1] || compNum[2] == compNum[3] ||
- compNum[3] == compNum[0] || compNum[3] == compNum[1] || compNum[3] == compNum[2]))
- {
- if (compNum[0] == 0)
- {
- Console.WriteLine($"Number is: {string.Join("", compNum)}");
- System.Threading.Thread.Sleep(1200);
- Console.WriteLine("ERROR - There is number start with zero");
- System.Threading.Thread.Sleep(1200);
- compNum.Clear();
- Console.WriteLine("Pick new number");
- System.Threading.Thread.Sleep(1200);
- compNum.Add(compRndNum.Next(0, 10));
- compNum.Add(compRndNum.Next(0, 10));
- compNum.Add(compRndNum.Next(0, 10));
- compNum.Add(compRndNum.Next(0, 10));
- }
- if (compNum[0] == compNum[1] || compNum[0] == compNum[2] || compNum[0] == compNum[3] ||
- compNum[1] == compNum[0] || compNum[1] == compNum[2] || compNum[1] == compNum[3] ||
- compNum[2] == compNum[0] || compNum[2] == compNum[1] || compNum[2] == compNum[3] ||
- compNum[3] == compNum[0] || compNum[3] == compNum[1] || compNum[3] == compNum[2])
- {
- Console.WriteLine($"Number is: {string.Join("", compNum)}");
- System.Threading.Thread.Sleep(1200);
- Console.WriteLine("ERROR - There is two equal numbers");
- System.Threading.Thread.Sleep(1200);
- compNum.Clear();
- Console.WriteLine("Pick new number");
- System.Threading.Thread.Sleep(1200);
- compNum.Add(compRndNum.Next(0, 10));
- compNum.Add(compRndNum.Next(0, 10));
- compNum.Add(compRndNum.Next(0, 10));
- compNum.Add(compRndNum.Next(0, 10));
- }
- }
- if (myNum.Contains(compNum[0]) && (!cowList.Contains(compNum[0])))
- {
- cowCount++;
- Console.WriteLine($"Number is: {string.Join("", compNum)}");
- System.Threading.Thread.Sleep(1000);
- Console.WriteLine($"I found cow, its number: {compNum[0]}.");
- System.Threading.Thread.Sleep(1000);
- cowList.Add(compNum[0]);
- }
- if (myNum.Contains(compNum[1]) && (!cowList.Contains(compNum[1])))
- {
- cowCount++;
- Console.WriteLine($"Number is: {string.Join("", compNum)}");
- System.Threading.Thread.Sleep(1000);
- Console.WriteLine($"I found cow, its number: {compNum[1]}.");
- System.Threading.Thread.Sleep(1000);
- cowList.Add(compNum[1]);
- }
- if (myNum.Contains(compNum[2]) && (!cowList.Contains(compNum[2])))
- {
- cowCount++;
- Console.WriteLine($"Number is: {string.Join("", compNum)}");
- System.Threading.Thread.Sleep(1000);
- Console.WriteLine($"I found cow, its number: {compNum[2]}.");
- System.Threading.Thread.Sleep(1000);
- cowList.Add(compNum[2]);
- }
- if (myNum.Contains(compNum[3]) && (!cowList.Contains(compNum[3])))
- {
- cowCount++;
- Console.WriteLine($"Number is: {string.Join("", compNum)}");
- System.Threading.Thread.Sleep(1000);
- Console.WriteLine($"I found cow, its number: {compNum[3]}.");
- System.Threading.Thread.Sleep(1000);
- cowList.Add(compNum[3]);
- }
- compNum.Clear();
- compNum.Add(compRndNum.Next(0, 10));
- compNum.Add(compRndNum.Next(0, 10));
- compNum.Add(compRndNum.Next(0, 10));
- compNum.Add(compRndNum.Next(0, 10));
- }
- Console.WriteLine($"All the cows are: {string.Join("", cowList)}");
- System.Threading.Thread.Sleep(1200);
- if (cowList.Count == 4)
- {
- Console.WriteLine("");
- Console.WriteLine("Start serching for bulls !!!");
- System.Threading.Thread.Sleep(1200);
- for (int i = 0; i < myNum.Count; i++)
- {
- if (cowList[i] == myNum[0])
- {
- Console.WriteLine($"Current number is: {cowList[i]}");
- System.Threading.Thread.Sleep(1200);
- var rightPosition = myNum.IndexOf(myNum[0]);
- Console.WriteLine($"Rigth position is: {myNum.IndexOf(myNum[0])}");
- System.Threading.Thread.Sleep(1200);
- Console.WriteLine($"I will insert {cowList[i]} at {myNum.IndexOf(myNum[0])} position.");
- System.Threading.Thread.Sleep(1200);
- bullList.Insert(rightPosition, cowList[i]);
- }
- }
- for (int i = 0; i < myNum.Count; i++)
- {
- if (cowList[i] == myNum[1])
- {
- Console.WriteLine($"Current number is: {cowList[i]}");
- System.Threading.Thread.Sleep(1200);
- var rightPosition = myNum.IndexOf(myNum[1]);
- Console.WriteLine($"Rigth position is: {myNum.IndexOf(myNum[1])}");
- System.Threading.Thread.Sleep(1200);
- Console.WriteLine($"I will insert {cowList[i]} at {myNum.IndexOf(myNum[1])} position.");
- System.Threading.Thread.Sleep(1200);
- bullList.Insert(rightPosition, cowList[i]);
- }
- }
- for (int i = 0; i < myNum.Count; i++)
- {
- if (cowList[i] == myNum[2])
- {
- Console.WriteLine($"Current number is: {cowList[i]}");
- System.Threading.Thread.Sleep(1200);
- var rightPosition = myNum.IndexOf(myNum[2]);
- Console.WriteLine($"Rigth position is: {myNum.IndexOf(myNum[2])}");
- System.Threading.Thread.Sleep(1200);
- Console.WriteLine($"I will insert {cowList[i]} at {myNum.IndexOf(myNum[2])} position.");
- System.Threading.Thread.Sleep(1200);
- bullList.Insert(rightPosition, cowList[i]);
- }
- }
- for (int i = 0; i < myNum.Count; i++)
- {
- if (cowList[i] == myNum[3])
- {
- Console.WriteLine($"Current number is: {cowList[i]}");
- System.Threading.Thread.Sleep(1200);
- var rightPosition = myNum.IndexOf(myNum[3]);
- Console.WriteLine($"Rigth position is: {myNum.IndexOf(myNum[3])}");
- System.Threading.Thread.Sleep(1200);
- Console.WriteLine($"I will insert {cowList[i]} at {myNum.IndexOf(myNum[3])} position.");
- System.Threading.Thread.Sleep(1200);
- bullList.Insert(rightPosition, cowList[i]);
- }
- }
- }
- Console.WriteLine($"I Guess !!!\nYour umber is: {string.Join("", bullList)} !!!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement