Exemple #1
0
 public Collection(Tactic tactic, int Count = 1)
 {
     name   = tactic.tacticName;
     type   = "Tactic";
     count  = Count;
     health = tactic.goldCost;
 }
Exemple #2
0
    public void Run()
    {
        Dictionary <string, string> cfg = new Dictionary <string, string>()
        {
            { "AUTO_CONFIG", "true" }
        };

        using (Context ctx = new Context(cfg))
        {
            RealExpr x = ctx.MkRealConst("x");
            RealExpr y = ctx.MkRealConst("y");
            RealExpr z = ctx.MkRealConst("z");

            RealExpr zero = ctx.MkReal(0);
            RealExpr one  = ctx.MkReal(1);

            Goal g = ctx.MkGoal();
            g.Assert(ctx.MkOr(ctx.MkEq(x, zero), ctx.MkEq(x, one)));
            g.Assert(ctx.MkOr(ctx.MkEq(y, zero), ctx.MkEq(y, one)));
            g.Assert(ctx.MkOr(ctx.MkEq(z, zero), ctx.MkEq(z, one)));
            g.Assert(ctx.MkGt(ctx.MkAdd(x, y, z), ctx.MkReal(2)));

            Tactic      t  = ctx.Repeat(ctx.OrElse(ctx.MkTactic("split-clause"), ctx.MkTactic("skip")));
            ApplyResult ar = t[g];
            foreach (var sg in ar.Subgoals)
            {
                Console.WriteLine(sg);
            }
        }
    }
        public TacticErrorReportingResolver(CompoundErrorInformation errorInfo)
        {
            Contract.Ensures(_errTok != null);
            Contract.Ensures(_errMessage != null);
            Contract.Ensures(_tacticCall != null);
            Contract.Ensures(_activeTactic != null);
            Contract.Ensures(_callingMember != null);
            Contract.Ensures(_tmpFailingMember != null);
            Contract.Ensures(!string.IsNullOrEmpty(_implTargetName));
            var proofState = errorInfo.S;
            var tmpProgram = ((CompoundErrorInformation)errorInfo.E).P;
            var innerError = ((CompoundErrorInformation)errorInfo.E).E;
            var tmpModule  = (DefaultClassDecl)tmpProgram.DefaultModuleDef.TopLevelDecls.FirstOrDefault(x => x.CompileName == "__default");

            var tok = innerError.Tok as NestedToken;

            _errTok     = tok != null ? (Bpl.Token)tok.Inner : (Bpl.Token)innerError.Tok;
            _errMessage = innerError.FullMsg;

            _implTargetName = MethodNameFromImpl(innerError.ImplementationName);
            _tacticCall     = proofState.TacticApplication;
            _activeTactic   = proofState.GetTactic(_tacticCall) as Tactic;

            _callingMember    = proofState.TargetMethod;
            _tmpFailingMember = tmpModule?.Members.FirstOrDefault(x => x.CompileName == _implTargetName);

            FailingLine = FailingCol = TacticLine = TacticCol = CallingLine = CallingCol = -1;

            if (!ActiveTacticWasNotUsed())
            {
                ResolveCorrectLocations();
            }
        }
        public void StartTactic(Tactic newTactic)
        {
            _needsUpdate = true;

            _currentStoppingDistance = newTactic.GetData().StoppingDistance;
            _currentCloseness        = newTactic.GetData().TacticDistance;
        }
Exemple #5
0
        private void CreateUcPlayers(Tactic tactic, int playerCount = 11)
        {
            this.panelPlayers.Controls.Clear();
            var tacticName    = tactic.Name;
            var tacticNumbers = ParseTacticName(tacticName);
            var j             = 0;

            var sum = GetSum(tacticNumbers, j);

            for (int i = 0; i < playerCount; i++)
            {
                Color color = Color.Green;

                if (i < sum)
                {
                    color = Color.FromName(tactic.PositionColors[j]);
                }
                else if (playerCount - 1 != i)
                {
                    j++;
                    sum = GetSum(tacticNumbers, j);
                    i--;
                    continue;
                }

                var ucPlayer = CreateNewUcPlayer(i);

                var btn = ucPlayer.Controls["btnPlayerPosition"] as Guna2CircleButton;

                btn.Text      = tactic.Positions[i];
                btn.FillColor = color;
                panelPlayers.Controls.Add(ucPlayer);
            }
        }
