示例#1
0
文件: Game.cs 项目: DanteX95X/pggjam
    public Model.Action ProcessInput()
    {
        Model.Action action = null;
        if (lastInput != noInput)
        {
            if (lastInput == state.SelectedPosition)
            {
                state.SelectedPosition = noInput;
                currentShip            = noInput;
                MoveSelection(noInput, false);
                MarkActions();
            }
            else if (currentShip == noInput)
            {
                action = new Model.SelectShipAction(lastInput);
            }
            else
            {
                action = new Model.MoveAction(lastInput);
            }
        }

        lastInput = noInput;
        return(action);
    }
示例#2
0
 public static WPFUtils.TreeViewWithSearch.TreeObject GetTreeStuffWithSearch()
 {
     Model.Action rootAction = new Model.Action("rootAction");
     for (int a = 5; a >= 0; a--)
     {
         Model.Action level1action = new Model.Action("0" + (6 - a) + " - level1action");
         for (int b = 4; b >= 0; b--)
         {
             Model.Action level2action = new Model.Action("0" + (6 - a) + " - level2action");
             for (int c = 3; c >= 0; c--)
             {
                 Model.Action level3action = new Model.Action("0" + (6 - a) + " - level3action");
                 for (int d = 2; d >= 0; d--)
                 {
                     Model.Action level4action = new Model.Action("0" + (6 - a) + " - level4action");
                     level3action.Children.Add(level4action);
                 }
                 level2action.Children.Add(level3action);
             }
             level1action.Children.Add(level2action);
         }
         rootAction.Children.Add(level1action);
     }
     return(rootAction);
 }
示例#3
0
文件: AI.cs 项目: jryancarr/easel
    public void move(BoardController board, bool movePlayer1)
    {
        Model.State state = getState(board, movePlayer1);
        if (state.isTerminal)
        {
            Debug.Log("AI Not moving; game is over!");
            return;
        }
        Model.Action    act      = strat.getAction(state);
        PieceController mover    = getPiece(board, act);
        PieceController captured = board.getTile(act.newPos).myPiece;

        if (captured != null)
        {
            Debug.Log("AI Moving player " + mover.model.playerNum + "'s " + mover.model.color + " piece at (" + mover.model.position.x + "," + mover.model.position.y + ") "
                      + " to capture player " + captured.model.playerNum + "'s " + captured.model.color + " piece at (" + captured.model.position.x + "," + captured.model.position.y + ").");
            board.combine(mover, captured);
        }
        else
        {
            Debug.Log("AI Moving player " + mover.model.playerNum + "'s " + mover.model.color + " piece at (" + mover.model.position.x + "," + mover.model.position.y + ") "
                      + " to (" + act.newPos.x + "," + act.newPos.y + ").");
            mover.move(act.newPos);
        }
    }
 public ActionViewModelBase(Model.Action action)
 {
     if (action is null)
     {
         throw new ArgumentException("Argument cannot be null", "action");
     }
     _action = action;
 }
示例#5
0
        public void Add(Model.Action action)
        {
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            DataContext.Actions.Add(action);
        }
示例#6
0
 private void SimulatorTookAction(Model.Action action, GameState resultState)
 {
     Invoke(new EventHandler(delegate
     {
         State       = resultState;
         label1.Text = action.ToString();
         ++TurnsTaken;
         UpdateDisplay();
     }));
 }
示例#7
0
 public Model.Action InsertAction(Model.Action action)
 {
     CheckZoneAccess(action);
     if (action.Id == null || action.Id == Guid.Empty)
     {
         action.Id = Guid.NewGuid();
     }
     actionRepository.CreateAction(action);
     return(action);
 }
