Пример #1
0
        public static bool isContrary(NumberRule rule1, PositionRule rule2)
        {
            if (rule1.OutputState == rule2.OutputState)
            {
                return(false);
            }

            switch (rule1.StateChoosen1)
            {
            case (int)GlobalSettings.States.Empty:
                if (rule1.Count == rule2.EmptyCount && rule2.DeadCount == 0 && rule2.AliveCount == 0)
                {
                    return(true);
                }
                break;

            case (int)GlobalSettings.States.Dead:
                if (rule1.Count == rule2.DeadCount && rule2.AliveCount == 0)
                {
                    return(true);
                }
                break;

            case (int)GlobalSettings.States.Alive:
                if (rule1.Count == rule2.AliveCount && rule2.DeadCount == 0)
                {
                    return(true);
                }
                break;
            }



            return(false);
        }
Пример #2
0
        public static bool  isContrary(PositionRule rule1, PositionRule rule2)
        {
            if (rule1.OutputState == rule2.OutputState)
            {
                return(false);
            }



            return(equals(rule1, rule2));
        }
Пример #3
0
        private void positionBasedButton(object sender, RoutedEventArgs e)
        {
            byte inputState = 0;
            var  neigh      = new byte[xDim, yDim];

            for (int i = 0; i < xDim; i++)
            {
                for (int j = 0; j < yDim; j++)
                {
                    if (i == xDim / 2 && j == yDim / 2)
                    {
                        inputState = (byte)_buttonList[i, j].Tag;
                    }

                    neigh[i, j] = (byte)_buttonList[i, j].Tag;
                }
            }


            var pr = new PositionRule(neigh, inputState, (byte)OutputStateButton.Tag);

            var iscontrary = false;

            foreach (PositionRule sec_rule in RuleSet.PositionRules)
            {
                if (iscontrary = RuleSet.isContrary(sec_rule, pr))
                {
                    break;
                }
            }

            foreach (NumberRule secRule in RuleSet.NumberRule.Where(sec_rule => iscontrary = RuleSet.isContrary(sec_rule, pr)))
            {
                break;
            }


            if (!iscontrary)
            {
                RuleSet.PositionRules.Add(pr);
                Console.WriteLine("No Contrary");
                MessageBox.Show("Rule Added", "Confirmation", MessageBoxButton.OK,
                                MessageBoxImage.Information);
            }
            else
            {
                Console.WriteLine("Is Contrary");
                MessageBox.Show("This is contrary", "Confirmation", MessageBoxButton.OK,
                                MessageBoxImage.Information);
            }
        }
Пример #4
0
        private static bool equals(PositionRule rule1, PositionRule rule2)
        {
            for (int i = 0; i < rule1.Neighbourhood.GetLength(0); i++)
            {
                for (int j = 0; j < rule1.Neighbourhood.GetLength(1); j++)
                {
                    if (rule1.Neighbourhood[i, j] != rule2.Neighbourhood[i, j])
                    {
                        return(false);
                    }
                }
            }



            return(true);
        }