Exemple #6
0
    public void Run()
    {
        Dictionary <string, string> cfg = new Dictionary <string, string>()
        {
            { "AUTO_CONFIG", "true" }
        };

        using (Context ctx = new Context(cfg))
        {
            RealExpr x    = ctx.MkRealConst("x");
            RealExpr y    = ctx.MkRealConst("y");
            RealExpr z    = ctx.MkRealConst("z");
            RatNum   zero = ctx.MkReal(0);
            RatNum   two  = ctx.MkReal(2);

            Goal g = ctx.MkGoal();

            g.Assert(ctx.MkGe(ctx.MkSub(ctx.MkPower(x, two), ctx.MkPower(y, two)), zero));

            Probe  p  = ctx.MkProbe("num-consts");
            Probe  p2 = ctx.Gt(p, ctx.Const(2));
            Tactic t  = ctx.Cond(p2, ctx.MkTactic("simplify"), ctx.MkTactic("factor"));

            Console.WriteLine(t[g]);

            g = ctx.MkGoal();
            g.Assert(ctx.MkGe(ctx.MkAdd(x, x, y, z), zero));
            g.Assert(ctx.MkGe(ctx.MkSub(ctx.MkPower(x, two), ctx.MkPower(y, two)), zero));

            Console.WriteLine(t[g]);
        }
    }
Exemple #7
0
    public void AddTactic(Tactic tactic)
    {
        int           index   = 0;
        List <Tactic> tactics = unusedTactics[Login.playerID];

        if (tactics.Count == 0 || tactic < tactics[0])
        {
            index = 0;
        }
        else if (tactic > tactics[tactics.Count - 1])
        {
            index = tactics.Count;
        }
        else
        {
            for (int i = 0; i < unusedTactics[Login.playerID].Count - 1; i++)
            {
                if (tactic > tactics[i] && tactic < tactics[i + 1])
                {
                    index = i + 1;
                    break;
                }
            }
        }
        unusedTactics[Login.playerID].Insert(index, tactic);
        Upload();
    }
Exemple #8
0
        //Organizes and returns a package for the combat manager's use.
        public targettingPackage getTargetandTactic()
        {
            Tactic     chosenTactic = DecideOnTactic();
            GameObject chosenTarget = DecideOnTarget(chosenTactic);

            return(new targettingPackage(chosenTarget, chosenTactic));
        }
        /// <summary>
        /// Handles opportunity tactics history update.
        /// </summary>
        /// <param name="oppEntity">Current opportunity entity</param>
        public void UpdateOpportunityTacticHistory(Entity oppEntity)
        {
            if (!oppEntity.GetIsColumnValueLoaded("Tactic") || !oppEntity.GetIsColumnValueLoaded("CheckDate"))
            {
                oppEntity.FetchFromDB(oppEntity.PrimaryColumnValue);
            }
            var    tacticValue  = oppEntity.GetTypedColumnValue <string>("Tactic");
            object checkDateobj = oppEntity.GetColumnValue("CheckDate");

            if (tacticValue.IsNullOrEmpty() && checkDateobj == null)
            {
                return;
            }
            var tactic = new Tactic()
            {
                TacticValue   = tacticValue,
                OpportunityId = oppEntity.GetTypedColumnValue <Guid>("Id"),
            };

            if (checkDateobj != null)
            {
                var checkDate = Convert.ToDateTime(checkDateobj);
                tactic.CheckDate = checkDate;
            }
            SaveOpportunityTactic(tactic);
        }
        public Data.Tactic GetDataTactic()
        {
            Tactic ret = DataHelpers.Entities.Tactics.FirstOrDefault(t => t.Aggressiveness == this.Aggressiveness &&
                                                                     t.Defense == this.Defense &&
                                                                     t.Power == this.Power &&
                                                                     t.Rest == this.Rest &&
                                                                     t.Strategy == (int)this.Style &&
                                                                     t.Target == (int)this.TargetArea &&
                                                                     t.Dirty == this.Dirty);

            if (ret == null)
            {
                ret = DataHelpers.Entities.Tactics.Create();
                ret.Aggressiveness = this.Aggressiveness;
                ret.Defense        = this.Defense;
                ret.Dirty          = this.Dirty;
                ret.Power          = this.Power;
                ret.Rest           = this.Rest;
                ret.Strategy       = (int)this.Style;
                ret.Target         = (int)this.TargetArea;
                ret = DataHelpers.Entities.Tactics.Add(ret);
                DataHelpers.Entities.SaveChanges();
            }
            return(ret);
        }
 private static IDecisionNode NodeToDecisionTree(IDataNode node)
 {
     if (node is DataLeaf)
     {
         DataLeaf leaf   = (DataLeaf)node;
         Tactic   tactic = EnumUtils.GetEnumValues <Tactic>().MaxBy(t => leaf.ClassDistribution[(int)t]);
         return(new DecisionLeaf(tactic));
     }
     else if (node is AttributeSplit)
     {
         AttributeSplit attributeSplit = (AttributeSplit)node;
         return(new DecisionNode {
             Partitioner = new ContinuousPartitioner((ContinuousAxis)attributeSplit.Axis, attributeSplit.SplitValue),
             Left = NodeToDecisionTree(attributeSplit.Left),
             Right = NodeToDecisionTree(attributeSplit.Right),
         });
     }
     else if (node is CategoricalSplit)
     {
         CategoricalSplit categoricalSplit = (CategoricalSplit)node;
         return(new DecisionNode {
             Partitioner = new CategoricalPartitioner(
                 (CategoricalAxis)categoricalSplit.Axis,
                 PolicyHelper.BitsToCategories((CategoricalAxis)categoricalSplit.Axis, categoricalSplit.Categories).ToArray()),
             Left = NodeToDecisionTree(categoricalSplit.Left),
             Right = NodeToDecisionTree(categoricalSplit.Right),
         });
     }
     else
     {
         throw new ArgumentException("Unknown node type: " + node);
     }
 }
