예제 #1
0
 private Dictionary <EDirection, Vector2Int> GetNeighbours(
     Vector2Int position,
     bool onlyAccessible = false)
 {
     return(AIUtils.GetNeighbours(position, _map, onlyAccessible));
 }
예제 #2
0
    public override void CollectDiscreteActionMasks(DiscreteActionMasker actionMasker)
    {
        List <AgentAction> disableActions = new List <AgentAction>()
        {
            AgentAction.Up,
            AgentAction.Right,
            AgentAction.Down,
            AgentAction.Left,
            AgentAction.Bomb
        };

        if (!_player.IsDead)
        {
            if (_isMoving)
            {
                // We only allow the same action (so direction) than the previous one
                disableActions.Remove(_previousAction);
                disableActions.Add(AgentAction.Nothing);
            }
            else if (_canTakeDecision)
            {
                // Check accessible cells around
                var cellPosition = _map.CellPosition(transform.position);
                var neighbours   = AIUtils.GetNeighbours(cellPosition, _map, true, true, false);

                foreach (var neighbourDirection in neighbours.Keys)
                {
                    switch (neighbourDirection)
                    {
                    case EDirection.None:
                        break;

                    case EDirection.Up:
                        disableActions.Remove(AgentAction.Up);
                        break;

                    case EDirection.Right:
                        disableActions.Remove(AgentAction.Right);
                        break;

                    case EDirection.Down:
                        disableActions.Remove(AgentAction.Down);
                        break;

                    case EDirection.Left:
                        disableActions.Remove(AgentAction.Left);
                        break;
                    }
                }

                // Only allow the agent to plant a bomb if he can
                if (_player.BombCount > 0)
                {
                    disableActions.Remove(AgentAction.Bomb);
                }
            }
        }

        int[] actionsMask = new int[disableActions.Count];

        for (int i = 0; i < disableActions.Count; i++)
        {
            actionsMask[i] = (int)disableActions[i];
        }

        actionMasker.SetMask(0, actionsMask);
    }