Пример #1
0
    private void Start()
    {
        InitializeTileSystem();

        foodSpawnPoints.Lock();

        //InitializeManualTT();
        //var outer = new twinrect(0, 0, 20-1, 18-1);
        //outer.DoEach(cell => { Sett(cell, 1); });
        //var inner = outer;
        //inner.min += twin.one;
        //inner.max -= twin.one;
        //inner.DoEach(cell => {

        //    Sett(cell, 0);

        //    if (Random.value < .1f)
        //    {
        //        banks["food"].Spawn<MazeBody>(GetEntLot("food")).Setup(master, cell);
        //    }
        //    else if (Random.value < .05f)
        //    {
        //        banks["bigfood"].Spawn<MazeBody>(GetEntLot("food")).Setup(master, cell);
        //    }
        //    else if (Random.value < .04f)
        //    {
        //        banks["eater"].Spawn<MazeBody>(GetEntLot("guts")).Setup(master, cell);
        //    }

        //});

        //banks["player"].Spawn<MazeBody>(GetEntLot("player")).Setup(master, new twin(10, 8));
    }
Пример #2
0
    void PickAMove()
    {
        var moves = new ChoiceStack <twin>();

        moves.AddManyThenLock(twin.compass);
        moves.RemoveAll(-bfm.lastMove);
        moves.Add(-bfm.lastMove);
        moves.Lock(shuffle: false);
        twin iMoved = moves.GetFirstTrue(bfm.TryMove);

        if (iMoved == twin.zero)
        {
            bfm.facingDir = twin.compass[Random.Range(0, 4)];
        }

        bfm.UpdateHelper_FaceFacingDir();
    }
Пример #3
0
    public void TryDWMove()
    {
        twin.StraightenCompass();
        ChoiceStack <twin> directions = new ChoiceStack <twin>();

        if (lastMove.taxicabLength == 2)
        {
            directions.AddManyThenLock(
                new twin(lastMove.x, 0),
                new twin(0, lastMove.y),
                lastMove); // prefer to continue in your weird diagonal direction.
        }
        bool open_space = false;

        for (int i = 0; i < 4; i++)
        {
            var dira = twin.compass[i];
            var dirb = twin.compass[(i + 1) % 4];
            if ((dira == lastMove || dirb == lastMove) &&
                CanMoveTo(my_cell_pos + dira) &&
                CanMoveTo(my_cell_pos + dirb) &&
                CanMoveTo(my_cell_pos + dira + dirb))
            {
                directions.Add(dira + dirb);
                open_space = true; // moving through an open space.
            }
        }
        if (open_space)
        {
            directions.Add(lastMove);             // in an open space, i can continue in the same direction.
        }
        directions.Lock();

        directions.AddManyThenLock(twin.compass);

        directions.RemoveAll(-lastMove);

        lastMove = directions.GetFirstTrue(TryMove);
    }
Пример #4
0
    public twin?GetRandomFreeCell(System.Func <twin, bool> cellVerifier)
    {
        var freeCells = new ChoiceStack <twin>();

        new twinrect(twin.zero, new twin(32, 32) - twin.one).DoEach(cell =>
        {
            if (!IsSolidTile(cell) && cellVerifier(cell))
            {
                freeCells.Add(cell);
            }
        });
        freeCells.Lock(shuffle: true);
        var freeCell = freeCells.GetFirstTrue(cell => { return(true); }, defaultValue: twin.one *-1000);

        if (freeCell == twin.one * -1000)
        {
            return(null);
        }
        else
        {
            return(freeCell);
        }
    }
Пример #5
0
        private void FixedUpdate()
        {
            if (IsWithinDistOfCentered(fullSpeedDist, offset: subtileOffset))
            {
                var agents = 0;

                // what's in this cell?
                foreach (var agent in board.GetAgentsAt(my_cell_pos))
                {
                    agents++;
                    if (agent is BaFoodSource)
                    {
                        if (pathNestToFood.Contains(this.my_cell_pos))
                        {
                            // only take food if i know how to get back home with it.

                            ((BaFoodSource)agent).TakeFood();
                            isCarryingFood = true;
                            isWandering    = false;
                            isGoingHome    = true;
                            frustration    = 0;
                        }

                        Dj.Tempf("Ant found food. Path has length {0}", this.pathNestToFood.Count);
                        SnapMyCellPos();
                    }
                    if (agent is BaNeonNest)
                    {
                        this.homeNest = (BaNeonNest)agent;
                        if (isCarryingFood)
                        {
                            this.homeNest.ReceiveFood();
                            isCarryingFood = false;
                        }

                        isGoingHome = false;

                        if (frustration > 100 + this.maxPathLength)
                        {
                            isWandering = true;
                        }

                        frustration = 0;

                        if (isWandering)
                        {
                            this.maxPathLength += Random.Range(1, 3 + 1); // try a longer path
                            this.pathNestToFood.Clear();
                            this.pathNestToFood.Add(my_cell_pos);
                        }

                        SnapMyCellPos();
                    }
                }

                bool do_wander = false;

                var on_path_index = pathNestToFood.IndexOf(my_cell_pos);
                if (isGoingHome && on_path_index > 0 && pathNestToFood.Count > 0 && TryMove(pathNestToFood[on_path_index - 1] - my_cell_pos))
                {
                    // ok, followed path!
                }
                else if (!isGoingHome && on_path_index >= 0 && on_path_index < pathNestToFood.Count - 1 && TryMove(pathNestToFood[on_path_index + 1] - my_cell_pos))
                {
                    // ok, followed path!
                }
                else
                {
                    do_wander = true;
                }

                if (!isCarryingFood && pathNestToFood.Count > 0 && my_cell_pos == pathNestToFood[pathNestToFood.Count - 1])
                {
                    frustration = 1000;
                }

                if (do_wander)
                {
                    ChoiceStack <twin> dirs = new ChoiceStack <twin>();
                    if (!isWandering)
                    {
                        // always prefer cells on the path!
                        foreach (var dir in twin.compass)
                        {
                            if (pathNestToFood.Contains(my_cell_pos + dir))
                            {
                                dirs.Add(dir);
                            }
                        }
                        dirs.Lock();
                    }
                    // move like a ghost.
                    List <twin> forward_compass = new List <twin>(twin.compass);
                    forward_compass.Remove(-lastMove);
                    dirs.AddManyThenLock(forward_compass);
                    lastMove = dirs.GetFirstTrue(TryMove);
                }
            }
            else
            {
                SetVelocityApproachTarget();
                GetComponent <SpriteRenderer>().flipX = body.velocity.x < 0;

                if (bodyStuckFrames > 20)
                {
                    frustration++;
                    if (!isCarryingFood && frustration > 20)
                    {
                        isGoingHome = true;
                    }
                    bodyStuckFrames = 0;
                    SnapMyCellPos(); RandomizeSubtileOffset();
                    if (Random.value < (isGoingHome?.75f : .25f))
                    {
                        TryMove(-lastMove);
                    }
                }
            }

            if (isCarryingFood)
            {
                GetComponent <BitsyAni>().spriteIds = new int[] { 54, 55, };
                GetComponent <BitsyAni>().speed     = 0.087f;
            }
            else
            {
                GetComponent <BitsyAni>().spriteIds = new int[] { 52, 53, };
                GetComponent <BitsyAni>().speed     = 0.050f;
            }
        }