Ejemplo n.º 1
0
    public List <object> AdaptStrategy(object log, object strategy)
    {
        //clean rules
        discardedDefrules = 0;
        discardedOffrules = 0;
        adaptationDefRules.Clear();
        adaptationOffRules.Clear();

        var o = strategy as Strategy;

        ruleNum = o.GStrategy.Rules.Count;


        //def adapt
        try
        {
            AdaptDefRules((LogHolder)log, (Strategy)strategy);
        }
        catch (Exception e)
        {
        }
        //off adapt
        try
        {
            AdaptOffRules((LogHolder)log, (Strategy)strategy);
        }
        catch (Exception e)
        {
        }

        //complete list
        List <object> adaptedRules = new List <object>();

        //convert def rules
        foreach (Rule r in adaptationDefRules)
        {
            GridRule gr = new GridRule();

            gr.Number = r.ruleNum;
            gr.Type   = GridRule.RuleType.Deffense;
            gr.Name   = "AdaptedDef";
            Vector2D[] vmine = new Vector2D[] {
                new Vector2D(Convert.ToDouble(r.lr0x), Convert.ToDouble(r.lr0y)),
                new Vector2D(Convert.ToDouble(r.lr1x), Convert.ToDouble(r.lr1y)),
                new Vector2D(Convert.ToDouble(r.lr2x), Convert.ToDouble(r.lr2y)),
                new Vector2D(Convert.ToDouble(r.lr3x), Convert.ToDouble(r.lr3y))
            };
            gr.Mine = vmine;
            Vector2D[] voppnt = new Vector2D[] {
                new Vector2D(Convert.ToDouble(r.rr0x), Convert.ToDouble(r.rr0y)),
                new Vector2D(Convert.ToDouble(r.rr1x), Convert.ToDouble(r.rr1y)),
                new Vector2D(Convert.ToDouble(r.rr2x), Convert.ToDouble(r.rr2y)),
                new Vector2D(Convert.ToDouble(r.rr3x), Convert.ToDouble(r.rr3y))
            };
            gr.Oppnt = voppnt;
            gr.Ball  = new Vector2D(Convert.ToDouble(r.ballX), Convert.ToDouble(r.ballY));
            Vector2D[] vmove = new Vector2D[] {
                new Vector2D(Convert.ToDouble(r.lr0mx), Convert.ToDouble(r.lr0my)),
                new Vector2D(Convert.ToDouble(r.lr1mx), Convert.ToDouble(r.lr1my)),
                new Vector2D(Convert.ToDouble(r.lr2mx), Convert.ToDouble(r.lr2my)),
                new Vector2D(Convert.ToDouble(r.lr3mx), Convert.ToDouble(r.lr3my))
            };
            gr.Move = vmove;

            gr.fillZOrder();

            if (!RuleCheck(gr, (Strategy)strategy))
            {
                adaptedRules.Add(gr);
            }
            else
            {
                discardedDefrules++;
            }
        }

        //convert off rules
        foreach (Rule r in adaptationOffRules)
        {
            GridRule gr = new GridRule();

            gr.Number = r.ruleNum;
            gr.Type   = GridRule.RuleType.Offense;
            gr.Name   = "AdaptedOff";
            Vector2D[] vmine = new Vector2D[] {
                new Vector2D(Convert.ToDouble(r.lr0x), Convert.ToDouble(r.lr0y)),
                new Vector2D(Convert.ToDouble(r.lr1x), Convert.ToDouble(r.lr1y)),
                new Vector2D(Convert.ToDouble(r.lr2x), Convert.ToDouble(r.lr2y)),
                new Vector2D(Convert.ToDouble(r.lr3x), Convert.ToDouble(r.lr3y))
            };
            gr.Mine = vmine;
            Vector2D[] voppnt = new Vector2D[] {
                new Vector2D(Convert.ToDouble(r.rr0x), Convert.ToDouble(r.rr0y)),
                new Vector2D(Convert.ToDouble(r.rr1x), Convert.ToDouble(r.rr1y)),
                new Vector2D(Convert.ToDouble(r.rr2x), Convert.ToDouble(r.rr2y)),
                new Vector2D(Convert.ToDouble(r.rr3x), Convert.ToDouble(r.rr3y))
            };
            gr.Oppnt = voppnt;
            gr.Ball  = new Vector2D(Convert.ToDouble(r.ballX), Convert.ToDouble(r.ballY));
            Vector2D[] vmove = new Vector2D[] {
                new Vector2D(Convert.ToDouble(r.lr0mx), Convert.ToDouble(r.lr0my)),
                new Vector2D(Convert.ToDouble(r.lr1mx), Convert.ToDouble(r.lr1my)),
                new Vector2D(Convert.ToDouble(r.lr2mx), Convert.ToDouble(r.lr2my)),
                new Vector2D(Convert.ToDouble(r.lr3mx), Convert.ToDouble(r.lr3my))
            };
            gr.Move = vmove;

            gr.fillZOrder();

            if (!RuleCheck(gr, (Strategy)strategy))
            {
                adaptedRules.Add(gr);
            }
            else
            {
                discardedOffrules++;
            }
        }

        return(adaptedRules);
    }
