Exemple #1
0
        public static List <RegulatoryGene> LoadAllRegulartoryGenes()
        {
            var allRegulatoryGeneJson             = CellWar.Utils.JsonHelper.Json2Object_NT <List <RegulartoryGeneJsonModel> >(GetGameDataPath("reg_gene.json"));
            List <RegulatoryGene> regulatoryGenes = new List <RegulatoryGene>();

            foreach (var geneJson in allRegulatoryGeneJson)
            {
                RegulatoryGene gene = new RegulatoryGene();
                gene.Type        = geneJson.Type;
                gene.Name        = geneJson.Name;
                gene.Description = geneJson.Description;
                gene.Length      = geneJson.Length;

                foreach (var cc in geneJson.Condition)
                {
                    var ch = ObjectHelper.Clone(FindChemicalByName(cc.Chemical));
                    if (ch != null)
                    {
                        ch.Count = cc.Count;
                        gene.Conditions.Add(ch);
                    }
                }

                regulatoryGenes.Add(gene);
            }
            AllRegulartoryGenes = regulatoryGenes;
            return(regulatoryGenes);
        }
Exemple #2
0
        public static void TestRegGeneCondition_PA()
        {
            var condition = new List <Chemical>
            {
                new Chemical
                {
                    Name = "1", Count = 10
                },
                new Chemical
                {
                    Name = "2", Count = 200
                },
                new Chemical
                {
                    Name = "3", Count = -200
                }
            };
            RegulatoryGene reg = new RegulatoryGene
            {
                Conditions = ObjectHelper.CloneList2(condition),
                Type       = "PA"
            };

            Debug.Assert(true == ctor.IsTriggered(condition, reg));
            Debug.Assert(!triggered("1", 190, reg));
            Debug.Assert(!triggered("2", 190, reg));
            Debug.Assert(!triggered("3", 190, reg));
        }
