Exemple #1
0
    //---------------------------------------------------------------------------------------------------------------
    public AWorld Activate(int WorldNum)
    {
        int usedLevel = 1;

        if (Game.Settings.GameProgress <= worlds.Length)
        {
            usedLevel = Game.Settings.GameProgress - 1;
        }
        else
        {
            Game.Settings.GameProgress = 1;
            usedLevel = 0;
        }

        GameObject levelObject = Instantiate(worlds[usedLevel]);
        AWorld     world       = levelObject.GetComponent <AWorld>();

        if (world == null)
        {
            Debug.LogError("Error with world # " + usedLevel + ". Its not a AWorld");
            return(null);
        }

        world.Activate();
        return(world);
    }
Exemple #2
0
        ///------------------------------------------------------------------------



        ///-----------------------------------------------------------------------
        ///
        /// <summary>
        /// Constructor
        /// </summary>
        ///
        ///------------------------------------------------------------------------
        public AProgram()
        {
            mGraphics             = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            mWorld = new AWorld(1024, 720);
        }
Exemple #3
0
        ///--------------------------------------------------------------------



        ///--------------------------------------------------------------------
        ///
        /// <summary>
        /// Установка игрового мира
        /// </summary>
        ///
        ///--------------------------------------------------------------------
        public void setWorld(AWorld world)
        {
            if (mWorld != null)
            {
                mWorld.remove(this);
            }
            mWorld = world;
            mWorld.append(this);
        }
Exemple #4
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            AWorld refwrld = new AWorld();
            if (!DA.GetData(0, ref refwrld) || !refwrld.IsValid) return;
            AWorld wrld = new AWorld(refwrld);

            int g = 0;
            if (!DA.GetData(1, ref g)) return;
            if (g > wrld.GenCount - 1) g = wrld.GenCount - 1;
            DA.SetDataList(0, wrld.gens[g]);
        }
Exemple #5
0
        public Game(string sentence, AWorld world, bool guess)
        {
            _sentence = sentence;
            _world    = world;
            _guess    = guess;

            try
            {
                _formula = PL1Parser.Parse(sentence);
            }
            catch (Exception e)
            {
                _formula = null;
            }
        }
Exemple #6
0
 public void SetWorld(AWorld world)
 {
     this.World = world;
 }
Exemple #7
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            AWorld refwrld = new AWorld();
            if (!DA.GetData(0, ref refwrld) || !refwrld.IsValid) return;
            AWorld wrld = new AWorld(refwrld);

            DA.SetData(0, wrld.gph);
        }