Exemple #12
0
    public void Run()
    {
        Dictionary <string, string> cfg = new Dictionary <string, string>()
        {
            { "AUTO_CONFIG", "true" }
        };

        using (Context ctx = new Context(cfg))
        {
            RealExpr x = ctx.MkRealConst("x");
            RealExpr y = ctx.MkRealConst("y");

            RatNum zero = ctx.MkReal(0);
            RatNum two  = ctx.MkReal(2);

            Goal g = ctx.MkGoal();
            g.Assert(ctx.MkGt(x, zero));
            g.Assert(ctx.MkGt(y, zero));
            g.Assert(ctx.MkEq(x, ctx.MkAdd(y, two)));
            Console.WriteLine(g);

            Tactic t1 = ctx.MkTactic("simplify");
            Tactic t2 = ctx.MkTactic("solve-eqs");
            Tactic t  = ctx.AndThen(t1, t2);

            Console.WriteLine(t[g]);
        }
    }
Exemple #13
0
    public void AddTactic(Tactic tactic)
    {
        int count = gameInfo.unusedTactics[Login.playerID].Count;

        if (count == Lineup.tacticLimit)
        {
            StartCoroutine(ShowFullTacticBag());
        }
        else
        {
            gameInfo.AddTactic(tactic);
            tacticObjs[count].parent.gameObject.SetActive(true);
            int index = 0;
            if (count != 0)
            {
                index = gameInfo.unusedTactics[Login.playerID].IndexOf(tactic);
                for (int i = count; i > index; i--)
                {
                    TacticInfo tacticInfo = tacticObjs[i - 1].GetComponent <TacticInfo>();
                    tacticObjs[i].GetComponent <TacticInfo>().SetAttributes(tacticInfo.tacticAttributes, Login.playerID, tacticInfo.tactic.original);
                }
            }
            TacticAttributes tacticAttributes = Database.FindTacticAttributes(tactic.tacticName);
            tacticObjs[index].GetComponent <TacticInfo>().SetAttributes(tacticAttributes, Login.playerID, false);
            tacticTriggers.Insert(index, tacticAttributes.trigger);
            SetTacticInteractable();
        }
    }
Exemple #14
0
 public GameEvent(Tactic tactic)
 {
     /// Tactic
     result           = "Tactic";
     eventTriggerName = tactic.tacticName;
     eventPlayerID    = tactic.ownerID;
 }
