Beispiel #1
0
        /*
         * set up as follows:
         *
         * (x coord, y coord)
         *
         * -----------------
         * |(0,0)(1,0)(2,0)|
         * |(0,1)(1,1)(2,1)|
         * |(0,2)(1,2)(2,2)|
         * -----------------
         *
         * for legacy (access by passing int rather than point): //TODO make sure this isn't anywhere in the code
         *  |/ 1 /|
         *  |0 4 3|
         *  |/_2_/|
         *
         */

        public AntVision(FloorTile.TileType zerozero = FloorTile.TileType.Blank, FloorTile.TileType onezero = FloorTile.TileType.Blank, FloorTile.TileType twozero = FloorTile.TileType.Blank,
                         FloorTile.TileType zeroone  = FloorTile.TileType.Blank, FloorTile.TileType oneone  = FloorTile.TileType.Blank, FloorTile.TileType twoone  = FloorTile.TileType.Blank,
                         FloorTile.TileType zerotwo  = FloorTile.TileType.Blank, FloorTile.TileType onetwo  = FloorTile.TileType.Blank, FloorTile.TileType twotwo  = FloorTile.TileType.Blank,
                         List <Pheremone> phzerozero = null, List <Pheremone> phonezero = null, List <Pheremone> phtwozero = null,
                         List <Pheremone> phzeroone  = null, List <Pheremone> phoneone  = null, List <Pheremone> phtwoone  = null,
                         List <Pheremone> phzerotwo  = null, List <Pheremone> phonetwo  = null, List <Pheremone> phtwotwo  = null
                         )
        {
            _antVision[0, 0] = zerozero;
            _antVision[0, 1] = zeroone;
            _antVision[0, 2] = zerotwo;
            _antVision[1, 0] = onezero;
            _antVision[1, 1] = oneone;
            _antVision[1, 2] = onetwo;
            _antVision[2, 0] = twozero;
            _antVision[2, 1] = twoone;
            _antVision[2, 2] = twotwo;
            _antSmell[0, 0]  = phzerozero;
            _antSmell[0, 1]  = phzeroone;
            _antSmell[0, 2]  = phzerotwo;
            _antSmell[1, 0]  = phonezero;
            _antSmell[1, 1]  = phoneone;
            _antSmell[1, 2]  = phonetwo;
            _antSmell[2, 0]  = phtwozero;
            _antSmell[2, 1]  = phtwoone;
            _antSmell[2, 2]  = phtwotwo;
        }
Beispiel #2
0
 //OLD VERSION
 public AntVision(FloorTile.TileType zero, FloorTile.TileType one, FloorTile.TileType two, FloorTile.TileType three, FloorTile.TileType four)
 {
     _antVision[0, 0] = FloorTile.TileType.Null;
     _antVision[0, 1] = one;
     _antVision[0, 2] = FloorTile.TileType.Null;
     _antVision[1, 0] = zero;
     _antVision[1, 1] = four;
     _antVision[1, 2] = three;
     _antVision[2, 0] = FloorTile.TileType.Null;
     _antVision[2, 1] = two;
     _antVision[2, 2] = FloorTile.TileType.Null;
 }
Beispiel #3
0
        public bool IsTileWalkable(FloorTile.TileType tileType)
        {
            switch (tileType) //Use integer passed back from colour.ToArgb()
            {
            default:
            {
                return(true);
            }

            case (FloorTile.TileType.Null):
            {
                return(false);
            }

            case (FloorTile.TileType.Special):     //TODO - need to determine what a 'special' tile would be...
            {
                return(false);
            }
            }
        }
