Example #1
0
        public void UpdatePanelOnMouse()
        {
            Vector2 p   = Camera.main.ScreenToWorldPoint(new Vector2(Input.mousePosition.x, Input.mousePosition.y));
            NVector pos = new NVector((int)p.x, (int)p.y, GameMgmt.Get().newMap.view.ActiveLevel);

            Debug.Log($"Click on {pos}");

            if (!pos.Valid())
            {
                NAudio.PlayBuzzer();
                return;
            }

            //active action?
            if (_action != null)
            {
                _action.Click(pos);
            }
            else
            {
                UpdatePanel(pos);
            }

            //center mouse?
            if (LSys.tem.options["centermouse"].Bool())
            {
                S.CameraMove().MoveTo(pos);
            }
        }
Example #2
0
        //Todo combine with action explore
        private void MoveToPos(Player player, UnitInfo unit, NVector pos, ActionHolder holder)
        {
            DataUnit dUnit = unit.dataUnit;
            NVector  dPos  = new NVector(holder.data["pos"]);
            //go to this field
            List <PPoint> points = S.Map().PathFinding(pos.level).Path(player, dUnit.movement, pos, dPos);

            foreach (PPoint pp in points)
            {
                NVector p = new NVector(pp.x, pp.y, pos.level);
                //free field?
                if (!S.Unit().Free(p))
                {
                    unit.SetLastInfo($"Can not explore the world, path {p} is blocked.");
                    return;
                }

                //not enough cost?
                var terr = S.Map().Terrain(pos);
                if (S.Map().PathFinding(pos.level).CostNode(player, dUnit.movement, pos) > dUnit.ap)
                {
                    return;
                }

                //explore terrain
                player.fog.Clear(pos);

                //move their
                unit.MoveTo(p, true);
            }

            holder.data.Remove("pos");
            unit.SetRepeatAction(null);
        }
Example #3
0
        private bool FindPos(Player player, UnitInfo unit, NVector pos, ActionHolder holder)
        {
            if (holder.data.ContainsKey("pos"))
            {
                return(true);
            }
            DataUnit dUnit = unit.dataUnit;

            //find next field
            foreach (var p in CircleGenerator.Gen(pos, unit.data.apMax / 5 * 2))
            {
                if (AddGoal(unit, holder, p))
                {
                    return(true);
                }
            }

            //has nothing?
            //search the whole map
            for (int x = 0; x < GameMgmt.Get().data.map.width; x++)
            {
                for (int y = 0; y < GameMgmt.Get().data.map.height; y++)
                {
                    if (AddGoal(unit, holder, new NVector(x, y, pos.level)))
                    {
                        return(true);
                    }
                }
            }

            //has a field?
            unit.SetLastInfo(S.T("actionRepeatErrorDestination", holder.DataAction().Name()));
            unit.SetWaitingAction(null);
            return(false);
        }
Example #4
0
      /// <summary/>
      public override NVector Compute(NVector input) {
         var count = OutputLayer.Neurons.Count;
         var result = new NVector(count);

         var sum = input.Sum();
         for (int i = 0; i < count; i++) {
            result[i] = sum;
         }

         return result;
      }
Example #5
0
      /// <summary/>
      public override NVector Compute(NVector input) {
         var count = OutputLayer.Neurons.Count;
         var result = new NVector(count);

         for (int i = 0; i < count; i++) {
            var sum = 0.0;
            for (int j = 0; j < input.Count; j++) {
               sum += input[j] * WeightMatrix[j, i];
            }
            result[i] = sum;
         }

         return result;
      }
Example #6
0
      private void _compute(NeuralOutputHolder holder, NeuralLayer layer, NVector input, Synapse source) {
         PreProcessLayer(layer, input, source);

         foreach (var synapse in layer.OutputSynapses) {
            if (!holder.Results.ContainsKey(synapse)) {
               var nextLayer = synapse.OutputLayer;
               var pattern = synapse.Compute(input);
               pattern = synapse.OutputLayer.Compute(pattern);
               synapse.OutputLayer.Process(pattern);
               holder.Results[synapse] = input;
               _compute(holder, synapse.OutputLayer, pattern, synapse);

               if (nextLayer == Network.OutputLayer) {
                  holder.Output = pattern;
               }
            }
         }
      }
Example #7
0
 /// <summary>Can be overridden by subclasses. Usually used to implement recurrent layers.</summary>
 public virtual void PreProcessLayer(NeuralLayer layer, NVector input, Synapse source) {
 }
Example #8
0
 /// <summary/>
 public override NVector Compute(NVector input) {
    var holder = new NeuralOutputHolder();
    _compute(holder, Network.InputLayer, input, null);
    return holder.Output;
 }
Example #9
0
 /// <summary>Computes the output for the associated neural network.</summary>
 /// <param name="input">The input to the network.</param>
 /// <returns>The output from the network.</returns>
 public abstract NVector Compute(NVector input);
Example #10
0
 /// <summary>Applies the deriative of the activation function over the given data (the data is modified in-place).</summary>
 /// <param name="data">The input data to the activation function deriative.</param>
 /// <remarks>Propagation training requires the derivative. Some activation functions do not support a derivative and will throw an error.</remarks>
 public abstract void ComputeDeriative(NVector data);
Example #11
0
 /// <summary>Applies the activation function over the given data (the data is modified in-place).</summary>
 /// <param name="data">The input data to the activation function.</param>
 public abstract void Compute(NVector data);
Example #12
0
 /// <summary/>
 public override NVector Compute(NVector input) {
    return input;
 }