示例#8
0
        public static int Calc(Model.Action action, Cell target, Player sender)
        {
            if (target == null || sender == null)
            {
                throw new ArgumentNullException();
            }
            switch (action)
            {
            case Model.Action.Attack:
                if (target.State == CellState.Empty)
                {
                    return(1000);
                }
                else if (target.State == CellState.Occupied)
                {
                    int time = 1000;
                    if (target.Owner != sender &&
                        DateTime.Now > target.OccupiedTime)
                    {
                        //attack other
                        var duration = (DateTime.Now - target.OccupiedTime).Value.TotalSeconds;
                        if (duration > 60)
                        {
                            time = 3000;
                        }
                        else if (duration > 30)
                        {
                            time = 6000;
                        }
                        else if (duration > 15)
                        {
                            time = 9000;
                        }
                        else if (duration > 5)
                        {
                            time = 12000;
                        }
                        else
                        {
                            time = 15000;
                        }
                    }

                    //Console.WriteLine("Sleep time:" + time.ToString());
                    return(time);
                }
                else
                {
                    return(0);
                }

            default:
                return(0);
            }
        }
 public override void OnGraphStart(Playable playable)
 {
     if (!EditorApplication.isPlaying)
     {
         return;
     }
     Loader.Instance.CreatAction(actionPlayable.ActionName, actionConfig => {
         roleAction = actionConfig;
     });
     roleObj = World.Instance.GetRoleObj(actionPlayable.Role);
 }
示例#10
0
        /// <summary>
        /// Procesa un node 'state'
        /// </summary>
        /// <param name="stateNode">El node.</param>
        /// <returns>Un objecte 'State'.</returns>
        ///
        private State ProcessStateNode(XmlNode stateNode)
        {
            // Obte el nom del estat.
            //
            string stateName = null;

            if (stateNode.ParentNode.Name == "state")
            {
                stateName = GetAttribute(stateNode.ParentNode, "name");
            }
            stateName += GetAttribute(stateNode, "name");

            // Obte l'accio d'entrada.
            //
            XmlNode onEnterNode = stateNode.SelectSingleNode("enter");

            Model.Action enterAction = (onEnterNode == null) ? null : ProcessActionNode(onEnterNode);

            // Obte l'accio de sortida.
            //
            XmlNode onExitNode = stateNode.SelectSingleNode("exit");

            Model.Action exitAction = (onExitNode == null) ? null : ProcessActionNode(onExitNode);

            // Obte les transicions.
            //
            List <Transition> transitionList = new List <Transition>();

            foreach (XmlNode transitionNode in stateNode.SelectNodes("transition"))
            {
                Transition transition = ProcessTransitionNode(transitionNode);
                transitionList.Add(transition);
            }

            // Obte els stats fills
            //
            foreach (XmlNode childStateNode in stateNode.SelectNodes("state"))
            {
                ProcessStateNode(childStateNode);
            }

            // Crea l'estat
            //
            State state = GetState(stateName);

            state.EnterAction = enterAction;
            state.ExitAction  = exitAction;
            foreach (var transition in transitionList)
            {
                state.AddTransition(transition);
            }

            return(state);
        }
 public MetaAction Create(Model.Action action)
 {
     return(new MetaAction()
     {
         Name = action.Name,
         Condition = Model.ModelParser.MetaConditionFactory.Create(action.Condition),
         Stop = Create(action.Stop),
         Limit = Create(action.Limit),
         Entry = Create(action.Entry),
         ActionType = ParseActionType(action.ActionType)
     });
 }
示例#12
0
        /// <summary>
        /// Procesa un node 'machine'
        /// </summary>
        /// <param name="machineNode">El node.</param>
        /// <returns>Un objecte 'Machine'.</returns>
        ///
        private Machine ProcessMachineNode(XmlNode machineNode)
        {
            // Obte el nom de la maquina
            //
            string machineName = GetAttribute(machineNode, "name");

            if (String.IsNullOrEmpty(machineName))
            {
                throw new Exception("No se especifico el atributo 'name'");
            }

            // Obte el estat inicial.
            //
            string startStateName = GetAttribute(machineNode, "start");

            if (String.IsNullOrEmpty(startStateName))
            {
                throw new Exception("No se especifico el atributo 'start'");
            }
            State startState = GetState(startStateName.Replace(":", ""));

            // Obte l'accio d'inicialitzacio.
            //
            XmlNode initializeNode = machineNode.SelectSingleNode("initialize");

            Model.Action initializeAction = (initializeNode == null) ? null : ProcessActionNode(initializeNode);

            // Obte l'accio de finalitzacio
            //
            XmlNode terminateNode = machineNode.SelectSingleNode("terminate");

            Model.Action terminateAction = (terminateNode == null) ? null : ProcessActionNode(terminateNode);

            // Procesa cada estat i asigna els parametres
            //
            List <State> stateList = new List <State>();

            foreach (XmlNode stateNode in machineNode.SelectNodes("state"))
            {
                stateList.Add(ProcessStateNode(stateNode));
            }

            // Crea la maquina
            //
            Machine machine = new Machine(machineName);

            machine.InitializeAction = initializeAction;
            machine.TerminateAction  = terminateAction;
            machine.AddStates(stateList);
            machine.Start = startState;

            return(machine);
        }
