示例#1
0
文件: Colors.cs 项目: shoter/Graphs
        public static Color Random(int number)
        {
            int index = number - Values.Count();

            while (Randoms.Count <= index)
            {
                Randoms.Add(null);
            }
            if (Randoms[index] == null)
            {
                Randoms[index] = Color.FromArgb(255, (byte)rand.Next(0, 255), (byte)rand.Next(0, 255), (byte)rand.Next(0, 255));
            }

            return(Randoms[index].Value);
        }
示例#2
0
        /// <summary>
        /// Add node to the proper place and return it for further MCing
        /// </summary>
        public FightNode AddChild(FightNode child)
        {
            //interesting, although enemymoves are also randoms, there is no point in having an intermediate copy node.
            //i.e. Cendturn => RenemyMove => [Rvarious enemy moves] is kind of of pointless
            //unlike CstartTurn => Rwildstrike => [Rvarious wildstrikes]
            //                  => Rother random card => [ROther random card random outputs]
            child.FightAction = child.Fight.FightAction;

            if (child.FightAction.FightActionType == FightActionEnum.EnemyMove)
            {
                child.Parent      = this;
                child.FightAction = child.Fight.FightAction;
                Randoms.Add(child);
            }

            else if (child.FightAction.Random)
            {
                //two cases:
                //the intermediate node is already created:
                FightNode intermediateNode = null;
                foreach (var c in Choices)
                {
                    if (c.FightAction.IsEqual(child.FightAction))
                    {
                        intermediateNode = c;
                        break;
                    }
                }

                if (intermediateNode == null)
                {
                    //if we have a random, then consider it a c with this as a random child.
                    intermediateNode        = new FightNode(child.Fight.Copy());
                    intermediateNode.Parent = this;
                    var src = child.Fight.FightAction;

                    //we convert the specced out action into a generic one again.
                    var nonspecifiecAction = new FightAction(fightActionType: src.FightActionType,
                                                             card: src.CardInstance, cardTargets: src.CardTargets, potion: src.Potion, target: src.Target,
                                                             hadRandomEffects: src.Random);
                    intermediateNode.FightAction = nonspecifiecAction;

                    //zero these out since at this stage they represent the action pre-randomization.
                    if (intermediateNode.Fight.FightNode != null)
                    {
                        intermediateNode.Fight.FightNode.FightAction.Key = null;
                    }
                    intermediateNode.FightAction.Key = null;
                    Choices.Add(intermediateNode);
                    //there is not a random with this key already since this is the first time we played this card with random children.
                }

                //we also have to check for identity with the child nodes.
                foreach (var other in intermediateNode.Randoms)
                {
                    if (other.FightAction.IsEqual(child.Fight.FightAction) && other.FightAction.Key == child.Fight.FightAction.Key)
                    {
                        //I should just compare the order of the draw pile actually.
                        other.Weight++;
                        return(other);
                    }
                    else
                    {
                        var ae = 4;
                    }
                }
                child.Parent      = intermediateNode;
                child.FightAction = child.Fight.FightAction;
                //child.fightaction still has its key
                intermediateNode.Randoms.Add(child);
            }
            else
            {
                child.Parent      = this;
                child.FightAction = child.Fight.FightAction;
                Choices.Add(child);
            }

            //Fight is over. Calc values.
            if (child.Fight.Status != FightStatus.Ongoing)
            {
                child.CalcValue();
            }

            return(child);
        }