コード例 #1
0
ファイル: SearchFramework.cs プロジェクト: ggrov/tacny
        public static Strategy GetSearchStrategy(ITactic tac)
        {
            Contract.Requires <ArgumentNullException>(tac != null);
            MemberDecl md    = tac as MemberDecl;
            Attributes attrs = md?.Attributes;


            if (attrs?.Name != "search")
            {
                return(Strategy.Bfs);
            }

            Expression expr = attrs.Args.FirstOrDefault();
            var        name = (expr as NameSegment)?.Name;

            switch (name?.ToUpper())
            {
            case "BFS":
                return(Strategy.Bfs);

            case "DFS":
                return(Strategy.Dfs);

            default:
                Contract.Assert(false, (Error.MkErr(expr, 19, name)));
                return(Strategy.Bfs);
            }
        }
コード例 #2
0
 public void FindAndResolveTacticApplication(Program tacnyProgram, Function fun)
 {
     if (IsLeaf())
     {
         var aps = Data as ApplySuffix;
         if (aps == null)
         {
             return;
         }
         UpdateStmt us = new UpdateStmt(aps.tok, aps.tok, new List <Expression>(), new List <AssignmentRhs> {
             new ExprRhs(aps)
         });
         if (tacnyProgram.IsTacticCall(us))
         {
             List <IVariable> variables = new List <IVariable>();
             ITactic          tac       = tacnyProgram.GetTactic(us);
             tacnyProgram.SetCurrent(tac, fun);
             variables.AddRange(fun.Formals);
             // get the resolved variables
             List <IVariable> resolved = new List <IVariable>();
             Console.Out.WriteLine($"Resolving {tac.Name} in {fun.Name}");
             resolved.AddRange(fun.Formals); // add input arguments as resolved variables
             var result = LazyTacny.Atomic.ResolveTactic(us, fun, tacnyProgram, variables, resolved);
             Data = result.State.DynamicContext.generatedExpressions[0];
             tacnyProgram.CurrentDebug.Fin();
             Modified = true;
         }
     }
     else
     {
         LChild.FindAndResolveTacticApplication(tacnyProgram, fun);
         RChild?.FindAndResolveTacticApplication(tacnyProgram, fun);
     }
 }
コード例 #3
0
        public static bool CheckTacticDef(ITactic tac, out string errMsg)
        {
            Contract.Requires(tac != null);
            foreach (var arg in tac.Ins)
            {
                var name = arg.Type is UserDefinedType ? (arg.Type as UserDefinedType).Name : arg.Type.ToString();
                if (!IsTacticTypes(name))
                {
                    errMsg = name +
                             " is a valid type for tactic arguments.";
                    return(false);
                }
            }
            foreach (var arg in tac.Outs)
            {
                var name = arg.Type is UserDefinedType ? (arg.Type as UserDefinedType).Name : arg.Type.ToString();
                if (!IsTacticTypes(name))
                {
                    errMsg = name +
                             " is a valid type for tactic return variables.";
                    return(false);
                }
            }

            errMsg = "";
            return(true);
        }
コード例 #4
0
 public void Add(ITactic tactic)
 {
     for (int i = 0; i < 5; i++)
     {
         string id = $"{alpha[i]}{i}";
         Tactics.Add(new TacticHolder(tactic, id));
     }
 }
コード例 #5
0
 public TacticHolder(ITactic tactic, string id)
 {
     Tactic  = tactic;
     Balance = 1000;
     State   = State.Idle;
     LastBet = new BetResult(true, new Bet(true, 0));
     Wins    = 0;
     Losses  = 0;
     ID      = id;
 }
コード例 #6
0
ファイル: Context.cs プロジェクト: ggrov/tacny
 public DynamicContext(MemberDecl md, ITactic tac, UpdateStmt tac_call)
     : base(md, tac_call) {
   tactic = tac;
   if (tactic is Tactic) {
     var tmp = tactic as Tactic;
     tacticBody = new List<Statement>(tmp.Body.Body.ToArray());
   }
   tacCounter = 0;
   FillTacticInputs();
 }
コード例 #7
0
ファイル: Context.cs プロジェクト: ggrov/tacny
 public DynamicContext(MemberDecl md, ITactic tac, UpdateStmt tac_call)
     : base(md, tac_call)
 {
     tactic = tac;
     if (tactic is Tactic)
     {
         var tmp = tactic as Tactic;
         tacticBody = new List <Statement>(tmp.Body.Body.ToArray());
     }
     tacCounter = 0;
     FillTacticInputs();
 }
