public StudentSnake(Color headColor, Color bodyColor,
                     int brainHeight, int brainWidth,
                     int initY, int initX, uint initSize) :
     base(headColor, bodyColor, initY, initX, initSize)
 {
     Studying = true;
     Brain    = new BrainBase(brainHeight, brainWidth);
 }
 public void ChangeTemplateBrainType(BrainType newBrainType)
 {
     if(brainType != newBrainType) { // only do something if the brainType has changed
         brainType = newBrainType;
         templateBrain = null;
         templateBrain = new BrainBase();
         // Test Type (manual coded brain)
         if(brainType == BrainType.Test) {
             templateBrain = new BrainTest();
         }
         // ANN Feed-Forward Layered Static All-to-All:
         if(brainType == BrainType.ANN_FF_Layered_AllToAll) {
             templateBrain = new BrainANN_FF_Layers_A2A();
         }
     }
 }
        public void TimeoutChangesStateToFollower()
        {
            var brain          = new BrainBase(new RobotBase(new DefaultEnvironment(new Map(10, 10))));
            var decoratedState = new IdleState();
            var followerState  = new IdleState();
            var state          = new TimeoutStateDecorator(decoratedState, 3, followerState);

            brain.CurrentState = state;
            Assert.Equal(state, brain.CurrentState);
            state.Tick();
            Assert.Equal(state, brain.CurrentState);
            state.Tick();
            Assert.Equal(state, brain.CurrentState);
            state.Tick();
            Assert.Equal(followerState, brain.CurrentState);
            state.Tick();
        }
        public override void Update(Field gameField, IEnumerable <SnakeBase> otherSnakes)
        {
            --CurrentEnergy;
            base.Update(gameField, otherSnakes);

            if (CurrentEnergy <= EnergyToDie)
            {
                base.Die();
                return;
            }

            if (CurrentEnergy >= EnergyToCreate)
            {
                int          size             = Body.Count / 2;
                List <Point> newBodyPositions = Body.Skip(size).Select(bs => bs.Position).ToList();

                Body.RemoveRange(size, Body.Count - size);
                BrainBase newBrain = new BrainBase(Brain);

                Random random    = new Random();
                int    mutations = random.Next(1, 5);

                for (int i = 0; i < mutations; ++i)
                {
                    newBrain.RandomMutation();
                }

                newBodyPositions.Reverse();
                DividingStudentSnake newSnake = new DividingStudentSnake(
                    HeadColor, newBodyPositions.First(), newBodyPositions.Skip(1), newBrain,
                    CurrentEnergy / 2, EnergyToCreate, EnergyToDie, EnergyPerFood
                    );

                ++TotalCreated;
                CurrentEnergy /= 2;
                OnDevide?.Invoke(this, new SnakeCreatedEventArgs(newSnake));
            }
        }
 public virtual void CopyBrainSettingsFrom(BrainBase sourceBrain)
 {
 }
Exemple #6
0
 public Result(BrainBase brain, int score, int produced)
 {
     Brain    = brain;
     Score    = score;
     Produced = produced;
 }
    /*
    // Run the network forwards to produce output values
    public void Run(ref float[] input, out float[] output)
    {
        // Make sure we have enough data
        if (input.Length != inputSize)
            throw new ArgumentException("Input data is not of the correct dimension.");

        //Dimension
        output = new float[layerSize[layerCount - 1]];  // set output size to that of last layer (output)

        // Run the network!
        for (int l = 0; l < layerCount; l++)
        {
            for (int j = 0; j < layerSize[l]; j++)  // for each node in the current layer l,
            {
                float sum = 0.0f;
                for (int i = 0; i < (l == 0 ? inputSize : layerSize[l - 1]); i++)  // for each node in the previous layer l-1,
                    sum += weight[l][i][j] * (l == 0 ? input[i] : layerOutput[l - 1][i]);  // sum for that node is the sum of all inputs multiplied by weights from previous layer

                sum += bias[l][j];  // add bias value to this node
                layerInput[l][j] = sum;  // store layerInput values for this layer

                layerOutput[l][j] = TransferFunctions.Evaluate(transferFunctions[l][j], sum); // pass the sum into the transferFunction for that layer
            }
        }

        //Copy the output to the output array
        for (int i = 0; i < layerSize[layerCount - 1]; i++)
            output[i] = layerOutput[layerCount - 1][i];
    }
    */
    public override void CopyBrainSettingsFrom(BrainBase sourceBrain)
    {
    }
    /*
     * // Run the network forwards to produce output values
     * public void Run(ref float[] input, out float[] output)
     * {
     *      // Make sure we have enough data
     *      if (input.Length != inputSize)
     *              throw new ArgumentException("Input data is not of the correct dimension.");
     *
     *      //Dimension
     *      output = new float[layerSize[layerCount - 1]];  // set output size to that of last layer (output)
     *
     *      // Run the network!
     *      for (int l = 0; l < layerCount; l++)
     *      {
     *              for (int j = 0; j < layerSize[l]; j++)  // for each node in the current layer l,
     *              {
     *                      float sum = 0.0f;
     *                      for (int i = 0; i < (l == 0 ? inputSize : layerSize[l - 1]); i++)  // for each node in the previous layer l-1,
     *                              sum += weight[l][i][j] * (l == 0 ? input[i] : layerOutput[l - 1][i]);  // sum for that node is the sum of all inputs multiplied by weights from previous layer
     *
     *                      sum += bias[l][j];  // add bias value to this node
     *                      layerInput[l][j] = sum;  // store layerInput values for this layer
     *
     *                      layerOutput[l][j] = TransferFunctions.Evaluate(transferFunctions[l][j], sum); // pass the sum into the transferFunction for that layer
     *              }
     *      }
     *
     *      //Copy the output to the output array
     *      for (int i = 0; i < layerSize[layerCount - 1]; i++)
     *              output[i] = layerOutput[layerCount - 1][i];
     * }
     */


    public override void CopyBrainSettingsFrom(BrainBase sourceBrain)
    {
    }
 public StudentSnake(Color headColor, Color bodyColor,
                     Point head, IEnumerable <Point> body,
                     BrainBase brain) : base(headColor, bodyColor, head, body) => Brain = brain;
        private DividingStudentSnake(Color headColor, Point head, IEnumerable <Point> body, BrainBase brain, int initEnegry, int energyToCreate,
                                     int energyToDie, int energyPerFood) : base(headColor, GetRandomColor(), head, body, brain)
        {
            CurrentEnergy  = initEnegry;
            EnergyToCreate = energyToCreate;
            EnergyToDie    = energyToDie;
            EnergyPerFood  = energyPerFood;

            OnEat += DividingStudentSnake_OnEat;
        }
Exemple #11
0
 private void Start()
 {
     m_brain = GetComponent <BrainBase>();
     m_body  = GetComponent <BodyAISimple>();
     m_agent = GetComponent <NavMeshAgent>();
 }
 protected void Init()
 {
     m_brain   = GetComponent <BrainBase>();
     m_job     = GetComponent <JobBase>();
     m_homePos = base.transform.position;
 }
Exemple #13
0
 public virtual void CopyBrainSettingsFrom(BrainBase sourceBrain)
 {
 }
Exemple #14
0
 protected void Init()
 {
     m_brain = GetComponent <BrainBase>();
     m_body  = GetComponent <BodyBase>();
 }