Beispiel #4
0
        public override Action Move(AntVision antVision) //TODO add in weighted randomisation for movement (weight based on tiles next to it) so like a goal is a higher weight.
        {
            /*
             * antVision is 3*3 bitmap.
             * tile setup is as follows (numbers refer to array index):
             * _____
             |0 3 6|
             |1 4 7| //4 is always walkable (unless code is very broken)
             |2_5_8|
             *
             */

            FloorTile.TileType best_tile = FloorTile.TileType.Blank;

            List <bool> walkable_tiles_list = new List <bool>();

            bool[] walkable_tiles;

            int random_int = 0;

            for (int x_count = 0; x_count < 3; x_count++) //TODO change this... //what to?
            {
                for (int y_count = 0; y_count < 3; y_count++)
                {
                    walkable_tiles_list.Add(IsTileWalkable(antVision._antVision[x_count, y_count]));
                }
            }

            //walkable_tiles_list.Add(true); //here to allow the ant to stay still (and to do things with the tile it is standing on)
            walkable_tiles = walkable_tiles_list.ToArray(); //TODO redo this function to allow for preference of direction.

            do
            {
                random_int = _random.Next(walkable_tiles.Length);
            } while (random_int % 2 == 0 || walkable_tiles_list[random_int] == false);

            switch (random_int)
            {
            case (1):
            {
                _location.X += -1;
                break;
            }

            case (3):
            {
                _location.Y += -1;
                break;
            }

            case (5):
            {
                _location.Y += 1;
                break;
            }

            case (7):
            {
                _location.X += 1;
                break;
            }
            }

            if (carrying_gold)
            {
                if (antVision._antVision[1, 1] == FloorTile.TileType.Home)
                {
                    //-TODO pass ant_vision as array of FloorTile. Pass by reference to allow for ant editing tiles.
                    //TODO increment home tile.
                    carrying_gold = false;

                    return(Action.None);
                }

                return(Action.DropPheremone);
            }
            else if (antVision._antVision[1, 1] == FloorTile.TileType.Goal)
            {
                carrying_gold = true;
            }

            return(Action.None);
        }
        public void Step(int steps = 1)
        {
            for (int count = 0; count < steps; count++)
            {
                _gameBoard.Step(1);                         //TODO use events

                foreach (Ant ant in _ants)                  //TODO Events?
                {
                    Point initial_location = ant._location; //TODO this doesn't show pheremones to the ants.

                    //TODO set all tiles here so if it's a null then we can sort it.
                    FloorTile.TileType zerozero   = FloorTile.TileType.Null;
                    FloorTile.TileType zeroone    = FloorTile.TileType.Null;
                    FloorTile.TileType zerotwo    = FloorTile.TileType.Null;
                    FloorTile.TileType onezero    = FloorTile.TileType.Null;
                    FloorTile.TileType oneone     = FloorTile.TileType.Null;
                    FloorTile.TileType onetwo     = FloorTile.TileType.Null;
                    FloorTile.TileType twozero    = FloorTile.TileType.Null;
                    FloorTile.TileType twoone     = FloorTile.TileType.Null;
                    FloorTile.TileType twotwo     = FloorTile.TileType.Null;
                    List <Pheremone>   phzerozero = new List <Pheremone>();
                    List <Pheremone>   phzeroone  = new List <Pheremone>();
                    List <Pheremone>   phzerotwo  = new List <Pheremone>();
                    List <Pheremone>   phonezero  = new List <Pheremone>();
                    List <Pheremone>   phoneone   = new List <Pheremone>();
                    List <Pheremone>   phonetwo   = new List <Pheremone>();
                    List <Pheremone>   phtwozero  = new List <Pheremone>();
                    List <Pheremone>   phtwoone   = new List <Pheremone>();
                    List <Pheremone>   phtwotwo   = new List <Pheremone>();

                    try
                    {
                        zerozero   = _gameBoard.GetTileAtLocation(initial_location.X - 1, initial_location.Y - 1).GetTileType();
                        phzerozero = _gameBoard.GetPheremonesAtLocation(initial_location.X - 1, initial_location.Y - 1);
                    }
                    catch (Exception e)
                    { }
                    try
                    {
                        zeroone   = _gameBoard.GetTileAtLocation(initial_location.X - 1, initial_location.Y).GetTileType();
                        phzeroone = _gameBoard.GetPheremonesAtLocation(initial_location.X - 1, initial_location.Y);
                    }
                    catch (Exception e)
                    { }
                    try
                    {
                        zerotwo   = _gameBoard.GetTileAtLocation(initial_location.X - 1, initial_location.Y + 1).GetTileType();
                        phzerotwo = _gameBoard.GetPheremonesAtLocation(initial_location.X - 1, initial_location.Y + 1);
                    }
                    catch (Exception e)
                    { }
                    try
                    {
                        onezero   = _gameBoard.GetTileAtLocation(initial_location.X, initial_location.Y - 1).GetTileType();
                        phonezero = _gameBoard.GetPheremonesAtLocation(initial_location.X, initial_location.Y - 1);
                    }
                    catch (Exception e)
                    { }
                    try
                    {
                        oneone   = _gameBoard.GetTileAtLocation(initial_location.X, initial_location.Y).GetTileType();
                        phoneone = _gameBoard.GetPheremonesAtLocation(initial_location.X, initial_location.Y);
                    }
                    catch (Exception e)
                    { }
                    try
                    {
                        onetwo   = _gameBoard.GetTileAtLocation(initial_location.X, initial_location.Y + 1).GetTileType();
                        phonetwo = _gameBoard.GetPheremonesAtLocation(initial_location.X, initial_location.Y + 1);
                    }
                    catch (Exception e)
                    { }
                    try
                    {
                        twozero   = _gameBoard.GetTileAtLocation(initial_location.X + 1, initial_location.Y - 1).GetTileType();
                        phtwozero = _gameBoard.GetPheremonesAtLocation(initial_location.X + 1, initial_location.Y - 1);
                    }
                    catch (Exception e)
                    { }
                    try
                    {
                        twoone   = _gameBoard.GetTileAtLocation(initial_location.X + 1, initial_location.Y).GetTileType();
                        phtwoone = _gameBoard.GetPheremonesAtLocation(initial_location.X + 1, initial_location.Y);
                    }
                    catch (Exception e)
                    { }
                    try
                    {
                        twotwo   = _gameBoard.GetTileAtLocation(initial_location.X + 1, initial_location.Y + 1).GetTileType();
                        phtwotwo = _gameBoard.GetPheremonesAtLocation(initial_location.X + 1, initial_location.Y + 1);
                    }
                    catch (Exception e)
                    { }

                    AntVision ant_vision = new AntVision( //TODO add pheremone detection here...
                        zerozero, onezero, twozero,
                        zeroone, oneone, twoone,
                        zerotwo, onetwo, twotwo,
                        phzerozero, phonezero, phtwozero,
                        phzeroone, phoneone, phtwoone,
                        phzerotwo, phonetwo, phtwotwo
                        );

                    Ant.Action ant_action = ant.Move(ant_vision);

                    switch (ant_action) //REMEMBER all actions are done to PREVIOUS tile
                    {
                    default:
                    {
                        break;
                    }

                    case (Ant.Action.DropPheremone):
                    {
                        Pheremone ph = new Pheremone(this, initial_location, 255, 0.5);
                        _gameBoard.addPheremone(ph);
                        break;
                    }
                    }
                }
            }

            OnBoardStep(new GameBoardSteppedEventArgs(DrawWholeGameBoard(_gameBoard)));
        }