コード例 #8
0
 public Frame(Frame parent, List <Statement> body)
 {
     Contract.Requires <ArgumentNullException>(parent != null);
     Contract.Requires <ArgumentNullException>(tcce.NonNullElements(body), "body");
     // carry over the tactic info
     TacticInfo         = parent.TacticInfo;
     Body               = body;
     _declaredVariables = new Dictionary <string, object>();
     Parent             = parent;
     ActiveTactic       = parent.ActiveTactic;
     _reporter          = parent._reporter;
 }
コード例 #9
0
        public void SetCurrent(ITactic tac, MemberDecl md)
        {
            Contract.Requires(tac != null);
            Contract.Requires(md != null);
            var dd = DebugDataList.LastOrDefault(i => i.Tactic == tac.Name && i.Method == md.Name);

            if (dd == null)
            {
                dd = new DebugData(tac.Name, md.Name);
                DebugDataList.Add(dd);
            }
            CurrentDebug = dd;
        }
コード例 #10
0
ファイル: Context.cs プロジェクト: ggrov/tacny
        public DynamicContext Copy()
        {
            var     newM       = Util.Copy.CopyMember(md);
            ITactic newTac     = Util.Copy.CopyMember(tactic as MemberDecl) as ITactic;
            var     new_target = newTarget != null?Util.Copy.CopyMember(newTarget) : null;

            var newContext = new DynamicContext(newM, newTac, tac_call, tacticBody, localDeclarations, Util.Copy.CopyStatementDict(generatedStatements), tacCounter, new_target);

            newContext.activeCtor         = activeCtor;
            newContext.isPartialyResolved = isPartialyResolved;
            newContext.whileStmt          = whileStmt;
            return(newContext);
        }
コード例 #11
0
        public static bool CheckTacticArgs(ITactic tac, ApplySuffix aps, ProofState state, out string errMsg)
        {
            Contract.Requires(tac != null);
            Contract.Requires(aps != null);

            if (aps.Args.Count != tac.Ins.Count)
            {
                errMsg = "The number of args doesn't match the tactic definition for "
                         + Printer.ExprToString(aps);
                return(false);
            }

            for (var i = 0; i < tac.Ins.Count; i++)
            {
                var name = tac.Ins[i].Type is UserDefinedType ?
                           (tac.Ins[i].Type as UserDefinedType).Name : tac.Ins[i].Type.ToString();

                switch (name)
                {
                case "bool":
                case "int":
                    if (!(aps.Args[i] is NameSegment) ||
                        tac.Ins[i].Type.ToString() != aps.Args[i].Type.ToString())
                    {
                        errMsg = "In arg[" + i + "], expect " + tac.Ins[i].Type + " but " + aps.Args[i] +
                                 " is found";
                        return(false);
                    }
                    break;

                case "term":
                    break;

                case "tac":
                    if (!CheckTypeTac(tac.Ins[i].Type as UserDefinedType,
                                      (aps.Args[i] as NameSegment).Name, state, out errMsg))
                    {
                        return(false);
                    }
                    break;

                default:
                    break;
                }
            }
            errMsg = "";
            return(true);
        }
コード例 #12
0
ファイル: Context.cs プロジェクト: ggrov/tacny
    public DynamicContext(MemberDecl md, ITactic tac, UpdateStmt tac_call,
        List<Statement> tac_body, Dictionary<IVariable, object> local_variables,
        Dictionary<Statement, Statement> updated_statements, int tacCounter, MemberDecl old_target)
        : base(md, tac_call) {
      tactic = tac;
      tacticBody = new List<Statement>(tac_body.ToArray());

      List<IVariable> lv_keys = new List<IVariable>(local_variables.Keys);
      List<object> lv_values = new List<object>(local_variables.Values);
      localDeclarations = lv_keys.ToDictionary(x => x, x => lv_values[lv_keys.IndexOf(x)]);

      generatedStatements = updated_statements;

      this.tacCounter = tacCounter;
      newTarget = old_target;
    }