Exemple #15
0
        public void Test_Z3_MemWithArray_2()
        {
            #region Definitions
            uint    nBits = 8;
            Context ctx   = new Context();

            BitVecExpr bv_0  = ctx.MkBV(0, nBits);
            BitVecExpr bv_16 = ctx.MkBV(16, nBits);
            BitVecExpr bv_32 = ctx.MkBV(32, nBits);

            BitVecExpr rax = ctx.MkBVConst("RAX!0", nBits);
            BitVecExpr rbx = ctx.MkBVConst("RBX!0", nBits);
            BitVecExpr rcx = ctx.MkBVConst("RCX!0", nBits);
            BitVecExpr rdx = ctx.MkBVConst("RDX!0", nBits);

            ArrayExpr mem = ctx.MkArrayConst("mem", ctx.MkBitVecSort(nBits), ctx.MkBitVecSort(nBits));

            Goal state = ctx.MkGoal();
            #endregion

            // Test possible memory overwrite
            Console.WriteLine("mov qword ptr[16], 0 ; store at address=16 value=0");
            mem = ctx.MkStore(mem, bv_16, bv_0);
            Console.WriteLine("mov rax, qword ptr[16] ; load rax with the value at address=16");
            state.Assert(ctx.MkEq(rax, ctx.MkSelect(mem, bv_16)));
            Console.WriteLine("mov qword ptr[rcx], 32 ; store at unknown address rcx value 32, appreciate that address 16 could be overwritten");
            mem = ctx.MkStore(mem, rcx, bv_32);
            Console.WriteLine("mov rbx, qword ptr[16] ; load rbx with value at address 16, appreciate that rbx need not be equal to rax");
            state.Assert(ctx.MkEq(rbx, ctx.MkSelect(mem, bv_16)));

            if (true)
            {
                Console.WriteLine("cmp rcx, 16 ;");
                Console.WriteLine("jnz label1: ");
                state.Assert(ctx.MkEq(rcx, bv_16));
            }
            #region Write to console
            Console.WriteLine("mem=" + mem);

            Solver solver   = ctx.MkSolver();
            Solver solver_U = ctx.MkSolver();
            solver.Assert(state.Formulas);
            Console.WriteLine("state1=" + state);
            if (true)
            {
                Tactic tactic1 = ctx.MkTactic("propagate-values");
                Goal   state2  = tactic1.Apply(state).Subgoals[0];
                Console.WriteLine("state2=" + state2.ToString());
            }
            Console.WriteLine(string.Empty);
            Tv[] raxTV = ToolsZ3.GetTvArray(rax, (int)nBits, solver, solver_U, ctx);
            Console.WriteLine("rax = " + ToolsZ3.ToStringBin(raxTV) + " = " + ToolsZ3.ToStringHex(raxTV));
            Tv[] rbxTV = ToolsZ3.GetTvArray(rbx, (int)nBits, solver, solver_U, ctx);
            Console.WriteLine("rbx = " + ToolsZ3.ToStringBin(rbxTV) + " = " + ToolsZ3.ToStringHex(rbxTV));
            Tv[] rcxTV = ToolsZ3.GetTvArray(rcx, (int)nBits, solver, solver_U, ctx);
            Console.WriteLine("rcx = " + ToolsZ3.ToStringBin(rcxTV) + " = " + ToolsZ3.ToStringHex(rcxTV));
            // Tv5[] rdxTV = ToolsZ3.getTvArray(rdx, nBits, solver, ctx);
            // Console.WriteLine("rdx = " + ToolsZ3.toStringBin(rdxTV) + " = " + ToolsZ3.toStringHex(rdxTV));
            #endregion
        }
Exemple #16
0
    public void Run()
    {
        Dictionary <string, string> cfg = new Dictionary <string, string>()
        {
            { "AUTO_CONFIG", "true" }
        };

        using (Context ctx = new Context(cfg))
        {
            BitVecExpr x = ctx.MkBVConst("x", 16);
            BitVecExpr y = ctx.MkBVConst("y", 16);

            Params p = ctx.MkParams();
            p.Add(":mul2concat", true);

            Tactic t = ctx.Then(ctx.UsingParams(ctx.MkTactic("simplify"), p),
                                ctx.MkTactic("solve-eqs"),
                                ctx.MkTactic("bit-blast"),
                                ctx.MkTactic("aig"),
                                ctx.MkTactic("sat"));
            Solver s = ctx.MkSolver(t);

            s.Assert(ctx.MkEq(ctx.MkBVAdd(ctx.MkBVMul(x, ctx.MkBV(32, 16)), y), ctx.MkBV(13, 16)));
            s.Assert(ctx.MkBVSLT(ctx.MkBVAND(x, y), ctx.MkBV(10, 16)));
            s.Assert(ctx.MkBVSGT(y, ctx.MkBV(-100, 16)));

            Console.WriteLine(s.Check());
            Model m = s.Model;
            Console.WriteLine(m);

            Console.WriteLine(ctx.MkBVAdd(ctx.MkBVMul(x, ctx.MkBV(32, 16)), y) + " == " + m.Evaluate(ctx.MkBVAdd(ctx.MkBVMul(x, ctx.MkBV(32, 16)), y)));
            Console.WriteLine(ctx.MkBVAND(x, y) + " == " + m.Evaluate(ctx.MkBVAND(x, y)));
        }
    }
    public TacticErrorReportingResolver(Tacny.CompoundErrorInformation errorInfo)
    {
      Contract.Ensures(_errTok != null);
      Contract.Ensures(_errMessage != null);
      Contract.Ensures(_tacticCall != null);
      Contract.Ensures(_activeTactic != null);
      Contract.Ensures(_callingMember != null);
      Contract.Ensures(_tmpFailingMember != null);
      Contract.Ensures(!string.IsNullOrEmpty(_implTargetName));
      var proofState = errorInfo.S;
      var tmpProgram = ((Tacny.CompoundErrorInformation)errorInfo.E).P;
      var innerError = ((Tacny.CompoundErrorInformation)errorInfo.E).E;
      var tmpModule = (DefaultClassDecl)tmpProgram.DefaultModuleDef.TopLevelDecls.FirstOrDefault();

      _errTok = (Bpl.Token)innerError.Tok;
      _errMessage = innerError.FullMsg;

      _implTargetName = MethodNameFromImpl(innerError.ImplementationName);
      _tacticCall = proofState.TacticApplication;
      _activeTactic = proofState.GetTactic(_tacticCall) as Tactic;

      _callingMember = proofState.TargetMethod;
      _tmpFailingMember = tmpModule?.Members.FirstOrDefault(x => x.CompileName == _implTargetName);

      FailingLine = FailingCol = TacticLine = TacticCol = CallingLine = CallingCol = -1;

      if(!ActiveTacticWasNotUsed()) ResolveCorrectLocations();
    }