Exemple #3
0
        public static List <RegulatoryGene> LoadAllRegulartoryGenes()
        {
            try
            {
                var allRegulatoryGeneJson             = JsonHelper.Json2Object_NT <List <RegulartoryGeneJsonModel> >(GetGameDataPath("reg_gene.json"));
                List <RegulatoryGene> regulatoryGenes = new List <RegulatoryGene>();
                foreach (var geneJson in allRegulatoryGeneJson)
                {
                    RegulatoryGene gene = new RegulatoryGene();
                    gene.Type        = geneJson.Type;
                    gene.Name        = geneJson.Name;
                    gene.Description = geneJson.Description;
                    gene.Length      = geneJson.Length;
                    gene.IsInternal  = geneJson.IsInternal;
                    gene.Conditions  = SemanticObjectController.GenerateText2ChemicalsWithCountInfo(geneJson.ChemicalConditions);

                    regulatoryGenes.Add(gene);
                }
                AllRegulartoryGenes = regulatoryGenes;
                return(regulatoryGenes);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #4
0
        // no 只要一个成立就不工作
        public static void TestRegGeneCondition_NO()
        {
            RegulatoryGene reg = new RegulatoryGene
            {
                Conditions = new List <Chemical>
                {
                    new Chemical
                    {
                        Name = "1", Count = 10
                    },
                    new Chemical
                    {
                        Name = "2", Count = 200
                    },
                    new Chemical
                    {
                        Name = "3", Count = -200
                    }
                },
                Type = "NO"
            };

            Debug.Assert(false == triggered("1", 10, reg));
            Debug.Assert(true == triggered("1", 5, reg));
            Debug.Assert(false == triggered("2", 210, reg));
            Debug.Assert(true == triggered("2", 190, reg));
            Debug.Assert(true == triggered("3", 1190, reg));
            Debug.Assert(false == triggered("3", 190, reg));
            Debug.Assert(true == triggered("4", 190, reg));
            Debug.Assert(true == triggered("5", 190, reg));
        }
Exemple #5
0
 static bool triggered(string name, int count, RegulatoryGene reg)
 {
     return(ctor.IsTriggered(new List <Chemical>
     {
         new Chemical
         {
             Name = name, Count = count
         }
     }, reg));
 }
Exemple #6
0
        /// <summary>
        /// 加载所有的race
        /// geneNameList的规范为 r1;c1;c2;r2;c3;r3;c4
        /// reg后的cod会被自动归类到该r的支配基因中,读到下一个reg时停止
        /// r1;c1;c2;r2;c3;r3;c4
        /// 将会转化为
        /// r1 - c1
        ///      c2
        ///
        /// r2 - c3
        ///
        /// r3 - c4
        /// </summary>
        /// <returns></returns>
        public static List <Race> LoadAllRaces()
        {
            var allRaceJson = CellWar.Utils.JsonHelper.Json2Object_NT <List <RaceJsonModel> >(GetGameDataPath("race.json"));

            AllRaces = new List <Race>();
            foreach (var raceJson in allRaceJson)
            {
                if (raceJson.CodingGeneNames == "")
                {
                    continue;
                }

                var geneNameList = raceJson.CodingGeneNames.Split(';');
                List <RegulatoryGene> regulatoryGenes = new List <RegulatoryGene>();

                RegulatoryGene previousReg = null;

                foreach (var geneName in geneNameList)
                {
                    var regGene = AllRegulartoryGenes.Find(m => m.Name == geneName);
                    // 首个名字必须为 reg gene
                    if (regGene == null && previousReg == null)
                    {
                        throw new InvalidOperationException("Invalid GeneNames. you should input a reg gene at first of the string list"
                                                            + "\n current gene name:" + geneName);
                    }
                    else if (regGene == null && previousReg != null)
                    {
                        // 继续增加该reg下的支配cod
                        var codGene = AllCodingGenes.Find(m => m.Name == geneName);
                        if (codGene != null)
                        {
                            previousReg.DominatedGenes.Add(codGene);
                        }
                        else
                        {
                            throw new InvalidOperationException("No gene named: " + geneName + "\n you should call LoadAllRaces() after LoadAllCodingGenes");
                        }
                    }
                    else if (regGene != null)
                    {
                        // 开始添加下一个reg
                        previousReg = ObjectHelper.Clone(regGene, regGene.GetType());
                        regulatoryGenes.Add(previousReg);
                    }
                }
                AllRaces.Add(new Race {
                    Name            = raceJson.Name,
                    MaxLength       = raceJson.MaxLength,
                    RegulatoryGenes = regulatoryGenes
                });
            }
            return(AllRaces);
        }
Exemple #7
0
 public void SwitchCodingGeneList( RegulatoryGene currentReg ) {
     var reg = currentReg;
     LabCurrent.RegulatoryGene = reg;
     string str = reg.Name + "'s Coding Gene(s)";
     UIHelper.ChangeText( GameObject.Find( "UI_CurrentReg" ), str );
     UIHelper.SwitchOffAllToggle( "UI_CodList" );
     // 显示所有的cod勾选状态
     foreach( var cod in reg.DominatedGenes ) {
         UIHelper.SwitchToggle( cod.Name, true );
     }
 }
Exemple #8
0
        /// <summary>
        /// 判断格子中的chemicals是否是conditions的父集,且满足一定条件:格子中chemical的Count不小于condition中的Count
        /// </summary>
        /// <param name="chemicalsInBlock"></param>
        /// <returns></returns>
        public bool IsTriggered(List <Model.Substance.Chemical> chemicalsInBlock, RegulatoryGene reg)
        {
            switch (reg.Type)
            {
            case "PA": return(isMeetAllCondition(chemicalsInBlock, reg));

            case "NA": return(!isMeetAllCondition(chemicalsInBlock, reg));

            case "PO": return(isMeetAtLeastOneCondition(chemicalsInBlock, reg));

            case "NO": return(!isMeetAtLeastOneCondition(chemicalsInBlock, reg));

            case "TRUE": return(true);

            case "FALSE": return(false);

            default: return(default);
            }
        }
        /// <summary>
        /// 将reg-cod规范的字符串转化为reg list对象
        /// geneNameList的规范为 r1;c1;c2;r2;c3;r3;c4
        /// reg后的cod会被自动归类到该r的支配基因中,读到下一个reg时停止
        /// r1;c1;c2;r2;c3;r3;c4
        /// 将会转化为
        /// r1 - c1
        ///      c2
        ///
        /// r2 - c3
        ///
        /// r3 - c4
        /// </summary>
        /// <returns></returns>
        public static List <RegulatoryGene> GenerateText2RegGeneObjects(string geneNames)
        {
            var geneNameList = geneNames.Split(';');
            List <RegulatoryGene> regulatoryGenes = new List <RegulatoryGene>();

            RegulatoryGene previousReg = null;

            foreach (var geneName in geneNameList)
            {
                var regGene = Local.AllRegulartoryGenes.Find(m => m.Name == geneName);
                // 首个名字必须为 reg gene
                if (regGene == null && previousReg == null)
                {
                    throw new InvalidOperationException("Invalid GeneNames. you should input a reg gene at first of the string list"
                                                        + "\n current gene name:" + geneName);
                }
                else if (regGene == null && previousReg != null)
                {
                    // 继续增加该reg下的支配cod
                    var codGene = Local.AllCodingGenes.Find(m => m.Name == geneName);
                    if (codGene != null)
                    {
                        previousReg.DominatedGenes.Add(codGene);
                    }
                    else
                    {
                        throw new InvalidOperationException("No gene named: " + geneName + "\n you should call LoadAllRaces() after LoadAllCodingGenes");
                    }
                }
                else if (regGene != null)
                {
                    // 开始添加下一个reg
                    previousReg = ObjectHelper.Clone(regGene, regGene.GetType());
                    regulatoryGenes.Add(previousReg);
                }
            }
            return(regulatoryGenes);
        }
Exemple #10
0
        /// <summary>
        /// 仅有一个条件就触发
        /// </summary>
        /// <param name="chemicalsInBlock"></param>
        /// <returns></returns>
        protected bool isMeetAtLeastOneCondition(List <Model.Substance.Chemical> chemicalsInBlock, RegulatoryGene reg)
        {
            foreach (var cInCondition in reg.Conditions)
            {
                // 寻找格子中是否含有条件的chemical
                var result = chemicalsInBlock.Find(r => { return(r.Name == cInCondition.Name); });

                if (result == null)
                {
                    continue;
                }

                if (cInCondition.Count > 0)
                {
                    if (result.Count >= cInCondition.Count)
                    {
                        return(true);
                    }
                }
                else if (cInCondition.Count < 0)
                {
                    if (result.Count <= -cInCondition.Count)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemple #11
0
 /// <summary>
 /// 判断是否满足所有条件
 /// </summary>
 /// <param name="chemicalsInBlock"></param>
 /// <returns></returns>
 protected bool isMeetAllCondition(List <Model.Substance.Chemical> chemicalsInBlock, RegulatoryGene reg)
 {
     foreach (var cInCondition in reg.Conditions)
     {
         // 寻找格子中是否含有条件的chemical
         var result = chemicalsInBlock.Find(r => { return(r.Name == cInCondition.Name); });
         // 如果不存在直接条件直接不成立
         if (result == null)
         {
             return(false);
         }
         // 如果存在,判断数量是否达标,如不达标直接不成立
         if (cInCondition.Count > 0)
         {
             if (result.Count < cInCondition.Count)
             {
                 return(false);
             }
         }
         else if (cInCondition.Count < 0)
         {
             if (result.Count > -cInCondition.Count)
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Exemple #12
0
 private void Clb_regs_SelectedIndexChanged(Object sender, EventArgs e)
 {
     curReg = clb_regs.SelectedItem as RegulatoryGene;
     freshCods();
 }