Ejemplo n.º 2
0
    public List <object> AdaptStrategy(LogHolder log, object strategy)
    {
        discardedDefrules = 0;
        discardedOffrules = 0;
        adaptationDefRules.Clear();
        adaptationOffRules.Clear();

        ruleNum = (int)strategy.GetType().GetMethod("CurrentRuleNumberCount").Invoke(strategy, null);

        //def adapt
        try
        {
            AdaptDefRules(log, (Strategy)strategy);
        }
        catch (Exception e)
        {
            Debug.Log(e.Message);
        }
        //off adapt
        try
        {
            AdaptOffRules(log, (Strategy)strategy);
        }
        catch (Exception e)
        {
            Debug.Log(e.Message);
        }

        //complete list
        List <object> adaptedRules = new List <object>();

        //convert def rules
        foreach (Rule r in adaptationDefRules)
        {
            GridRule gr = new GridRule();

            gr.Number = r.ruleNum;
            gr.Type   = GridRule.RuleType.Deffense;
            gr.Name   = "AdaptedDef";
            Vector2D[] vmine = new Vector2D[] {
                new Vector2D(Convert.ToDouble(r.lr0x), Convert.ToDouble(r.lr0y)),
                new Vector2D(Convert.ToDouble(r.lr1x), Convert.ToDouble(r.lr1y)),
                new Vector2D(Convert.ToDouble(r.lr2x), Convert.ToDouble(r.lr2y)),
                new Vector2D(Convert.ToDouble(r.lr3x), Convert.ToDouble(r.lr3y))
            };
            gr.Mine = vmine;
            Vector2D[] voppnt = new Vector2D[] {
                new Vector2D(Convert.ToDouble(r.rr0x), Convert.ToDouble(r.rr0y)),
                new Vector2D(Convert.ToDouble(r.rr1x), Convert.ToDouble(r.rr1y)),
                new Vector2D(Convert.ToDouble(r.rr2x), Convert.ToDouble(r.rr2y)),
                new Vector2D(Convert.ToDouble(r.rr3x), Convert.ToDouble(r.rr3y))
            };
            gr.Oppnt = voppnt;
            gr.Ball  = new Vector2D(Convert.ToDouble(r.ballX), Convert.ToDouble(r.ballY));
            Vector2D[] vmove = new Vector2D[] {
                new Vector2D(Convert.ToDouble(r.lr0mx), Convert.ToDouble(r.lr0my)),
                new Vector2D(Convert.ToDouble(r.lr1mx), Convert.ToDouble(r.lr1my)),
                new Vector2D(Convert.ToDouble(r.lr2mx), Convert.ToDouble(r.lr2my)),
                new Vector2D(Convert.ToDouble(r.lr3mx), Convert.ToDouble(r.lr3my))
            };
            gr.Move = vmove;

            Debug.Log(gr.ToString());

            gr.fillZOrder();

            if (!RuleCheck(gr, (Strategy)strategy))
            {
                adaptedRules.Add(gr);
            }
            else
            {
                discardedDefrules++;
            }

            Debug.Log("Discarded def rules: " + discardedDefrules);
        }

        //convert off rules
        foreach (Rule r in adaptationOffRules)
        {
            GridRule gr = new GridRule();

            gr.Number = r.ruleNum;
            gr.Type   = GridRule.RuleType.Offense;
            gr.Name   = "AdaptedOff";
            Vector2D[] vmine = new Vector2D[] {
                new Vector2D(Convert.ToDouble(r.lr0x), Convert.ToDouble(r.lr0y)),
                new Vector2D(Convert.ToDouble(r.lr1x), Convert.ToDouble(r.lr1y)),
                new Vector2D(Convert.ToDouble(r.lr2x), Convert.ToDouble(r.lr2y)),
                new Vector2D(Convert.ToDouble(r.lr3x), Convert.ToDouble(r.lr3y))
            };
            gr.Mine = vmine;
            Vector2D[] voppnt = new Vector2D[] {
                new Vector2D(Convert.ToDouble(r.rr0x), Convert.ToDouble(r.rr0y)),
                new Vector2D(Convert.ToDouble(r.rr1x), Convert.ToDouble(r.rr1y)),
                new Vector2D(Convert.ToDouble(r.rr2x), Convert.ToDouble(r.rr2y)),
                new Vector2D(Convert.ToDouble(r.rr3x), Convert.ToDouble(r.rr3y))
            };
            gr.Oppnt = voppnt;
            gr.Ball  = new Vector2D(Convert.ToDouble(r.ballX), Convert.ToDouble(r.ballY));
            Vector2D[] vmove = new Vector2D[] {
                new Vector2D(Convert.ToDouble(r.lr0mx), Convert.ToDouble(r.lr0my)),
                new Vector2D(Convert.ToDouble(r.lr1mx), Convert.ToDouble(r.lr1my)),
                new Vector2D(Convert.ToDouble(r.lr2mx), Convert.ToDouble(r.lr2my)),
                new Vector2D(Convert.ToDouble(r.lr3mx), Convert.ToDouble(r.lr3my))
            };
            gr.Move = vmove;

            Debug.Log(gr.ToString());

            gr.fillZOrder();

            if (!RuleCheck(gr, (Strategy)strategy))
            {
                adaptedRules.Add(gr);
            }
            else
            {
                discardedOffrules++;
            }

            Debug.Log("Discarded off rules: " + discardedOffrules);
        }

        return(adaptedRules);
    }