public Turmit(TurmitRule rule, TurmiteMatrix matrix)
 {
     currentRule = rule;
     this.matrix = matrix;
     i = this.matrix.GetLength() / 2; k = i;
     currentState = 'A';
     currentDirection = Direction.North;
     MoveFunction[] moveFunctions = new MoveFunction[4]
     {
         new MoveFunction(MoveNorth),
         new MoveFunction(MoveSouth),
         new MoveFunction(MoveEast),
         new MoveFunction(MoveWest)
     };
     mapping.Add(Direction.East, moveFunctions[2]);
     mapping.Add(Direction.North, moveFunctions[0]);
     mapping.Add(Direction.South, moveFunctions[1]);
     mapping.Add(Direction.West, moveFunctions[3]);
 }
 static void Main(string[] args)
 {
     int automataID = GetAutomataID();
     int iterationCount = GetIterationCount();
     turmiteMatrix = new TurmiteMatrix(MATRIX_RANGE);
     crystalMatrix = new CrystalMapping(MATRIX_RANGE);
     if (automataID >= 0 && automataID <= 4)
     {
         switch (automataID)
         {
             case 0: crystal = new Crystal(crystalMatrix, 286); break;
             case 1: crystal = new Crystal(crystalMatrix, 324); break;
             case 2: crystal = new Crystal(crystalMatrix, 465); break;
             case 3: crystal = new Crystal(crystalMatrix, 501); break;
             case 4: crystal = new Crystal(crystalMatrix, 471); break;
         }
         IterateAutomata(crystal.GrowToNextIteration, iterationCount);
         SaveMatrixAsImage(crystalMatrix);
     }
     else
     {
         string ruleDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Rules\");
         TurmitRule turmiteRule = new TurmitRule();
         switch (automataID)
         {
             case 5: turmiteRule.ReadRuleFromFile(Path.Combine(ruleDir, @"Labirint.txt")); break;
             case 6: turmiteRule.ReadRuleFromFile(Path.Combine(ruleDir, @"Island.txt")); break;
             case 7: turmiteRule.ReadRuleFromFile(Path.Combine(ruleDir, @"Cross.txt")); break;
             default: turmiteRule.ReadRuleFromFile(Path.Combine(ruleDir, @"YellowSquare.txt")); break;
         }
         turmite = new Turmit(turmiteRule, turmiteMatrix);
         IterateAutomata(turmite.Move, iterationCount);
         SaveMatrixAsImage(turmiteMatrix);
     }
     Console.ReadLine();
 }
示例#3
0
        private void Form1_Load(object sender, EventArgs e)
        {
            crystalMatrix = new CrystalMapping(MATRIX_RANGE);
            turmiteMatrix = new TurmiteMatrix(MATRIX_RANGE);
            turmiteRule = new TurmitRule();
            canvas = automataPictureBox.CreateGraphics();
            automataType.SetSelected(0, true);

            this.closure = new Action<bool>((bool flag) =>
            {
                this.Invoke(new Action(() =>
                {
                    automataType.Enabled = flag;
                    automataName.Enabled = flag;
                    startIterationBtn.Enabled = flag;
                }));
            });
        }