Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
7.2 kB
1
Indexable
Never
using System;
//Problem: Every single number gets eliminated

namespace testconsole
{
    internal class Program
    {
        int correct = 0;
        int wrong = 0;
        int number = 1234;
        public int[] list = new int[9877];
        int digit1;
        int digit2;
        int firstOne;
        int digit3;
        int digit4;
        int arrayItemPick;
        string playerNumber;
        string cInput1;
        string cInput2;
        int cInput1int;
        int cInput2int;
        bool value = false;
        public static bool win_;    
        int computerGuessNumber = 0;
        Random rnd = new Random();
        static void Main(string[] args)

        {
            Program some = new Program();
            some.askForNumber();
            some.createArray();
            some.avoidImposible();
   
            do
            {
                some.checkWin();
                some.computerGuessNumber++;
                some.selectArrayItem();
                some.checkForCorrectness();

                foreach (int i in some.list)
                {
                    if (i != 0)
                    {
                        some.firstOne = some.list[some.arrayItemPick];
                        some.value = some.Function(some.firstOne, i, some.cInput1int, some.cInput2int);
                        Console.WriteLine("some.list[some.arrayItemPick: " + some.list[some.arrayItemPick]);
                        if (some.value == false)
                        {
                            some.list[i] = 0;
                        }
                        if (some.cInput1int == 4)
                        {
                            win_ = true;
                        }
                    }
                }
                some.checkWin();
            } while (win_ is false);
            Console.ReadKey();
        }
        
        public void createArray()
        {
            // Creates array that ranges from 1234-9876
            do
            {
                list[number] = number;
                number = number + 1;
            } while (number < 9877);
        }
        
        public void avoidImposible()
        {
            foreach (int i in list)
            {
                

                //Divides list by 4 
                if (list[i] != 0)
                {
                    digit1 = list[i].ToString()[0];
                    digit2 = list[i].ToString()[1];
                    digit3 = list[i].ToString()[2];
                    digit4 = list[i].ToString()[3];

                    digit1 = digit1 - 48;
                    digit2 = digit2 - 48;
                    digit3 = digit3 - 48;
                    digit4 = digit4 - 48;
                }

                // Checks if the number has a 0 in it

                if (digit1 == 0 || digit2 == 0 || digit3 == 0 || digit4 == 0)
                {
                    // Sets the certain array item to 0
                    list[i] = 0;
                }

                //Checks if the number has duplicates

                if (digit1 == digit2 || digit1 == digit3 || digit1 == digit4 || digit2 == digit3 || digit2 == digit4 || digit3 == digit4)
                {
                    // Sets the certain array item to 0
                    list[i] = 0;
                }
            }
        }

        public void printArray()
        {
            foreach (int i in list)
            {
                if (list[i] != 0)
                {
                    Console.WriteLine(list[i]);
                }
            }
        }

        public void askForNumber()
        {
            Console.WriteLine("Enter your 4 digit number that does not contain 0's or repeating digits: ");
            playerNumber = Console.ReadLine();
            Console.WriteLine("Enter in '{possitive number},{negative number}' form: ");
        }

        public void selectArrayItem()
        {
            
            int arrayItemPick = rnd.Next(0, list.Length);
            if (list[arrayItemPick] != 0)
            {
                Console.WriteLine(list[arrayItemPick]);
            }
            if (list[arrayItemPick] == 0)
            {
                selectArrayItem();
                Console.WriteLine("list arrayitempick was 0");
            }
        }

        public void checkForCorrectness()
        {

            string correctnessInput = Console.ReadLine();
            string cInput1 = ToSplit(correctnessInput, 0);
            string cInput2 = ToSplit(correctnessInput, 1);
            int cInput1int = Convert.ToInt32(cInput1);
            int cInput2int = Convert.ToInt32(cInput2);

        }

        string ToSplit(string a, int b)
        {
            return a.Split(',')[b];
        }
        bool Function(int num1, int num2, int otherCorrect, int otherWrong)
        {
            int num11 = num1.ToString()[0];
            int num12 = num1.ToString()[1];
            int num13 = num1.ToString()[2];
            int num14 = num1.ToString()[3];
            int num21 = num2.ToString()[0];
            int num22 = num2.ToString()[1];
            int num23 = num2.ToString()[2];
            int num24 = num2.ToString()[3];

            num11 = num11 - 48;
            num12 = num12 - 48;
            num13 = num13 - 48;
            num14 = num14 - 48;

            num21 = num21 - 48;
            num22 = num22 - 48;
            num23 = num23 - 48;
            num24 = num24 - 48;

            if (num11 == num21)
            {
                correct++;
            }
            if (num11 == num22 || num11 == num23 || num11 == num24)
            {
                wrong++;
            }
            if (num12 == num22)
            {
                correct++;
            }
            if (num12 == num21 || num12 == num23 || num12 == num24)
            {
                wrong++;
            }
            if (num13 == num23)
            {
                correct++;
            }
            if (num13 == num21 || num13 == num22 || num13 == num24)
            {
                wrong++;
            }
            if (num14 == num24)
            {
                correct++;
            }
            if (num14 == num21 || num14 == num22 || num14 == num23)
            {
                wrong++;
            }


            Console.WriteLine("Correct: " + correct + " Wrong: " + wrong);
            Console.WriteLine("otherCorrect: " + otherCorrect + " otherWrong: " + otherWrong);
            if (correct == otherCorrect && wrong == otherWrong)
            {
                Console.WriteLine("True");
                
                return true;

            }
            else
            {
                Console.WriteLine("False");
                return false;
            }
        }


        public void checkWin()
        {
            if (win_ == true)
            {
                Console.WriteLine("Computer Guessed your number in " + computerGuessNumber + " tries!");
            }
        }
    }
}