예제 #1
0
        /// <summary>
        /// Verifies the color.
        /// 4.	绿色房子坐落在白色房子的左面。The green house is just to the left of the white one.
        /// 5.	绿色房子的主人喝咖啡。The owner of the green house drinks coffee.
        /// </summary>
        /// <param name="house">The house.</param>
        /// <returns></returns>
        public static bool VerifyColor(IntHouse house)
        {
            for (int i = 0; i < 5; i++)
            {
                switch (house[i, Enums.HouseType.National])
                {
                case 1:    //Blue
                    break;

                case 2:                                       //Green 绿色房子坐落在白色房子的左面
                    if (house[i, Enums.HouseType.Drink] != 1) //喝咖啡
                    {
                        return(false);
                    }
                    for (int j = i; j >= 0; j--)
                    {
                        if (house[j, Enums.HouseType.Color] == 1)
                        {
                            break;
                        }
                    }
                    return(false);

                case 3:    //Red
                case 4:    //White
                case 5:    //Yellow
                    break;
                }
            }
            return(true);
        }
예제 #2
0
        /// <summary>
        /// Verifies the national.
        /// 1.	英国人住红色房子里。The Englishman lives in the red house.
        /// 2.	瑞典人养狗。The Swede keeps dogs.
        /// 3.	丹麦人喝茶。The Dane drinks tea.
        /// </summary>
        /// <param name="house">The house.</param>
        /// <returns></returns>
        public static bool VerifyNational(IntHouse house)
        {
            for (int i = 0; i < 5; i++)
            {
                switch (house[i, Enums.HouseType.National])
                {
                case 1:    //Dane 喝茶
                    if (house[i, Enums.HouseType.Drink] != 0)
                    {
                        return(false);
                    }
                    break;

                case 2:    //English 红色房子
                    if (house[i, Enums.HouseType.Color] != 0)
                    {
                        return(false);
                    }
                    break;

                case 3:    //German
                case 4:    //Norwegian
                    break;

                case 5:    //Swede 养狗
                    if (house[i, Enums.HouseType.Drink] != 0)
                    {
                        return(false);
                    }
                    break;
                }
            }
            return(true);
        }
예제 #3
0
        /// <summary>
        /// Verifies the smoker.
        /// 6.	抽Pall Mall香烟的人养鸟。The Pall Mall smoker keeps birds.
        /// 10.	抽Blends香烟的住在养猫人的隔壁。The Blend smoker has a neighbor who keeps cats.
        /// 15.	抽Blends香烟的人有一个喝水的邻居。The Blend smoker has a neighbor who drinks water.
        /// 12.	抽Blue Master香烟的喝啤酒。The man who keeps horses lives next to the Dunhill smoker.
        /// 11.	抽Dunhill香烟者的隔壁养马。The man who smokes Blue Masters drinks bier.
        /// 7.	抽Dunhill香烟住黄色房子。The owner of the yellow house smokes Dunhills.
        /// 13.	德国人抽Prince香烟。The German smokes Prince.
        /// </summary>
        public static bool VerifySmoker(IntHouse house)
        {
            for (int i = 0; i < 5; i++)
            {
                switch (house[i, Enums.HouseType.Cigarette])
                {
                case 1:    //抽Blends香烟的住在养猫人的隔壁。
                    if (!((i - 1 >= 0 && house[i - 1, Enums.HouseType.Pet] == 2) ||
                          ((i + 1 < 5) && (house[i + 1, Enums.HouseType.Pet] == 2))))
                    {
                        return(false);
                    }     //抽Blends香烟的人有一个喝水的邻居。
                    if (!((i - 1 >= 0 && house[i - 1, Enums.HouseType.Drink] == 4) ||
                          ((i + 1 < 5) && (house[i + 1, Enums.HouseType.Drink] == 4))))
                    {
                        return(false);
                    }
                    break;

                case 2:    //BlueMaster 抽Blue Master香烟的喝啤酒
                    if (house[i, Enums.HouseType.Drink] != 3)
                    {
                        return(false);
                    }
                    break;

                case 3:    //Dunhill 隔壁养马 住黄色房子
                    if (house[i, Enums.HouseType.Color] != 3)
                    {
                        return(false);
                    }
                    if (!((i - 1 >= 0 && house[i - 1, Enums.HouseType.Pet] == 3) ||
                          ((i + 1 < 5) && (house[i + 1, Enums.HouseType.Pet] == 3))))
                    {
                        return(false);
                    }
                    break;

                case 4:    //PallMall 养鸟
                    if (house[i, Enums.HouseType.Pet] != 1)
                    {
                        return(false);
                    }
                    break;

                case 5:    //Prince 德国人
                    if (house[i, Enums.HouseType.National] != 4)
                    {
                        return(false);
                    }
                    break;
                }
            }
            return(true);
        }
예제 #4
0
        void DoIntHouseBuilder()
        {
            _step = 0;
            foreach (int[] color in _Colors)
            {
                foreach (int[] national in _Nationals)
                {
                    foreach (int[] pet in _Pets)
                    {
                        foreach (int[] cigarette in _Cigarettes)
                        {
                            foreach (int[] drink in _Drinks)
                            {
                                IntHouse house = new IntHouse(color, national, pet, cigarette, drink);
                                if (house.Verify())
                                {
                                    this.ResultHouses.Add(house);
                                    this.SetCountLabel(this.ResultHouses.Count);
                                }
                                _step++;
                            }
                        }
                    }
                }
            }
            StringBuilder sb = new StringBuilder();

            if (this.ResultHouses.Count > 0)
            {
                foreach (var item in this.ResultHouses)
                {
                    sb.AppendLine(item.ToString());
                    sb.AppendLine();
                }
            }
            else
            {
                sb.AppendLine("Nothing......");
            }
            MessageBox.Show(sb.ToString());
        }