Exemple #8
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            AWorld refwrld = new AWorld();
            List<object> v_list = new List<object>();
            GH_ObjectWrapper gh_dict = new GH_ObjectWrapper();
            IDictionary<string, string> dict = new Dictionary<string,string>();
            string k = "";

            //GH_Dict test = GH_Dict.create("a", 1.0);

            //if (!DA.GetData(0, ref refwrld) || !refwrld.IsValid) return;
            //AWorld wrld = new AWorld(refwrld);

            SpatialGraph gph = new SpatialGraph();
            if (!DA.GetData(0, ref gph)) return;

            int nGen = 0;
            string pyString = "";
            if (!DA.GetData(1, ref pyString)) return;
            if (!DA.GetDataList(2, v_list)) return;
            if (!DA.GetData(3, ref nGen)) return;
            if (!DA.GetData(4, ref gh_dict)) return;
            if (!DA.GetData(5, ref k)) return;

            //dict = (IDictionary<string, string>)gh_dict.Value;

            //object d = gh_dict.Value;
            var t = Type.GetType("IronPython.Runtime.PythonDictionary,IronPython");
            IDictionary i_dict = Activator.CreateInstance(t) as IDictionary;
            //IronPython.Runtime.PythonDictionary d = gh_dict.Value;
            //string v = d.get(k);
            string v = "oops";

            // Sets the initial Generation by using the input v_list
            // if it runs out of values, it starts over (wraps)
            //object[] val_list = new object[gph.nodes.Count];
            //int v_i = 0;
            //for (int i = 0; i < gph.nodes.Count; i++)
            //{
            //    if (v_i == v_list.Count) v_i = 0;
            //    val_list[i] = v_list[v_i];
            //    v_i++;
            //}

            //AWorld wrld = new AWorld(gph, val_list);

            //_py = PythonScript.Create();
            //_py.Output = this.m_py_output.Write;
            //_compiled_py = _py.Compile(pyString);

            //// console out
            Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_String> consoleOut = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_String>();

            //// Main evaluation cycle
            //// Should move code into the Antsworld Class
            //for (int g = 0; g < nGen; g++)
            //{
            //    // console out
            //    this.m_py_output.Reset();

            //    double[] new_vals = new double[wrld.NodeCount];
            //    for (int i = 0; i < wrld.NodeCount; i++)
            //    {
            //        int[] neighboring_indices = wrld.gph.NeighboringIndexesOf(i);

            //        // build list of neighboring values
            //        List<double> neighboring_vals = new List<double>();
            //        for (int k = 0; k < neighboring_indices.Length; k++) neighboring_vals.Add(wrld.LatestGen[neighboring_indices[k]]);

            //        double d = EvaluateCell(i, wrld.LatestGen[i], neighboring_vals);
            //        //double d = g + i + 0.0;

            //        new_vals[i] = d;
            //    }
            //    wrld.AddGen(new_vals);

            //    // console out
            //    Grasshopper.Kernel.Data.GH_Path key_path = new Grasshopper.Kernel.Data.GH_Path(g);
            //    List<Grasshopper.Kernel.Types.GH_String> gh_strs = new List<Grasshopper.Kernel.Types.GH_String>();
            //    foreach (String str in this.m_py_output.Result) gh_strs.Add(new Grasshopper.Kernel.Types.GH_String(str));
            //    consoleOut.AppendRange(gh_strs, key_path);

            //}

            DA.SetDataTree(0, consoleOut);
            //DA.SetData(1, wrld);
            DA.SetData(2, v);
        }
Exemple #9
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            AWorld refwrld = new AWorld();
            List<double> v_list = new List<double>();
            //GH_Dict test = GH_Dict.create("a", 1.0);

            //if (!DA.GetData(0, ref refwrld) || !refwrld.IsValid) return;
            //AWorld wrld = new AWorld(refwrld);

            SpatialGraph gph = new SpatialGraph();
            if (!DA.GetData(0, ref gph)) return;

            int nGen = 0;
            string pyString = "";
            if (!DA.GetData(1, ref pyString)) return;
            if (!DA.GetDataList(2, v_list)) return;
            if (!DA.GetData(3, ref nGen)) return;

            // Sets the initial Generation by using the input v_list
            // if it runs out of values, it starts over (wraps)
            double[] val_list = new double[gph.nodes.Count];
            int v_i = 0;
            for (int i = 0; i < gph.nodes.Count; i++)
            {
                if (v_i == v_list.Count) v_i = 0;
                val_list[i] = v_list[v_i];
                v_i++;
            }

            AWorld wrld = new AWorld(gph, val_list);

            _py = PythonScript.Create();
            _py.Output = this.m_py_output.Write;
            _compiled_py = _py.Compile(pyString);

            // console out
            Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_String> consoleOut = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_String>();

            // Main evaluation cycle
            // Should move code into the Antsworld Class
            for (int g = 0; g < nGen; g++)
            {
                // console out
                this.m_py_output.Reset();

                double[] new_vals = new double[wrld.NodeCount];
                for (int i = 0; i < wrld.NodeCount; i++)
                {
                    int[] neighboring_indices = wrld.gph.NeighboringIndexesOf(i);

                    // build list of neighboring values
                    List<double> neighboring_vals = new List<double>();
                    for (int k = 0; k < neighboring_indices.Length; k++) neighboring_vals.Add(wrld.LatestGen[neighboring_indices[k]]);

                    double d = EvaluateCell(i, wrld.LatestGen[i], neighboring_vals);
                    //double d = g + i + 0.0;

                    new_vals[i] = d;
                }
                wrld.AddGen(new_vals);

                // console out
                Grasshopper.Kernel.Data.GH_Path key_path = new Grasshopper.Kernel.Data.GH_Path(g);
                List<Grasshopper.Kernel.Types.GH_String> gh_strs = new List<Grasshopper.Kernel.Types.GH_String>();
                foreach (String str in this.m_py_output.Result) gh_strs.Add(new Grasshopper.Kernel.Types.GH_String(str));
                consoleOut.AppendRange(gh_strs, key_path);

            }

            DA.SetDataTree(0, consoleOut);
            DA.SetData(1, wrld);
        }
