Example #1
0
    public List <GameObject> GetMoveFields(BoardManager.TileType type)
    {
        BoardManager board = BoardManager.Instance;

        List <GameObject> moveFields = new List <GameObject>();

        GameObject unitPos = board.GetPositionOfUnit(unit);

        if (unit.Movement == Unit.MovementType.Forward)
        {
            if (unit.IsPlayerControlled)
            {
                moveFields = board.GetForwardFields(unitPos, unit.MovementRange);
            }
            else
            {
                moveFields = board.GetForwardFields(unitPos, -unit.MovementRange);
            }
        }

        if (unit.Movement == Unit.MovementType.Side)
        {
            moveFields = board.GetOrthogonalFields(unitPos, unit.MovementRange, type, true);
        }

        if (unit.Movement == Unit.MovementType.Orthogonal)
        {
            moveFields = board.GetOrthogonalFields(unitPos, unit.MovementRange, type, false);
        }

        if (unit.Movement == Unit.MovementType.Diagonal)
        {
            moveFields = board.GetDiagonalFields(unitPos, unit.MovementRange, type);
        }

        if (unit.Movement == Unit.MovementType.Knight)
        {
            moveFields = board.GetKnightFields(unitPos);
        }

        if (unit.Movement == Unit.MovementType.All)
        {
            moveFields = board.GetOrthogonalFields(unitPos, unit.MovementRange, type, false)
                         .Concat(board.GetDiagonalFields(unitPos, unit.MovementRange, type)).ToList();
        }

        return(moveFields);
    }
Example #2
0
    // ACTION METHOD: Returns the main steering vector to accomplish this action,
    // allong with setting this.action to null and updating insistances when the
    // action is finished
    public Vector2 seekTile(BoardManager.TileType tileType, SmellType smellType)
    {
        Vector2 goalSteering = new Vector2(-1, -1);

        // If we've seen the tile and stored its location, just arrive at the tile
        // (If we don't have a target to arrive at the vector is (-1, -1))
        if (this.target.x >= 0 && this.target.y >= 0)
        {
            goalSteering = arriveAt(new Vector2(this.target.x * CELL_SIZE, this.target.y * CELL_SIZE));

            // If we have arrived at the target, the agent should execute the action
            BoardManager.TileType currentCellType =
                GameManager.instance.getBoardArray()[(int)currentCell.x, (int)currentCell.y];
            if (this.target.x == this.currentCell.x && this.target.y == this.currentCell.y ||
                currentCellType == BoardManager.TileType.Water)
            {
                this.goal.apply(this.insistance);
                this.goal   = null;
                this.target = new Vector2(-1, -1);
            }
        }
        else
        {
            // If we haven't seen tile yet, check if we see one
            // Check if within 3 blocks of the tile (represents the agent seeing the tile and going)
            Vector2 closeTile = getCloseTile(tileType, 3, currentCell, GameManager.instance.getBoardArray());
            if (closeTile.x >= 0 && closeTile.y >= 0)
            {
                this.target  = closeTile;
                goalSteering = arriveAt(new Vector2(closeTile.x * CELL_SIZE, closeTile.y * CELL_SIZE));
            }
            else
            {
                // If we still can't see a bush, just follow the smell
                goalSteering = directionOfSmell(currentCell,
                                                GameManager.instance.getSmellArray(), smellType) * MAX_ACCEL;
            }
        }

        return(goalSteering);
    }
Example #3
0
    // Return the location of the first object of the given tile type within the given
    // distance of the location
    public Vector2 getCloseTile(BoardManager.TileType type, int distance,
                                Vector2 currentCell, BoardManager.TileType[, ] boardArray)
    {
        for (int xOffset = -distance; xOffset < distance + 1; xOffset++)
        {
            for (int yOffset = -distance; yOffset < distance + 1; yOffset++)
            {
                int curX = (int)currentCell.x + xOffset;
                int curY = (int)currentCell.y + yOffset;
                if (curX >= 0 && curX < GameManager.SIZE && curY >= 0 && curY < GameManager.SIZE)
                {
                    if (boardArray[curX, curY] == type)
                    {
                        return(new Vector2(curX, curY));
                    }
                }
            }
        }

        // If we didn't find any tiles of the given type, return "dummy" vector (-1, -1)
        return(new Vector2(-1, -1));
    }
Example #4
0
    public List <GameObject> GetAttackTiles(GameObject startField, bool getOccupiedOnly, BoardManager.TileType type)
    {
        BoardManager      board        = BoardManager.Instance;
        List <GameObject> attackFields = new List <GameObject>();


        if (unit.Type == Unit.UnitType.Grunt || unit.Type == Unit.UnitType.Drone)
        {
            attackFields = board.GetDiagonalFields(startField, unit.AttackRange, type);
        }

        if (unit.Type == Unit.UnitType.Jumpship || unit.Type == Unit.UnitType.Tank)
        {
            attackFields = board.GetOrthogonalFields(startField, unit.AttackRange, type, false);
        }

        if (unit.Type == Unit.UnitType.Dreadnought)
        {
            attackFields = board.GetOrthogonalFields(startField, unit.AttackRange, type, false)
                           .Concat(board.GetDiagonalFields(startField, unit.AttackRange, type)).ToList();
        }

        if (getOccupiedOnly)
        {
            attackFields = attackFields.Where(i => BoardManager.Instance.OccupiedFieldsDict[i] != null &&
                                              BoardManager.Instance.OccupiedFieldsDict[i].IsPlayerControlled != unit.IsPlayerControlled).ToList();
        }

        return(attackFields);
    }