コード例 #13
0
ファイル: ProofState.cs プロジェクト: ggrov/tacny
 public Frame(Frame parent, List <Statement> body, bool partial, string kind)
 {
     Contract.Requires <ArgumentNullException>(parent != null);
     Contract.Requires <ArgumentNullException>(tcce.NonNullElements(body), "body");
     // carry over the tactic info
     Body = body;
     _declaredVariables      = new Dictionary <string, object>();
     _DafnyVariables         = new Dictionary <string, VariableData>();
     Parent                  = parent;
     ActiveTactic            = parent.ActiveTactic;
     _reporter               = parent._reporter;
     _generatedCode          = null;
     _rawCodeList            = new List <List <Statement> >();
     WhatKind                = kind;
     FrameCtrlInfo           = parent.FrameCtrlInfo;
     FrameCtrlInfo.IsPartial = FrameCtrlInfo.IsPartial || partial;
 }
コード例 #14
0
ファイル: Context.cs プロジェクト: ggrov/tacny
        public DynamicContext(MemberDecl md, ITactic tac, UpdateStmt tac_call,
                              List <Statement> tac_body, Dictionary <IVariable, object> local_variables,
                              Dictionary <Statement, Statement> updated_statements, int tacCounter, MemberDecl old_target)
            : base(md, tac_call)
        {
            tactic     = tac;
            tacticBody = new List <Statement>(tac_body.ToArray());

            List <IVariable> lv_keys   = new List <IVariable>(local_variables.Keys);
            List <object>    lv_values = new List <object>(local_variables.Values);

            localDeclarations = lv_keys.ToDictionary(x => x, x => lv_values[lv_keys.IndexOf(x)]);

            generatedStatements = updated_statements;

            this.tacCounter = tacCounter;
            newTarget       = old_target;
        }
コード例 #15
0
            /// <summary>
            /// Initialize the top level frame
            /// </summary>
            /// <param name="tactic"></param>
            /// <param name="reporter"></param>
            public Frame(ITactic tactic, ErrorReporter reporter)
            {
                Contract.Requires <ArgumentNullException>(tactic != null, "tactic");
                Parent = null;
                var o = tactic as Tactic;

                if (o != null)
                {
                    Body = o.Body.Body;
                }
                else
                {
                    throw new NotSupportedException("tactic functions are not yet supported");
                }
                ActiveTactic = tactic;
                ParseTacticAttributes(((MemberDecl)ActiveTactic).Attributes);
                _reporter          = reporter;
                _declaredVariables = new Dictionary <string, object>();
                _generatedCode     = new List <Statement>();
            }
コード例 #16
0
ファイル: Robot.cs プロジェクト: jimfim/vindinium-core
        //starts everything
        public void Run()
        {
            while (this._server.Finished == false && this._server.Errored == false)
            {
                _tactic   = new SurvivalGoldRush(_server);
                _movement = new ShortestPath(_server);

                var destination = _tactic.NextDestination();

                var route = _movement.GetShortestCompleteRouteToLocation(destination.Location);

                string direction = "Stay";
                if (route != null)
                {
                    direction = this._server.GetDirection(_server.MyHero.Location, route.Any() ? route.First().Location : null);
                }


                this._server.MoveHero(direction);
                Console.Clear();
                VisualizeMap(_server, route);
                Console.Out.WriteLine("=========================================");
                Console.Out.WriteLine("Target Location : {0},{1}", destination.Location.X, destination.Location.Y);
                Console.Out.WriteLine("Target Cost \t: {0}", destination.MovementCost);
                Console.Out.WriteLine("Target Type \t: {0}", destination.Type);
                Console.Out.WriteLine("=========================================");
                Console.Out.WriteLine("Hero Location \t: {0},{1}", _server.MyHero.Location.X, _server.MyHero.Location.Y);
                Console.Out.WriteLine("Hero Life \t: {0}", (_server.MyHero as HeroNode).Life);
                Console.Out.WriteLine("Hero Gold \t: {0}", (_server.MyHero as HeroNode).Gold);
                Console.Out.WriteLine("Hero Mines \t: {0}", (_server.MyHero as HeroNode).MineCount);
                Console.Out.WriteLine("Hero Moving \t: {0}", direction);
                Console.Out.WriteLine("=========================================");
                Console.Out.WriteLine("Completed Turn " + this._server.CurrentTurn);
            }

            if (this._server.Errored)
            {
                Console.Out.WriteLine("error: " + this._server.ErrorText);
            }
            Console.Out.WriteLine("{0} Finished", BotName);
        }
