示例#1
0
 //function that checks how many similaritis are their
 public static int HowManySameAll(Row first, Row second)
 {
     int total = 0;
     bool[] didThisup = new bool[first.row.Length];
     bool[] didThisdown = new bool[second.row.Length];
     for (int i = 0; i < first.row.Length; i++)
     {
         for (int z = 0; z < second.row.Length; z++)
         {
             if (first.row[i].numcolor == second.row[z].numcolor && didThisdown[z] == false && didThisup[i] == false)
             {
                 total++;
                 didThisdown[z] = true;
                 didThisup[i] = true;
             }
         }
     }
     return total;
 }
示例#2
0
        public static void logic(Random rnd)
        {
            Manager manager = new Manager(rnd);
            Row a = new Row();
            int count = 0;
            do
            {
                if (manager.possibilities.Count == 0)
                {
                    Console.WriteLine("mistake");
                    break;
                }
                    a = manager.possibilities[rnd.Next(manager.possibilities.Count - 1)] as Row;
                a.pins(manager.answer, a);
                Console.WriteLine(manager.answer.ToString() + " answer\n");
                Console.WriteLine(a.ToString() + " guess\n");
                Console.WriteLine(a.black_pins + " " + a.white_pins);

                //goes threw the hole array from up to down and erases the not possible options
                for (int i = manager.possibilities.Count - 1; i >= 0; i--)
                {
                    Row check = manager.possibilities[i] as Row;
                    int samePlace = HowManySamePlace(a, check);
                    int amount = HowManySameAll(a, check);

                    //the logic
                    if (a.black_pins != samePlace || amount > a.white_pins + a.black_pins)
                        manager.possibilities.RemoveAt(i);

                }
                count++;
            } while (a.black_pins < 4);

            Console.WriteLine("it took " + count + " times");
        }
示例#3
0
 //creates the white and black pins
 public void pins(Row answer, Row row)
 {
     bool[] didThisup = new bool[answer.row.Length];
     bool[] didThisdown = new bool[row.row.Length];
     //black pins
     for (int i = 0; i < answer.row.Length; i++)
     {
          if (answer.row[i].numcolor == row.row[i].numcolor)
          {
              row.black_pins++;
              didThisdown[i] = true;
              didThisup[i] = true;
          }
     }
     //white pins
     for (int i = 0; i < answer.row.Length; i++)
     {
         for (int z = 0; z < row.row.Length; z++)
         {
             if (answer.row[i].numcolor == row.row[z].numcolor && didThisdown[z] == false && didThisup[i] == false)
             {
                 row.white_pins++;
                 didThisdown[z] = true;
                 didThisup[i] = true;
             }
         }
     }
 }
示例#4
0
 //function that checks how many are at the same place
 public static int HowManySamePlace(Row first, Row second)
 {
     int total = 0;
     for (int i = 0; i < first.row.Length; i++)
     {
         if (first.row[i].numcolor == second.row[i].numcolor)
             total++;
     }
     return total;
 }