Exemple #18
0
    public static void ResumeTactic(Tactic tactic)
    {
        TacticAttributes attributes = Database.FindTacticAttributes(tactic.tacticName);

        tactic.oreCost  = attributes.oreCost;
        tactic.goldCost = attributes.goldCost;
    }
Exemple #19
0
        public ProgramSyntesizer(int nLines, IList <Rn> registers)
        {
            this._nLines    = nLines;
            this._registers = registers;


            Dictionary <string, string> settings = new Dictionary <string, string>
            {
                { "unsat-core", "true" },   // enable generation of unsat cores
                { "model", "true" },        // enable model generation
                { "proof", "true" }         // enable proof generation
            };

            this._ctx = new Context(settings);

            Tactic ta1 = this._ctx.MkTactic("simplify");            // some minor rewrites
            Tactic ta2 = this._ctx.MkTactic("ctx-simplify");        //
            Tactic ta3 = this._ctx.MkTactic("ctx-solver-simplify"); //VERY SLOW

            this._tactic = ta3;                                     // ctx.AndThen(ta2, ta1);
            this._solver = this._ctx.MkSolver();

            this._validPrograms = new HashSet <string>();
            this._constants     = new Dictionary <string, BitVecExpr>();
            this._switches      = new Dictionary <int, List <BoolExpr> >();
            for (int i = 1; i <= this._nLines; ++i)
            {
                this._switches.Add(i, new List <BoolExpr>());
            }
        }
Exemple #20
0
        /// <summary> Создаёт тактику из стандартной тактики и сохраняет её в Хранилище Данных </summary>
        private Tactic CreateTactic(int tacticKey = -1)
        {
            Random rnd = new Random();

            if (tacticKey == -1)
            {
                tacticKey = rnd.Next(0, StandartTactics.GeneralTactics.Count);
            }
            GeneralTactic generalTactic = StandartTactics.GeneralTactics[tacticKey];
            int           defKey        = rnd.Next(0, StandartTactics.LineFormations.Where(x => x.LineKey == 1 && x.PlayersCount == generalTactic.DefendersCount).Count());
            int           midKey        = rnd.Next(0, StandartTactics.LineFormations.Where(x => x.LineKey == 2 && x.PlayersCount == generalTactic.MidfieldersCount).Count());
            int           strKey        = rnd.Next(0, StandartTactics.LineFormations.Where(x => x.LineKey == 3 && x.PlayersCount == generalTactic.StrikersCount).Count());
            List <Point>  locations     = StandartTactics.GeneralTactics[tacticKey].GetLocations(defKey, midKey, strKey);
            Tactic        Result        = this.dataStorage.CreateDBObject <Tactic>();

            Result.Name = "Своя тактика";
            for (int I = 0; I < 11; I++)
            {
                PositionInfo position = this.dataStorage.CreateDBObject <PositionInfo>();
                position.X      = locations[I].X;
                position.Y      = locations[I].Y;
                position.Number = I;
                position.Tactic = Result;
            }
            return(Result);
        }
Exemple #21
0
    public void Run()
    {
        Dictionary <string, string> cfg = new Dictionary <string, string>()
        {
            { "AUTO_CONFIG", "true" }
        };

        using (Context ctx = new Context(cfg))
        {
            RealExpr x = ctx.MkRealConst("x");
            RealExpr y = ctx.MkRealConst("y");

            Goal g = ctx.MkGoal();
            g.Assert(ctx.MkOr(ctx.MkLt(x, ctx.MkReal(0)),
                              ctx.MkGt(x, ctx.MkReal(0))));
            g.Assert(ctx.MkEq(x, ctx.MkAdd(y, ctx.MkReal(1))));
            g.Assert(ctx.MkLt(y, ctx.MkReal(0)));

            Tactic      t  = ctx.MkTactic("split-clause");
            ApplyResult ar = t[g];
            foreach (var sg in ar.Subgoals)
            {
                Console.WriteLine(sg);
            }
        }
    }