コード例 #17
0
ファイル: SearchFramework.cs プロジェクト: ggrov/tacny
    public static Strategy GetSearchStrategy(ITactic tac) {
      Contract.Requires<ArgumentNullException>(tac != null);
      MemberDecl md = tac as MemberDecl;
      Attributes attrs = md?.Attributes;


      if (attrs?.Name != "search")
        return Strategy.Bfs;

      Expression expr = attrs.Args.FirstOrDefault();
      var name = (expr as NameSegment)?.Name;
      switch (name?.ToUpper()) {
        case "BFS":
          return Strategy.Bfs;
        case "DFS":
          return Strategy.Dfs;
        default:
          Contract.Assert(false, (Error.MkErr(expr, 19, name)));
          return Strategy.Bfs;
      }
    }
コード例 #18
0
ファイル: Robot.cs プロジェクト: jimfim/vindinium-bot
        //starts everything
        public void Run()
        {
            while (this._server.Finished == false && this._server.Errored == false)
            {
                _mapBuilder = new DefaultMapBuilder(_server);
                _tactic = new SurvivalGoldRush(_mapBuilder);
                _movement = new DefaultMovement(_mapBuilder);

                var destination = _tactic.NextDestination();
                var route = _movement.GetShortestCompleteRouteToLocation(destination.Location);

                var direction = this._server.GetDirection(_mapBuilder.HeroNode.Location, route.Any() ? route.First().Location : null);
                this._server.MoveHero(direction);
                Console.Out.WriteLine("completed turn " + this._server.CurrentTurn);
            }

            if (this._server.Errored)
            {
                Console.Out.WriteLine("error: " + this._server.ErrorText);
            }
            Console.Out.WriteLine("{0} Finished", BotName);
        }
コード例 #19
0
ファイル: ProofState.cs プロジェクト: ggrov/tacny
 public Frame(Frame parent, List<Statement> body) {
   Contract.Requires<ArgumentNullException>(parent != null);
   Contract.Requires<ArgumentNullException>(tcce.NonNullElements(body), "body");
   // carry over the tactic info
   TacticInfo = parent.TacticInfo;
   Body = body;
   _declaredVariables = new Dictionary<string, object>();
   Parent = parent;
   ActiveTactic = parent.ActiveTactic;
   _reporter = parent._reporter;
 }
コード例 #20
0
ファイル: ProofState.cs プロジェクト: ggrov/tacny
 /// <summary>
 /// Initialize the top level frame
 /// </summary>
 /// <param name="tactic"></param>
 /// <param name="reporter"></param>
 public Frame(ITactic tactic, ErrorReporter reporter) {
   Contract.Requires<ArgumentNullException>(tactic != null, "tactic");
   Parent = null;
   var o = tactic as Tactic;
   if (o != null) Body = o.Body.Body;
   else {
     throw new NotSupportedException("tactic functions are not yet supported");
   }
   ActiveTactic = tactic;
   ParseTacticAttributes(((MemberDecl)ActiveTactic).Attributes);
   _reporter = reporter;
   _declaredVariables = new Dictionary<string, object>();
   _generatedCode = new List<Statement>();
 }
コード例 #21
0
ファイル: ProofState.cs プロジェクト: ggrov/tacny
 public Frame(Frame parent, List<Statement> body, bool partial, string kind) {
   Contract.Requires<ArgumentNullException>(parent != null);
   Contract.Requires<ArgumentNullException>(tcce.NonNullElements(body), "body");
   // carry over the tactic info
   Body = body;
   _declaredVariables = new Dictionary<string, object>();
   _DafnyVariables = new Dictionary<string, VariableData>();
   Parent = parent;
   ActiveTactic = parent.ActiveTactic;
   _reporter = parent._reporter;
   _generatedCode = null;
   _rawCodeList = new List<List<Statement>>();
   WhatKind = kind;
   FrameCtrlInfo = parent.FrameCtrlInfo;
   FrameCtrlInfo.IsPartial = FrameCtrlInfo.IsPartial || partial;
 }
コード例 #22
0
ファイル: Battle.cs プロジェクト: samwowen/PrisonersDilema
 public Battle(ITactic a, ITactic b)
 {
     p1 = a;
     p2 = b;
 }