示例#13
0
        private void CheckZoneAccess(Model.Action action)
        {
            ZoneState zoneState = inventorizationRepository.GetZoneState(action.Inventorization, action.Zone);

            if (zoneState == null)
            {
                throw new ZoneAccessException(action.Zone, $"Зона не была открыта. Сначала откройте зону.");
            }
            if (zoneState.ClosedAt.HasValue && zoneState.ClosedAt.Value.ToUniversalTime() < DateTime.Now)
            {
                throw new ZoneAccessException(action.Zone, $"Зона закрыта. Выберите другую зону.");
            }
        }
示例#14
0
        public Model.Action UpsertAction(Model.Action action)
        {
            bool actionExists = ActionExists(action.Id);

            if (actionExists)
            {
                UpdateAction(action);
                return(action);
            }
            else
            {
                return(InsertAction(action));
            }
        }
示例#15
0
        public static int Calc(Model.Action action, Cell target, Player sender)
        {
            if (target == null || sender == null)
            {
                return(Int32.MinValue);
            }
            switch (action)
            {
            case Model.Action.Attack:
                return(_calcInternal(action, target, sender));

            default:
                return(0);
            }
        }
示例#16
0
        internal static int _calcInternal(Model.Action action, Cell target, Player sender)
        {
            if (target.State == CellState.Occupied)
            {
                int time = 2000;
                if (target.Owner != sender &&
                    DateTime.Now > target.OccupiedTime)
                {
                    //attack other
                    var ts = DateTime.Now - target.OccupiedTime;
                    if (ts != null && ts.HasValue)
                    {
                        var duration = ts.Value.TotalSeconds;
                        if (duration > 60)
                        {
                            time = 5000;
                        }
                        else if (duration > 30)
                        {
                            time = 15000;
                        }
                        else if (duration > 15)
                        {
                            time = 20000;
                        }
                        else if (duration > 5)
                        {
                            time = 25000;
                        }
                        else
                        {
                            time = 30000;
                        }
                    }
                }

                //Console.WriteLine("Sleep time:" + time.ToString());
                return(time);
            }
            else
            {
                return(2000);
            }
        }
示例#17
0
        private void DoAction(Model.Action action)
        {
            bool wasActionTaken = false;

            if (_Mode == Mode.Play)
            {
                wasActionTaken = GameSimulator.TakeAction(State, action);
            }
            else if (_Mode == Mode.Guide && State.IsActionLegal(action))
            {
                State.ApplyAction(action);
            }

            if (wasActionTaken)
            {
                ++TurnsTaken;
                UpdateDisplay();
                DisplayEndOfGameIfNeeded();
            }
        }
示例#18
0
        public void InitializeAction()
        {
            ActionService actionService = new ActionService();

            Model.Action action = actionService.Add(new Model.Action
            {
                ActionType = "menu"
            });
            //关联Menu菜单和权限
            MenuService menuService = new MenuService();

            menuService.GetEntities(u => u.Id > 0).ToList().ForEach(m => m.Action.Add(action));
            Model.Action module = actionService.Add(new Model.Action
            {
                ActionType = "module"
            });
            //关联ActionModule表和Action表
            ActionModuleService actionModuleService = new ActionModuleService();

            actionModuleService.GetEntities(u => u.Id > 0).ToList().ForEach(m => m.Action.Add(module));
        }
