Пример #1
0
        public void checkSenses()
        {
            leftEyeSense [0]  = 0.0;
            leftEyeSense [1]  = 0.0;
            leftEyeSense [2]  = 0.0;
            rightEyeSense [0] = 0.0;
            rightEyeSense [1] = 0.0;
            rightEyeSense [2] = 0.0;
            pressure          = 0;

            double leftAngle  = DudeMath.wrapPi(spacials.angle - eyeAngle);
            double rightAngle = DudeMath.wrapPi(spacials.angle + eyeAngle);

            foreach (var thingy in Thing.things)
            {
                if (thingy.id == this.id)
                {
                    continue;
                }

                double angleBetweenDudes = Math.Atan2(spacials.pos.X - thingy.spacials.pos.X, spacials.pos.Y - thingy.spacials.pos.Y);

                double dist = (spacials.pos - thingy.spacials.pos).Length;
                pressure += dist * thingy.spacials.mass;               //See tanh later, just taking advantage of this expensive number

                double leftEyeDifference  = DudeMath.aDiff(leftAngle, angleBetweenDudes);
                double rightEyeDifference = DudeMath.aDiff(rightAngle, angleBetweenDudes);

                if ((leftEyeDifference > -focus / 2) && (leftEyeDifference < focus / 2))
                {
                    leftEyeSense[0] += 16 * (thingy.red / dist);
                    leftEyeSense[1] += 16 * (thingy.green / dist);
                    leftEyeSense[2] += 16 * (thingy.blue / dist);
                }
                if ((rightEyeDifference > -focus / 2) && (rightEyeDifference < focus / 2))
                {
                    rightEyeSense[0] += 16 * (thingy.red / dist);
                    rightEyeSense[1] += 16 * (thingy.green / dist);
                    rightEyeSense[2] += 16 * (thingy.blue / dist);
                }

                leftEyeSense[0]  = Math.Tanh(leftEyeSense[0]);
                leftEyeSense[1]  = Math.Tanh(leftEyeSense[1]);
                leftEyeSense[2]  = Math.Tanh(leftEyeSense[2]);
                rightEyeSense[0] = Math.Tanh(rightEyeSense[0]);
                rightEyeSense[1] = Math.Tanh(rightEyeSense[1]);
                rightEyeSense[2] = Math.Tanh(rightEyeSense[2]);

//				leftEyePos.X = pd.x + Math.Sin (leftAngle) * 4;
//				leftEyePos.Y = pd.y + Math.Cos (leftAngle) * 4;
//				rightEyePos.X = pd.x + Math.Sin (leftAngle) * 4;
//				rightEyePos.Y = pd.y + Math.Cos (leftAngle) * 4;
            }

            pressure = Math.Tanh(pressure);             //Squish it down
        }
Пример #2
0
        public void act()
        {
            energy = DudeMath.constrain(energy + world.energy, 0, 1);
            charge = DudeMath.constrain(charge + world.charge, 0, 1);
            //eyeAngle = DudeMath.constrain(eyeAngle + (outs[(int)nnOutputs.eyeAngle] * 0.01), 0, 2);
            //focus = DudeMath.map (outs [(int)nnOutputs.eyeAngle], -1, 1, 0, 2);
            red   = DudeMath.map(outs [(int)nnOutputs.colorR], -1, 1, 0, 1);
            green = DudeMath.map(outs [(int)nnOutputs.colorG], -1, 1, 0, 1);
            blue  = DudeMath.map(outs [(int)nnOutputs.colorB], -1, 1, 0, 1);
//			red = 1;
//			green = 0;
//			blue = 0;
        }
Пример #3
0
        public Dude()
        {
            double r = world.radius;

            Vector point = new Vector(DudeMath.map(random.NextDouble(), 0, 1, -r, r),
                                      DudeMath.map(random.NextDouble(), 0, 1, -r, r));

            while ((point - spacials.pos).Length > world.radius)
            {
                point = new Vector(DudeMath.map(random.NextDouble(), 0, 1, -r, r),
                                   DudeMath.map(random.NextDouble(), 0, 1, -r, r));
            }

            spacials.angle = DudeMath.map(random.NextDouble(), 0, 1, -Math.PI, Math.PI);

            teleport(point);
        }
Пример #4
0
        public void doThrusters()
        {
            thrusters[0, 0] = DudeMath.wrapPi(thrusters[0, 0] + (outs[(int)nnOutputs.thrusterA0] * 0.1));
            thrusters[1, 0] = DudeMath.wrapPi(thrusters[1, 0] + (outs[(int)nnOutputs.thrusterA1] * 0.1));
            thrusters[2, 0] = DudeMath.wrapPi(thrusters[2, 0] + (outs[(int)nnOutputs.thrusterA2] * 0.1));
            thrusters[3, 0] = DudeMath.wrapPi(thrusters[3, 0] + (outs[(int)nnOutputs.thrusterA3] * 0.1));


            thrusters[0, 1] = DudeMath.map(outs [(int)nnOutputs.thrusterT0], -1, 1, 0, 1);
            thrusters[1, 1] = DudeMath.map(outs [(int)nnOutputs.thrusterT1], -1, 1, 0, 1);
            thrusters[2, 1] = DudeMath.map(outs [(int)nnOutputs.thrusterT2], -1, 1, 0, 1);
            thrusters[3, 1] = DudeMath.map(outs [(int)nnOutputs.thrusterT3], -1, 1, 0, 1);


            for (int i = 0; i < 4; i++)
            {
                //double angle = DudeMath.wrapPi (spacials.angle + thrusters [i,0]);

                //spacials.pos.X += Math.Sin (angle) * thrusters[i,1] * 1;
                //spacials.pos.Y += Math.Cos (angle) * thrusters[i,1] * 1;
            }
        }