Пример #1
0
        private static void MakeLangtonTurmite()
        {
            var tst = new Entities.TransitionStateTable
            {
                Colors      = 2,
                States      = 1,
                Transitions = new Entities.Transition[]
                {
                    new Entities.Transition
                    {
                        OnStateId  = 0,
                        OnColorId  = 0,
                        Turn       = Entities.TransitionTurn.Left,
                        NewColorId = 1,
                        NewStateId = 0,
                    },

                    new Entities.Transition
                    {
                        OnStateId  = 0,
                        OnColorId  = 1,
                        Turn       = Entities.TransitionTurn.Right,
                        NewColorId = 0,
                        NewStateId = 0,
                    }
                }
            };

            TransitionStateTable.Save(Path.Combine(
                                          Resources.BasePath,
                                          "resources/turmites/langton.xml"), tst);
        }
Пример #2
0
        public static void Save(string fileName, TransitionStateTable table)
        {
            var s = new XmlSerializer(typeof(TransitionStateTable));

            using (var f = File.OpenWrite(fileName))
            {
                s.Serialize(f, table);
            }
        }
Пример #3
0
        public Turmite(TransitionStateTable table)
        {
            Table = new Dictionary <TurmiteStateKey, Transition>();

            foreach (var t in table.Transitions)
            {
                Table.Add(new TurmiteStateKey(t.OnStateId, t.OnColorId), t);
            }
        }
Пример #4
0
        public World(WorldMetadata world)
        {
            W = world.W;
            H = world.H;

            Cells = new int[W, H];

            for (var x = 0; x < W; x++)
            {
                for (var y = 0; y < H; y++)
                {
                    Cells[x, y] = 0;
                }
            }

            Colors = new SDL.SDL_Color[world.Colors.Length];

            foreach (var cm in world.Colors)
            {
                Colors[cm.Id] = Resources.ParseColorCode(cm.RGBACode);
            }

            Turmites = new List <Turmite>();

            foreach (var tm in world.Turmites)
            {
                var tst = TransitionStateTable.Load(Resources.GetFilePath($@"turmites/{tm.Name}.xml"));
                var t   = new Turmite(tst);

                t.Direction = tm.Direction;
                t.StateId   = tm.StateId;
                t.X         = tm.X;
                t.Y         = tm.Y;

                Turmites.Add(t);
            }
        }