Exemple #10
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            AWorld refwrld = new AWorld();
            bool SelectType = false;
            List<double> v_list = new List<double>();
            Random rnd = new Random();

            //if (!DA.GetData(0, ref refwrld) || !refwrld.IsValid) return;
            //AWorld wrld = new AWorld(refwrld);

            SpatialGraph gph = new SpatialGraph();
            if (!DA.GetData(0, ref gph)) return;

            int nGen = 0;
            string pyString = "";
            string spyString = "";
            if (!DA.GetData(1, ref spyString)) return;
            if (!DA.GetData(2, ref SelectType)) return;
            if (!DA.GetData(3, ref pyString)) return;
            if (!DA.GetDataList(4, v_list)) return;
            if (!DA.GetData(5, ref nGen)) return;

            // Sets the initial Generation by using the input v_list
            // if it runs out of values, it starts over (wraps)
            double[] val_list = new double[gph.nodes.Count];
            int v_i = 0;
            for (int i = 0; i < gph.nodes.Count; i++)
            {
                if (v_i == v_list.Count) v_i = 0;
                val_list[i] = v_list[v_i];
                v_i++;
            }

            AWorld wrld = new AWorld(gph, val_list);

            // evaluation function
            _py = PythonScript.Create();
            _py.Output = this.m_py_output.Write;
            _compiled_py = _py.Compile(pyString);

            // selection function
            _spy = PythonScript.Create();
            _py.Output = this.m_py_output.Write;
            _compiled_spy = _py.Compile(spyString);

            // console out
            Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_String> consoleOut = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_String>();

            // Main evaluation cycle
            // Should move code into the Antsworld Class
            for (int g = 0; g < nGen; g++)
            {
                // console out
                this.m_py_output.Reset();
                double[] new_vals = new double[wrld.NodeCount];

                // build list to test
                List<int> nodes_to_test = new List<int>();

                for (int i = 0; i < wrld.NodeCount; i++)
                {
                    // build this now since we will only change a few of them later
                    new_vals[i] = wrld.LatestGen[i];

                    int[] neighboring_indices = wrld.gph.NeighboringIndexesOf(i);
                    double[] n_wts = wrld.gph.NeighboringWeightsOf(i);

                    // build list of neighboring values
                    List<double> neighboring_vals = new List<double>();
                    for (int k = 0; k < neighboring_indices.Length; k++) neighboring_vals.Add(wrld.LatestGen[neighboring_indices[k]]);

                    bool test = SelectCell(i, wrld.LatestGen[i], neighboring_vals, n_wts);

                    if (test) nodes_to_test.Add(i);

                }

                if (SelectType)
                {
                    int trial = rnd.Next(nodes_to_test.Count);
                    int new_index = nodes_to_test[trial];
                    nodes_to_test[0] = new_index;
                    nodes_to_test.RemoveRange(1, nodes_to_test.Count - 1);
                }

                // evaluate list of cells
                for (int j = 0; j < nodes_to_test.Count; j++)
                {
                    int i = nodes_to_test[j];
                    int[] neighboring_indices = wrld.gph.NeighboringIndexesOf(i);

                    // build list of neighboring values
                    List<double> neighboring_vals = new List<double>();
                    for (int k = 0; k < neighboring_indices.Length; k++) neighboring_vals.Add(wrld.LatestGen[neighboring_indices[k]]);

                    double d = EvaluateCell(i, wrld.LatestGen[i], neighboring_vals, wrld.gph.NeighboringWeightsOf(i));
                    //double d = g + i + 0.0;

                    new_vals[i] = d;
                }
                wrld.AddGen(new_vals);

                // console out
                Grasshopper.Kernel.Data.GH_Path key_path = new Grasshopper.Kernel.Data.GH_Path(g);
                List<Grasshopper.Kernel.Types.GH_String> gh_strs = new List<Grasshopper.Kernel.Types.GH_String>();
                foreach (String str in this.m_py_output.Result) gh_strs.Add(new Grasshopper.Kernel.Types.GH_String(str));
                consoleOut.AppendRange(gh_strs, key_path);

            }

            DA.SetDataTree(0, consoleOut);
            DA.SetData(1, wrld);
        }
