Пример #1
0
    protected override void Control(float delta)
    {
        if (PathEnd != Vector2.Zero && PathEndDistance > PathDistanceDeadband)
        {
            // update the path mover script
            pathMover.Call("update_acceleration", delta);
            Velocity = (Vector2)(pathMover.Get("velocity"));
            float angularVelocity = (float)(pathMover.Get("angular_velocity"));
            Rotation += angularVelocity * delta;
        }
        else
        {
            Path     = new Vector2[] { };
            Velocity = Vector2.Zero;
        }

        if (State == States.Idle)
        {
            if (Hopper.HasBalls)
            {
                machine.Fire(Triggers.Score);
            }
            else
            {
                machine.Fire(Triggers.PickupBalls);
            }
        }
        else if (State == States.DrivingToPickup)
        {
            // we ran out of room, go score
            if (!Hopper.HasRoom)
            {
                machine.Fire(Triggers.Score);
            }
        }
        else if (State == States.Shoot && !Hopper.HasBalls)
        {
            machine.Fire(Triggers.PickupBalls);
        }
        else if (State == States.Pickup && Hopper.HasBalls)
        {
            machine.Fire(Triggers.Score);
        }
    }
Пример #2
0
 private void SpawnPieces()
 {
     for (int x = 0; x < width; x++)
     {
         for (int y = 0; y < height; y++)
         {
             int    piece_idx = 0;
             int    loops     = 0;
             Node2D piece     = null;
             do
             {
                 if (++loops == 100)
                 {
                     break;
                 }
                 piece_idx = (int)Math.Floor(GD.RandRange(0, PossiblePieces.Length));
                 piece     = (Node2D)PossiblePieces[piece_idx].Instance();
             } while (MatchAt(x, y, (String)piece.Get("colour")));
             piece.Position = GridToPixel(new Vector2i(x, y));
             AddChild(piece);
             AllPieces[x, y] = piece;
         }
     }
 }
    public void think()
    {
        ClosestFriend = get_friends_informaion();

        ClosestFoe = get_foe_informaion();

        Enviroment = get_evironment_information();

        ClosestFriend2 = sort_distance(ClosestFriend);

        #if DebugA
        GD.Print("Network input Objects");
        GD.Print(ClosestFriend);
        GD.Print(ClosestFoe);
        GD.Print(Enviroment);
        GD.Print(ClosestFriend2);
        GD.Print(ClosestFoe[0].Position);
        GD.Print(ClosestFoe[0].Position.x);
        GD.Print(ClosestFoe[0].Position.y);
        #endif

        #if DebugB
        GD.Print("+++ClosestFrient+++");
        GD.Print(ClosestFriend);
        GD.Print("---ClosestFrient2---");
        GD.Print(ClosestFriend2);
        #endif


        data_in[0] = ClosestFoe[0].Position.x;
        data_in[1] = ClosestFoe[0].Position.y;
        data_in[2] = ClosestFoe[1].Position.x;
        data_in[3] = ClosestFoe[1].Position.y;
        data_in[4] = ClosestFoe[2].Position.x;
        data_in[5] = ClosestFoe[2].Position.y;
        data_in[6] = ClosestFriend[0].Position.x;
        data_in[7] = ClosestFriend[0].Position.y;
        data_in[8] = ClosestFriend[1].Position.x;
        data_in[9] = ClosestFriend[1].Position.y;
        //data_in[10] = ClosestFriend[2].Position.x;
        //data_in[11] = ClosestFriend[2].Position.y;
        data_in[12] = Enviroment[0].Position.x;
        data_in[13] = Enviroment[0].Position.y;
        data_in[14] = Enviroment[1].Position.x;
        data_in[15] = Enviroment[1].Position.y;
        data_in[16] = Enviroment[2].Position.x;
        data_in[17] = Enviroment[2].Position.y;

        FirstData.Inputs[0] = ClosestFoe[0].Position.x;

        #if (DebugA)
        MyString = "";
        foreach (double Anumber in data_in)
        {
            MyString += Anumber.ToString() + ",";
        }
        GD.Print("Objects Position Data");
        GD.Print(MyString);
        #endif

        normalize(data_in);
        MoveShootNet.ApplyInput(data_in);
        MoveShootNet.CalculateOutput();
        data_out2 = MoveShootNet.ReadOutput();
        data_out2 = denormalize(data_out2);



        data_out = new double[] { data_in[0], data_in[1], data_in[0], data_in[1] };
        //normalize(data_out);

        Training = new NeuralNetworks.DataSet {
            Outputs = data_out, Inputs = data_in
        };
        //Training = new NeuralNetworks.DataSet() {(double[]) data_out2, Inputs = data_in };
        TrainingData.Add(Training);

        #if DebugA
        MyString = "";
        foreach (double Anumber in data_out2)
        {
            MyString += Anumber.ToString() + ",";
        }
        GD.Print("Output of Network");
        GD.Print(MyString);


        //data_out = (double[]) data_out2;
        GD.Print("Has Current Move ", Parent.Get("CurrentMove"));
        GD.Print("Has Side ", Parent.Get("Side"));
        #endif

        Acount = 0;
        foreach (double Anumber in data_out2)
        {
            data_out3[Acount] = (float)Anumber;
            Acount++;
        }



        Parent.Set("CurrentMove", Parent.ToLocal(new Godot.Vector2(data_out3[2], data_out3[3])));
        Parent.Set("CurrentTarget", new Godot.Vector2(data_out3[0], data_out3[1]));
    }