//helper function for getting brain input
        private double [] GetInputFromDirection(Vector2 Direction)
        {
            double [] returnInfo     = new double [3];
            Vector2   SearchPosition = HeadPosition;
            int       distance       = 1;
            bool      foundFood      = false;
            bool      foundBody      = false;

            //Search in the direction until you exit game area
            while (IsInsideGameArea(SearchPosition += Direction))
            {
                distance++;
                //if food is found return info about it
                if (!foundFood && SearchPosition == CurrentFoodUnit.Location())
                {
                    returnInfo [0] = 1;
                    foundFood      = true;
                }
                //if bodypart is found, return info about it
                if (!foundBody && WillEatBody(SearchPosition))
                {
                    returnInfo [1] = 1 / distance;
                    foundBody      = true;
                }
            }
            //after reaching the wall return info about it
            returnInfo [2] = 1 / distance;

            return(returnInfo);
        }
Example #2
0
        void MoveByOne()
        {
            Vector2 Velocity = BaseVelocity * VelocityModifier;

            NewHeadPosition = HeadPosition + Velocity;

            if (!isDead && WillDie(NewHeadPosition))
            {
                Die();
            }

            if (Configerator.instance.GameType == Configerator.Game.player)
            {
                Item potentialItem = Item.FindItem(NewHeadPosition);
                if (potentialItem != null)
                {
                    potentialItem.UseItem(this);
                }
            }
            else if (!isDead && NewHeadPosition == CurrentFoodUnit.Location())
            {
                CurrentFoodUnit.UseItem(this);
            }


            ModifyLength(NewHeadPosition);
        }
Example #3
0
        //pomocna funkcija za jest
        private void Eat(Food food, Vector2 NewHeadPosition)
        {
            CurrentFoodUnit = Food.CreateNewFoodUnit();

            //if the food spawned on the snake, spawn it again
            while (BodyParts.Contains(CurrentFoodUnit.Location()) ||
                   HeadPosition == CurrentFoodUnit.Location() ||
                   NewHeadPosition == CurrentFoodUnit.Location())
            {
                CurrentFoodUnit = Food.CreateNewFoodUnit();
            }

            //increase time left before starvation
            timeLeft += 100;

            //ALL HAIL MAGIC NUMBERS!!!!
            if (isTested || length > 10)
            {
                TimesToGrow += 4;
            }
            else
            {
                TimesToGrow += 1;
            }
        }
Example #4
0
        //napravi izracunati potez
        public void Move()
        {
            age++; timeLeft--;
            if (timeLeft == 0)
            {
                isDead = true;
            }

            Vector2 Velocity        = baseVelocity * VelocityModifier;
            Vector2 NewHeadPosition = HeadPosition + Velocity;

            if (WillDie(NewHeadPosition))
            {
                isDead = true;
            }

            if (NewHeadPosition == CurrentFoodUnit.Location())
            {
                Eat(CurrentFoodUnit, NewHeadPosition);
            }

            //if snake needs to grow don't remove the last body part
            if (TimesToGrow > 0)
            {
                TimesToGrow--;
                Vector2 newBodyPart = new Vector2(HeadPosition); //old head possition becomes new bodyPart
                BodyParts.Enqueue(newBodyPart);                  //add to bodyParts old head possition
                HeadPosition = NewHeadPosition;                  //update head possition
                length++;
            }
            else
            {
                Vector2 newBodyPart = new Vector2(HeadPosition); //old head possition becomes new bodyPart
                BodyParts.Dequeue();                             //remove the last bodyPart
                BodyParts.Enqueue(newBodyPart);                  //add to bodyParts old head possition
                HeadPosition = NewHeadPosition;                  //update head possition
            }
        }