Exemple #11
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            AWorld                       refwrld = new AWorld();
            List <object>                v_list  = new List <object>();
            GH_ObjectWrapper             gh_dict = new GH_ObjectWrapper();
            IDictionary <string, string> dict    = new Dictionary <string, string>();
            string                       k       = "";

            //GH_Dict test = GH_Dict.create("a", 1.0);

            //if (!DA.GetData(0, ref refwrld) || !refwrld.IsValid) return;
            //AWorld wrld = new AWorld(refwrld);

            SpatialGraph gph = new SpatialGraph();

            if (!DA.GetData(0, ref gph))
            {
                return;
            }

            int    nGen     = 0;
            string pyString = "";

            if (!DA.GetData(1, ref pyString))
            {
                return;
            }
            if (!DA.GetDataList(2, v_list))
            {
                return;
            }
            if (!DA.GetData(3, ref nGen))
            {
                return;
            }
            if (!DA.GetData(4, ref gh_dict))
            {
                return;
            }
            if (!DA.GetData(5, ref k))
            {
                return;
            }

            //dict = (IDictionary<string, string>)gh_dict.Value;

            //object d = gh_dict.Value;
            var         t      = Type.GetType("IronPython.Runtime.PythonDictionary,IronPython");
            IDictionary i_dict = Activator.CreateInstance(t) as IDictionary;
            //IronPython.Runtime.PythonDictionary d = gh_dict.Value;
            //string v = d.get(k);
            string v = "oops";

            // Sets the initial Generation by using the input v_list
            // if it runs out of values, it starts over (wraps)
            //object[] val_list = new object[gph.nodes.Count];
            //int v_i = 0;
            //for (int i = 0; i < gph.nodes.Count; i++)
            //{
            //    if (v_i == v_list.Count) v_i = 0;
            //    val_list[i] = v_list[v_i];
            //    v_i++;
            //}

            //AWorld wrld = new AWorld(gph, val_list);

            //_py = PythonScript.Create();
            //_py.Output = this.m_py_output.Write;
            //_compiled_py = _py.Compile(pyString);

            //// console out
            Grasshopper.Kernel.Data.GH_Structure <Grasshopper.Kernel.Types.GH_String> consoleOut = new Grasshopper.Kernel.Data.GH_Structure <Grasshopper.Kernel.Types.GH_String>();

            //// Main evaluation cycle
            //// Should move code into the Antsworld Class
            //for (int g = 0; g < nGen; g++)
            //{
            //    // console out
            //    this.m_py_output.Reset();

            //    double[] new_vals = new double[wrld.NodeCount];
            //    for (int i = 0; i < wrld.NodeCount; i++)
            //    {
            //        int[] neighboring_indices = wrld.gph.NeighboringIndexesOf(i);

            //        // build list of neighboring values
            //        List<double> neighboring_vals = new List<double>();
            //        for (int k = 0; k < neighboring_indices.Length; k++) neighboring_vals.Add(wrld.LatestGen[neighboring_indices[k]]);


            //        double d = EvaluateCell(i, wrld.LatestGen[i], neighboring_vals);
            //        //double d = g + i + 0.0;

            //        new_vals[i] = d;
            //    }
            //    wrld.AddGen(new_vals);

            //    // console out
            //    Grasshopper.Kernel.Data.GH_Path key_path = new Grasshopper.Kernel.Data.GH_Path(g);
            //    List<Grasshopper.Kernel.Types.GH_String> gh_strs = new List<Grasshopper.Kernel.Types.GH_String>();
            //    foreach (String str in this.m_py_output.Result) gh_strs.Add(new Grasshopper.Kernel.Types.GH_String(str));
            //    consoleOut.AppendRange(gh_strs, key_path);


            //}

            DA.SetDataTree(0, consoleOut);
            //DA.SetData(1, wrld);
            DA.SetData(2, v);
        }