Ejemplo n.º 1
0
        public void SendMoveRequest(Party p, Tile t, MovementIntent intent)
        {
            var path = t.Chunk.Map.FindPath(p.Tile, t).Select(pa => new Position(pa.X, pa.Y)).ToList();
            var ev   = new MoveRequestEvent()
            {
                Path = path, PartyIndex = p.PartyIndex, Intent = intent
            };

            ev.Sender = this;
            t.Chunk.Map.World.Game.NetworkEvents.RunCallbacks(ev);
        }
Ejemplo n.º 2
0
        private CourseTask StartCourse(Party party, List <Position> sentPath, MovementIntent intent)
        {
            List <Tile> path  = new List <Tile>();
            var         owner = party.Owner;

            foreach (var position in sentPath)
            {
                var tile = _world.GetTile(position.X, position.Y);
                if (!tile.Passable)
                {
                    Log.Error($"Impassable tile {tile} in course path: {owner} moving party {party}");
                    return(null);
                }
                path.Add(tile);
            }
            party.Course = new CourseTask(party, path, intent);
            return(party.Course);
        }
Ejemplo n.º 3
0
        private void MoveToSelectedTile(MovementIntent intent)
        {
            ClientParty party        = UIManager.PartyUI.SelectedParty;
            ClientTile  selectedTile = UIManager.TileUI.SelectedTile;

            Log.Debug($"Moving {party} to {selectedTile}");
            var map      = selectedTile.Chunk.Map;
            var path     = map.FindPath(party.Tile, selectedTile);
            var tilePath = path.Select(node => (ClientTile)map.GetTile(node.X, node.Y)).ToList();

            ClientEvents.StartMovementRequest(party, tilePath);
            MainBehaviour.Networking.Send(new MoveRequestEvent()
            {
                PartyIndex = party.PartyIndex,
                Path       = path.Select(p => new Game.World.Position(p.X, p.Y)).ToList(),
                Intent     = intent
            });
        }
Ejemplo n.º 4
0
 void Update()
 {
     Intent = 0;
     // Human AZERTY / QWERTY
     if (ControlType == 0)
     {
         if (Input.GetKey(KeyCode.Z) || Input.GetKey(KeyCode.W))
         {
             Intent = Intent | MovementIntent.WantToMoveForward;
         }
         if (Input.GetKey(KeyCode.S))
         {
             Intent = Intent | MovementIntent.WantToMoveBackward;
         }
         if (Input.GetKey(KeyCode.Q) || Input.GetKey(KeyCode.A))
         {
             Intent = Intent | MovementIntent.WantToMoveLeft;
         }
         if (Input.GetKey(KeyCode.D))
         {
             Intent = Intent | MovementIntent.WantToMoveRight;
         }
     }
     // Human Arrow
     else if (ControlType == 1)
     {
         if (Input.GetKey(KeyCode.UpArrow))
         {
             Intent = Intent | MovementIntent.WantToMoveForward;
         }
         if (Input.GetKey(KeyCode.DownArrow))
         {
             Intent = Intent | MovementIntent.WantToMoveBackward;
         }
         if (Input.GetKey(KeyCode.LeftArrow))
         {
             Intent = Intent | MovementIntent.WantToMoveLeft;
         }
         if (Input.GetKey(KeyCode.RightArrow))
         {
             Intent = Intent | MovementIntent.WantToMoveRight;
         }
     }
 }
Ejemplo n.º 5
0
    public MovementIntent Act(PacManGameState gs, int playerNumber)
    {
        int            bestActionScore = 0;
        int            j;
        MovementIntent bestAction = 0;

        foreach (var action in movementIntentValues)
        {
            int actionScore = 0;

            for (var i = 0; i < RolloutIterations; i++)
            {
                gsCopy.CopyGS(gs);

                var            randActionIndex = UnityEngine.Random.Range(0, movementIntentValues.Length);
                MovementIntent randAction      = (MovementIntent)movementIntentValues.GetValue(randActionIndex);

                var result = PacManGameState.Step(gsCopy, action, randAction, Speed);

                for (j = 0; !result[2] && j < ExplorationFrames; j++)   // While not terminal state
                {
                    randActionIndex = UnityEngine.Random.Range(0, movementIntentValues.Length);
                    MovementIntent randAction1 = (MovementIntent)movementIntentValues.GetValue(randActionIndex);
                    randActionIndex = UnityEngine.Random.Range(0, movementIntentValues.Length);
                    MovementIntent randAction2 = (MovementIntent)movementIntentValues.GetValue(randActionIndex);

                    result = PacManGameState.Step(gsCopy, randAction1, randAction2, Speed);
                }

                actionScore += result[playerNumber] ? 1 : 0;
            }

            if (actionScore > bestActionScore)
            {
                bestActionScore = actionScore;
                bestAction      = action;
            }
        }

        return(bestAction);
    }
Ejemplo n.º 6
0
    // Setter mouvement
    private static void IntentManagement(MovementIntent Intent, int playerIndex, float Speed, PacManGameState p)
    {
        if ((Intent & MovementIntent.WantToMoveForward) != 0)
        {
            tryMovingInDirection(playerIndex, 0, Speed, p);
        }

        if ((Intent & MovementIntent.WantToMoveBackward) != 0)
        {
            tryMovingInDirection(playerIndex, 1, Speed, p);
        }

        if ((Intent & MovementIntent.WantToMoveLeft) != 0)
        {
            tryMovingInDirection(playerIndex, 3, Speed, p);
        }
        if ((Intent & MovementIntent.WantToMoveRight) != 0)
        {
            tryMovingInDirection(playerIndex, 2, Speed, p);
        }
        p.P1 = Portal(p.P1, 0.0f, (float)p.XSize - 1.0f, 0.0f, (float)p.ZSize - 1.0f);
        p.P2 = Portal(p.P2, 0.0f, (float)p.XSize - 1.0f, 0.0f, (float)p.ZSize - 1.0f);
    }
Ejemplo n.º 7
0
 // Récupère Intent et Applique changement de position
 public static bool[] Step(PacManGameState p, MovementIntent action1, MovementIntent action2, float Speed)
 {
     if (p.P1Killer)
     {
         IntentManagement(action1, 0, Speed * 1.2f, p);
         IntentManagement(action2, 1, Speed, p);
     }
     else if (p.P2Killer)
     {
         IntentManagement(action1, 0, Speed, p);
         IntentManagement(action2, 1, Speed * 1.2f, p);
     }
     else
     {
         IntentManagement(action1, 0, Speed, p);
         IntentManagement(action2, 1, Speed, p);
     }
     SearchContactWithGum(p);
     SearchContactBetweenPlayer(p);
     return(new bool[3] {
         p.P1Winner, p.P2Winner, p.GameEnd
     });
 }
Ejemplo n.º 8
0
 public CourseTask(Party party, List <Tile> path, MovementIntent intent) : base(party.GetMoveDelay())
 {
     this.Party  = party;
     this.Path   = path;
     this.Intent = intent;
 }