예제 #5
0
 void DoIntHouseBuilder()
 {
     _step = 0;
     foreach (int[] color in _Colors)
     {
         foreach (int[] national in _Nationals)
         {
             foreach (int[] pet in _Pets)
             {
                 foreach (int[] cigarette in _Cigarettes)
                 {
                     foreach (int[] drink in _Drinks)
                     {
                         IntHouse house = new IntHouse(color, national, pet, cigarette, drink);
                         if (house.Verify())
                         {
                             this.ResultHouses.Add(house);
                             this.SetCountLabel(this.ResultHouses.Count);
                         }
                         _step++;
                     }
                 }
             }
         }
     }
     StringBuilder sb = new StringBuilder();
     if (this.ResultHouses.Count > 0)
     {
         foreach (var item in this.ResultHouses)
         {
             sb.AppendLine(item.ToString());
             sb.AppendLine();
         }
     }
     else
         sb.AppendLine("Nothing......");
     MessageBox.Show(sb.ToString());
 }
예제 #6
0
 /// <summary>
 /// Verifies the smoker.
 /// 6.	抽Pall Mall香烟的人养鸟。The Pall Mall smoker keeps birds.
 /// 10.	抽Blends香烟的住在养猫人的隔壁。The Blend smoker has a neighbor who keeps cats.
 /// 15.	抽Blends香烟的人有一个喝水的邻居。The Blend smoker has a neighbor who drinks water.
 /// 12.	抽Blue Master香烟的喝啤酒。The man who keeps horses lives next to the Dunhill smoker.
 /// 11.	抽Dunhill香烟者的隔壁养马。The man who smokes Blue Masters drinks bier.
 /// 7.	抽Dunhill香烟住黄色房子。The owner of the yellow house smokes Dunhills.
 /// 13.	德国人抽Prince香烟。The German smokes Prince.
 /// </summary>
 public static bool VerifySmoker(IntHouse house)
 {
     for (int i = 0; i < 5; i++)
     {
         switch (house[i, Enums.HouseType.Cigarette])
         {
             case 1://抽Blends香烟的住在养猫人的隔壁。
                 if (!((i - 1 >= 0 && house[i - 1, Enums.HouseType.Pet] == 2) ||
                     ((i + 1 < 5) && (house[i + 1, Enums.HouseType.Pet] == 2))))
                 {
                     return false;
                 } //抽Blends香烟的人有一个喝水的邻居。
                 if (!((i - 1 >= 0 && house[i - 1, Enums.HouseType.Drink] == 4) ||
                     ((i + 1 < 5) && (house[i + 1, Enums.HouseType.Drink] == 4))))
                 {
                     return false;
                 }
                 break;
             case 2://BlueMaster 抽Blue Master香烟的喝啤酒
                 if (house[i, Enums.HouseType.Drink] != 3)
                 {
                     return false;
                 }
                 break;
             case 3://Dunhill 隔壁养马 住黄色房子
                 if (house[i, Enums.HouseType.Color] != 3)
                 {
                     return false;
                 }
                 if (!((i - 1 >= 0 && house[i - 1, Enums.HouseType.Pet] == 3) ||
                     ((i + 1 < 5) && (house[i + 1, Enums.HouseType.Pet] == 3))))
                 {
                     return false;
                 }
                 break;
             case 4://PallMall 养鸟
                 if (house[i, Enums.HouseType.Pet] != 1)
                 {
                     return false;
                 }
                 break;
             case 5://Prince 德国人
                 if (house[i, Enums.HouseType.National] != 4)
                 {
                     return false;
                 }
                 break;
         }
     }
     return true;
 }
예제 #7
0
 /// <summary>
 /// Verifies the national.
 /// 1.	英国人住红色房子里。The Englishman lives in the red house.
 /// 2.	瑞典人养狗。The Swede keeps dogs.
 /// 3.	丹麦人喝茶。The Dane drinks tea.
 /// </summary>
 /// <param name="house">The house.</param>
 /// <returns></returns>
 public static bool VerifyNational(IntHouse house)
 {
     for (int i = 0; i < 5; i++)
     {
         switch (house[i, Enums.HouseType.National])
         {
             case 1://Dane 喝茶
                 if (house[i, Enums.HouseType.Drink] != 0)
                 {
                     return false;
                 }
                 break;
             case 2://English 红色房子
                 if (house[i, Enums.HouseType.Color] != 0)
                 {
                     return false;
                 }
                 break;
             case 3://German
             case 4://Norwegian
                 break;
             case 5://Swede 养狗
                 if (house[i, Enums.HouseType.Drink] != 0)
                 {
                     return false;
                 }
                 break;
         }
     }
     return true;
 }
예제 #8
0
 /// <summary>
 /// Verifies the color.
 /// 4.	绿色房子坐落在白色房子的左面。The green house is just to the left of the white one.
 /// 5.	绿色房子的主人喝咖啡。The owner of the green house drinks coffee.
 /// </summary>
 /// <param name="house">The house.</param>
 /// <returns></returns>
 public static bool VerifyColor(IntHouse house)
 {
     for (int i = 0; i < 5; i++)
     {
         switch (house[i, Enums.HouseType.National])
         {
             case 1://Blue
                 break;
             case 2://Green 绿色房子坐落在白色房子的左面
                 if (house[i, Enums.HouseType.Drink] != 1) //喝咖啡
                 {
                     return false;
                 }
                 for (int j = i; j >= 0; j--)
                 {
                     if (house[j, Enums.HouseType.Color] == 1)
                     {
                         break;
                     }
                 }
                 return false;
             case 3://Red
             case 4://White
             case 5://Yellow
                 break;
         }
     }
     return true;
 }