Exemple #22
0
    public void Run()
    {
        Dictionary <string, string> cfg = new Dictionary <string, string>()
        {
            { "AUTO_CONFIG", "true" }
        };

        using (Context ctx = new Context(cfg))
        {
            RealExpr x = ctx.MkRealConst("x");
            RealExpr y = ctx.MkRealConst("y");
            RealExpr z = ctx.MkRealConst("z");

            RealExpr zero = ctx.MkReal(0);
            RealExpr one  = ctx.MkReal(1);

            Goal g = ctx.MkGoal();
            g.Assert(ctx.MkOr(ctx.MkEq(x, zero), ctx.MkEq(x, one)));
            g.Assert(ctx.MkOr(ctx.MkEq(y, zero), ctx.MkEq(y, one)));
            g.Assert(ctx.MkOr(ctx.MkEq(z, zero), ctx.MkEq(z, one)));
            g.Assert(ctx.MkGt(ctx.MkAdd(x, y, z), ctx.MkReal(2)));

            Tactic t = ctx.Repeat(ctx.OrElse(ctx.MkTactic("split-clause"), ctx.MkTactic("skip")));
            Console.WriteLine(t[g]);

            t = ctx.Repeat(ctx.OrElse(ctx.MkTactic("split-clause"), ctx.MkTactic("skip")), 1);
            Console.WriteLine(t[g]);

            t = ctx.Then(ctx.Repeat(ctx.OrElse(ctx.MkTactic("split-clause"), ctx.MkTactic("skip"))), ctx.MkTactic("solve-eqs"));
            Console.WriteLine(t[g]);
        }
    }
        public ActionResult DeleteConfirmed(int id)
        {
            Tactic tactic = db.Tactic.Find(id);

            db.Tactic.Remove(tactic);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #24
0
 public GameEvent(string Result, Tactic tactic, int Amount = 0)
 {
     /// Discard or TacticOre or TacticGold
     result            = Result;
     targetTriggerName = tactic.tacticName;
     targetPlayerID    = tactic.ownerID;
     amount            = Amount;
 }
Exemple #25
0
 /// <summary>Creates a new instance of TeamSheetCreator </summary>
 public TeamSheetCreator(System.String filename)
 {
     Config.loadConfig("league.xml");
     Tactic.parseTactics("tactics.xml");
     roster = new Roster(filename);
     //Parse command line and read roster;
     teamsheet = new TeamSheet(roster);
 }
        public static Rollout[] Winner(Policy policy, Policy adversary, bool storeRollout = false)
        {
            Policy[] teamPolicies = new[] { policy, adversary };

            return(WorldGenerator.AllMatchups().AsParallel().Select(matchup => {
                World current = WorldGenerator.GenerateInitial(matchup.Team0, matchup.Team1);

                // Debug.WriteLine("Simulating " + matchup.ToString());
                List <RolloutTick> ticks = storeRollout ? new List <RolloutTick>() : null;
                int?winner = null;
                while (winner == null)
                {
                    Dictionary <int, Tactic> heroTactics = storeRollout ? new Dictionary <int, Tactic>() : null;

                    Dictionary <int, GameAction> actions = new Dictionary <int, GameAction>();
                    Simulator.AddEnvironmentalActions(current, actions);
                    foreach (Unit unit in current.Units)
                    {
                        if (unit.UnitType == UnitType.Hero)
                        {
                            Tactic tactic = PolicyEvaluator.Evaluate(current, unit, teamPolicies[unit.Team]);
                            actions[unit.UnitId] = PolicyEvaluator.TacticToAction(current, unit, tactic);

                            heroTactics?.Add(unit.UnitId, tactic);
                        }
                    }
                    ticks?.Add(new RolloutTick {
                        HeroTactics = heroTactics,
                        World = current,
                    });

                    current = Simulator.Forward(current, actions);

                    winner = current.Winner();
                }

                double winRate;
                if (winner == 0)
                {
                    winRate = 1.0;
                }
                else if (winner == 1)
                {
                    winRate = 0.0;
                }
                else
                {
                    winRate = 0.5;
                }
                return new Rollout {
                    Matchup = matchup,
                    WinRate = winRate,
                    Ticks = ticks,
                    FinalWorld = storeRollout ? current : null,
                    FinalEvaluation = IntermediateEvaluator.Evaluate(current, 0),
                };
            }).ToArray());
        }
Exemple #27
0
        public void StartTactic(Tactic newTactic)
        {
            if (!newTactic.GetData().ImmuneToKnockback)
            {
                return;
            }

            _knockbackLock.AddLock();
        }
Exemple #28
0
 public void Clear()
 {
     tactic            = null;
     trigger           = null;
     nameText.text     = "Tactic";
     oreCostText.text  = "0";
     goldCostText.text = "0";
     image.sprite      = null;
 }
Exemple #29
0
        public void EndTactic(Tactic oldTactic)
        {
            if (!oldTactic.GetData().ImmuneToKnockback)
            {
                return;
            }

            _knockbackLock.RemoveLock();
        }
        private async Task StartTacticAsync()
        {
            Tactic newTactic = await boardService.LoadTacticAsync();

            TacticDetailsViewModel = new TacticDetailsViewModel(newTactic);

            ReloadBoard(boardService.WasBlackFirstToMove() ? SideColor.White : SideColor.Black);
            OnExecuteNextMoveAsync(null);
        }
Exemple #31
0
        private void cmBoxTactics_SelectedIndexChanged(object sender, EventArgs e)
        {
            _selectedTactic = cmBoxTactics.SelectedItem as Tactic;

            var tacticIndex = _footballTactic.FindIndex(_selectedTactic?.Name);

            CreateUcPlayers(_footballTactic[tacticIndex]);

            btnSave.Enabled = false;
        }
Exemple #32
0
    private List<Tactic> TacticRouteOptimization(List<Tactic> plan)
    {
        if (plan.Count == 0)
            return plan;

        List<Tactic> finalPlan = new List<Tactic>();
        Tactic lastTactic = new Tactic(0, 0, enemyLeader, false, 0);
        Tactic nearestTactic = plan[0];

        int iterations = plan.Count;

        for (int i = 0; i < iterations; i++)
        {
            /*foreach (Tactic tc in plan)
            {
                if (Vector3.Distance(tc.targetElement.transform.position, lastTactic.targetElement.transform.position) < Vector3.Distance(nearestTactic.targetElement.transform.position, lastTactic.targetElement.transform.position))
                    nearestTactic = tc;
            }
            finalPlan.Add(nearestTactic);
            plan.Remove(nearestTactic);
            lastTactic = nearestTactic;*/

            int tci = 0;
            while(tci < plan.Count)
            {
                if (Vector3.Distance(plan[tci].targetElement.transform.position, lastTactic.targetElement.transform.position) < Vector3.Distance(nearestTactic.targetElement.transform.position, lastTactic.targetElement.transform.position))
                    nearestTactic = plan[tci];
                tci++;
            }
            finalPlan.Add(nearestTactic);
            plan.Remove(nearestTactic);
            lastTactic = nearestTactic;
        }

        return finalPlan;
    }
Exemple #33
0
 public static Tactic CopyTactic(Tactic oldTac) {
   return new Tactic(oldTac.tok, oldTac.Name, oldTac.HasStaticKeyword, oldTac.TypeArgs,
       oldTac.Ins, oldTac.Outs, oldTac.Req, oldTac.Mod, oldTac.Ens, oldTac.Decreases, oldTac.Body,
       oldTac.Attributes, oldTac.SignatureEllipsis);
 }
Exemple #34
0
	void MethodDecl(DeclModifierData dmod, bool allowConstructor, bool isWithinAbstractModule, out Method/*!*/ m) {
		Contract.Ensures(Contract.ValueAtReturn(out m) !=null);
		IToken/*!*/ id = Token.NoToken;
		bool hasName = false;  IToken keywordToken;
		Attributes attrs = null;
		List<TypeParameter/*!*/>/*!*/ typeArgs = new List<TypeParameter/*!*/>();
		List<Formal/*!*/> ins = new List<Formal/*!*/>();
		List<Formal/*!*/> outs = new List<Formal/*!*/>();
		List<MaybeFreeExpression/*!*/> req = new List<MaybeFreeExpression/*!*/>();
		List<FrameExpression/*!*/> mod = new List<FrameExpression/*!*/>();
		List<MaybeFreeExpression/*!*/> ens = new List<MaybeFreeExpression/*!*/>();
		List<Expression/*!*/> dec = new List<Expression/*!*/>();
		Attributes decAttrs = null;
		Attributes modAttrs = null;
		BlockStmt body = null;
		bool isLemma = false;
		bool isConstructor = false;
		bool isIndLemma = false;
		bool isCoLemma = false;
		bool isTactic = false;
		IToken signatureEllipsis = null;
		IToken bodyStart = Token.NoToken;
		IToken bodyEnd = Token.NoToken;
		AllowedDeclModifiers allowed = AllowedDeclModifiers.None;
		string caption = "";
		
		while (!(StartOf(12))) {SynErr(172); Get();}
		switch (la.kind) {
		case 89: {
			Get();
			caption = "Methods";
			allowed = AllowedDeclModifiers.Ghost | AllowedDeclModifiers.Static 
			 | AllowedDeclModifiers.Extern; 
			break;
		}
		case 60: {
			Get();
			isTactic = true; caption = "Tactics"; 
			allowed = AllowedDeclModifiers.AlreadyGhost | AllowedDeclModifiers.Static 
			| AllowedDeclModifiers.Protected; 
			break;
		}
		case 41: {
			Get();
			isLemma = true; caption = "Lemmas";
			allowed = AllowedDeclModifiers.AlreadyGhost | AllowedDeclModifiers.Static 
			 | AllowedDeclModifiers.Protected; 
			break;
		}
		case 90: {
			Get();
			isCoLemma = true; caption = "Colemmas";
			allowed = AllowedDeclModifiers.AlreadyGhost | AllowedDeclModifiers.Static 
			 | AllowedDeclModifiers.Protected; 
			break;
		}
		case 91: {
			Get();
			isCoLemma = true; caption = "Comethods";
			allowed = AllowedDeclModifiers.AlreadyGhost | AllowedDeclModifiers.Static 
			 | AllowedDeclModifiers.Protected;
			errors.Warning(t, "the 'comethod' keyword has been deprecated; it has been renamed to 'colemma'");
			
			break;
		}
		case 40: {
			Get();
			Expect(41);
			isIndLemma = true;  caption = "Inductive lemmas";
			allowed = AllowedDeclModifiers.AlreadyGhost | AllowedDeclModifiers.Static;
			break;
		}
		case 92: {
			Get();
			if (allowConstructor) {
			 isConstructor = true;
			} else {
			 SemErr(t, "constructors are allowed only in classes");
			} 
			caption = "Constructors";
			allowed = AllowedDeclModifiers.None;
			
			break;
		}
		default: SynErr(173); break;
		}
		keywordToken = t; 
		CheckDeclModifiers(dmod, caption, allowed); 
		while (la.kind == 46) {
			Attribute(ref attrs);
		}
		if (la.kind == 1) {
			NoUSIdent(out id);
			hasName = true; 
		}
		if (!hasName) {
		 id = keywordToken;
		 if (!isConstructor) {
		   SemErr(la, "a method must be given a name (expecting identifier)");
		 }
		}
		EncodeExternAsAttribute(dmod, ref attrs, id, /* needAxiom */ true);
		
		if (la.kind == 50 || la.kind == 52) {
			if (la.kind == 52) {
				GenericParameters(typeArgs);
			}
			Formals(true, !dmod.IsGhost, ins);
			if (la.kind == 88) {
				Get();
				if (isConstructor) { SemErr(t, "constructors cannot have out-parameters"); } 
				Formals(false, !dmod.IsGhost, outs);
			}
		} else if (la.kind == 59) {
			Get();
			signatureEllipsis = t; 
		} else SynErr(174);
		while (StartOf(13)) {
			MethodSpec(req, mod, ens, dec, ref decAttrs, ref modAttrs);
		}
		if (la.kind == 46) {
			BlockStmt(out body, out bodyStart, out bodyEnd);
		}
		if (!isWithinAbstractModule && DafnyOptions.O.DisallowSoundnessCheating && body == null && ens.Count > 0 && !Attributes.Contains(attrs, "axiom") && !Attributes.Contains(attrs, "imported") && !Attributes.Contains(attrs, "decl") && theVerifyThisFile) {
		  SemErr(t, "a method with an ensures clause must have a body, unless given the :axiom attribute");
		}
		
		IToken tok = theVerifyThisFile ? id : new IncludeToken(id);
		if (isConstructor) {
		 m = new Constructor(tok, hasName ? id.val : "_ctor", typeArgs, ins,
		                     req, new Specification<FrameExpression>(mod, modAttrs), ens, new Specification<Expression>(dec, decAttrs), body, attrs, signatureEllipsis);
		} else if (isIndLemma) {
		 m = new InductiveLemma(tok, id.val, dmod.IsStatic, typeArgs, ins, outs,
		                        req, new Specification<FrameExpression>(mod, modAttrs), ens, new Specification<Expression>(dec, decAttrs), body, attrs, signatureEllipsis);
		} else if (isCoLemma) {
		 m = new CoLemma(tok, id.val, dmod.IsStatic, typeArgs, ins, outs,
		                 req, new Specification<FrameExpression>(mod, modAttrs), ens, new Specification<Expression>(dec, decAttrs), body, attrs, signatureEllipsis);
		} else if (isLemma) {
		 m = new Lemma(tok, id.val, dmod.IsStatic, typeArgs, ins, outs,
		               req, new Specification<FrameExpression>(mod, modAttrs), ens, new Specification<Expression>(dec, decAttrs), body, attrs, signatureEllipsis);
		} else if(isTactic) {
		 m = new Tactic(tok, id.val, dmod.IsStatic, typeArgs, ins, outs,
		               req, new Specification<FrameExpression>(mod, modAttrs), ens, new Specification<Expression>(dec, decAttrs), body, attrs, signatureEllipsis);
		
		} else {
		 m = new Method(tok, id.val, dmod.IsStatic, dmod.IsGhost, typeArgs, ins, outs,
		                req, new Specification<FrameExpression>(mod, modAttrs), ens, new Specification<Expression>(dec, decAttrs), body, attrs, signatureEllipsis);
		}
		m.BodyStartTok = bodyStart;
		m.BodyEndTok = bodyEnd;
		
	}