示例#19
0
        public static IEnumerator StartPruning(GameState state, float timeLimit)
        {
            needToExit = false;
            int    depth      = 1;
            float  timeStart  = Time.time;
            Action bestAction = null;

            do
            {
                Model.Action current = Prune(state, depth, int.MinValue, int.MaxValue, state.CurrentPlayer == 0, null, timeLimit, timeStart).action;
                if (!needToExit)
                {
                    bestAction = current;
                }
                ++depth;
                System.GC.Collect();
                yield return(null);
            }while(Time.time - timeStart < timeLimit);
            //bestAction.Print();
            ufo        = bestAction;
            needToExit = false;
        }
示例#20
0
        /// <summary>
        /// Construeix les instruccions coresponents a una accio.
        /// </summary>
        /// <param name="action">La accio.</param>
        /// <returns>La llista d'instruccions.</returns>
        ///
        private StatementList MakeActionStatements(Model.Action action)
        {
            if (action.Activities == null)
            {
                return(null);
            }

            else
            {
                StatementList statements = new StatementList();
                foreach (var activity in action.Activities)
                {
                    if (activity is RunActivity callActivity)
                    {
                        Statement statement = new InvokeStatement(
                            new InvokeExpression(
                                new IdentifierExpression(String.Format("owner->do{0}", callActivity.ProcessName))));
                        statements.Add(statement);
                    }
                }
                return(statements);
            }
        }
示例#21
0
文件: Game.cs 项目: DanteX95X/pggjam
    void Update()
    {
        if (isWon)
        {
            timePassed += Time.deltaTime;
            if (timePassed >= 5.0f)
            {
                SceneManager.LoadScene(0);
            }
        }


        if (dirtyHack)
        {
            dirtyHack = false;
            MarkActions();
        }

        if (!isInCouroutine)
        {
            if (state.WhoWon() == -1)
            {
                Model.Action action = null;
                switch (controllers[CurrentPlayer])
                {
                case ControllerType.HUMAN:
                {
                    action = ProcessInput();
                    break;
                }

                case ControllerType.AI:
                {
                    StartCoroutine(Model.AlphaBeta.StartPruning(state, 0.3f));                            //state.GenerateActions()[0];//Model.AlphaBeta.StartPruning(state.Clone(), 1.0f);
                    action = Model.AlphaBeta.ufo;
                    break;
                }

                case ControllerType.RANDOM:
                {
                    List <Model.Action> actions = state.GenerateActions();
                    action = actions[UnityEngine.Random.Range(0, actions.Count)];
                    break;
                }
                }
                if (action != null && action.IsLegal(state))
                {
                    action.ApplyAction(state);
                    action.ApplyAction(this);
                    MarkActions();
                    //action.Print();
                    Model.AlphaBeta.ufo = null;
                }
            }
            else
            {
                if (!winText.enabled)
                {
                    Camera.main.gameObject.GetComponent <AudioSource>().Stop();
                    GetComponent <AudioSource>().Play();
                }
                Debug.Log("Game Over " + state.WhoWon());
                if (state.WhoWon() == 1)
                {
                    winText.text    = "Player 1 won!";
                    winText.enabled = true;
                    isWon           = true;
                }
                else if (state.WhoWon() == 0)
                {
                    winText.text    = "Player 0 won!";
                    winText.enabled = true;
                    isWon           = true;
                }
            }
        }

        SetupShipLines();
    }
示例#22
0
文件: AI.cs 项目: jryancarr/easel
 private PieceController getPiece(BoardController board, Model.Action act)
 {
     return(board.getTile(act.piece.position).myPiece);
 }
示例#23
0
 public ActionMessage(Model.Action action)
 {
     this.Action = action;
 }
示例#24
0
 public SearchPair(Model.Action act, double eval)
 {
     this.act  = act;
     this.eval = eval;
 }
 private void AddAction()
 {
     Model.Action action = new Model.Action() { ActionName = this.ActionName.Trim() };
     this.Actions.Add(action);
     this.CurrentAction = action;
     //this.ActionName = string.Empty;
 }
示例#26
0
 public ActionViewModel(Model.Action action)
     : base(action)
 {
 }
示例#27
0
 public void UpdateAction(Model.Action action)
 {
     CheckZoneAccess(action);
     actionRepository.UpdateAction(action);
 }