예제 #1
0
        public static void PlayPong()
        {
            Q_Learning player1 = new Q_Learning(0.8, 0, 3, 0);
            Q_Learning player2 = new Q_Learning(0.8, 0, 3, 0);

            for (int i = 0; i < 120000; ++i)
            {
                int p1 = player1.Get_SetAction(Pong.GetState1(), Pong.punktePlayer1);
                int p2 = player2.Get_SetAction(Pong.GetState2(), Pong.punktePlayer2);



                Pong.punktePlayer1 = 0;
                Pong.punktePlayer2 = 0;

                Pong.Play(p1, p2);
                //System.Threading.Thread.Sleep(20);
            }
            while (true)
            {
                int p1 = player1.Get_SetAction(Pong.GetState1(), Pong.punktePlayer1);
                int p2 = player2.Get_SetAction(Pong.GetState2(), Pong.punktePlayer2);



                Pong.punktePlayer1 = 0;
                Pong.punktePlayer2 = 0;

                Pong.Play(p1, p2);
                //Pong.DrawMap();
                System.Threading.Thread.Sleep(20);
            }
        }
예제 #2
0
        public static void Q_Learning_Tetris()
        {
            int        lauf = 0;
            Q_Learning Q    = new Q_Learning(0.9, 0.2, 5, 3);

            while (true)
            {
                Tetris.TetrisSetup();
                Tetris.MapAktualisieren(true);

                while (Tetris.leben)
                {
                    double[] b = new double[5];
                    //Tetris.CheckLocher(18);
                    if (Tetris.punkte <= -300)
                    {
                        Tetris.leben = false;
                    }

                    Tetris.GetPunkteFurFastFolleReihe(5, 19, 18);
                    b[Q.Get_SetAction(Tetris.GetReihe(19, 18), Tetris.punkte)] = 1;
                    Console.SetCursorPosition(0, 0);
                    Console.WriteLine("Punkte: {0}", Tetris.punkte);


                    Tetris.punkte = 0;
                    Tetris.BewegungShow(b, 0.5);
                    System.Threading.Thread.Sleep(15);
                }
                Q.Get_SetAction(Tetris.GetReihe(19, 18), -500);
                Tetris.AllesReset();
                Console.Clear();
                ++lauf;

                //if(lauf%100==0)
                //    Serialize(Q, @"C:\Users\Gregor\Ki\Q_LearningTable_1.bin");
            }
        }
예제 #3
0
        public static void SimplesSpielStart()
        {
            Q_Learning Tim3 = new Q_Learning(0.96, 0.1, 4, 0);

            SimplesSpiel.Setup(5, 5, 0, 1);
            int       action;
            SimpleNet Prediction = new SimpleNet(4, 29, 30, 25);

            Prediction.SetAfNames(AF.Linear, AF.Sigmoid, AF.Sigmoid);
            Prediction.SetAfT(1, 1);
            Prediction.SetAfT(2, 1);

            for (int i = 0; i < 100000; ++i)
            {
                double[] arrAckt = new double[4];

                if (SimplesSpiel.punkte == 0 && i > 0)
                {
                    Prediction.DeltawertBerechen((double[])SimplesSpiel.GetMap().Clone());
                    Prediction.Backpropagation();
                }


                action = Tim3.Get_SetAction(SimplesSpiel.GetPlayerPos(), SimplesSpiel.punkte);

                arrAckt[action] = 1;
                if (SimplesSpiel.punkte == 0)
                {
                    Prediction.SetInput(arrAckt.Concat(SimplesSpiel.GetMap()).ToArray());
                }
                Prediction.OutputBerechnen();

                SimplesSpiel.punkte = 0;
                SimplesSpiel.PlayerBewegen(action);
                SimplesSpiel.ExtraMapAusgeben(Prediction.GetOutput());


                //System.Threading.Thread.Sleep(10);
            }

            for (int i = 0; i < 5000; ++i)
            {
                action = Tim3.Get_SetAction(SimplesSpiel.GetPlayerPos(), SimplesSpiel.punkte);
                SimplesSpiel.punkte = 0;
                SimplesSpiel.PlayerBewegen(action);
                System.Threading.Thread.Sleep(100);
            }

            Console.ResetColor();
            while (true)
            {
                Console.SetCursorPosition(14, 0);
                Console.Write("  ");
                Console.SetCursorPosition(14, 1);
                Console.Write("  ");
                Console.SetCursorPosition(0, 0);
                Console.Write("X-Koordinate: ");
                sbyte x = Convert.ToSByte(Console.ReadLine());
                Console.Write("Y-Koordinate: ");
                sbyte y = Convert.ToSByte(Console.ReadLine());

                Q_State state = Tim3.Q_Table[new SimplesSpiel.SimplPos(x, y)];

                Console.SetCursorPosition(40, 4);
                Console.Write(Math.Round(state.actionReward[1]) + "    ");

                Console.SetCursorPosition(50, 4);
                Console.Write(Math.Round(state.actionReward[0]) + "    ");

                Console.SetCursorPosition(45, 1);
                Console.Write(Math.Round(state.actionReward[2]) + "    ");

                Console.SetCursorPosition(45, 7);
                Console.Write(Math.Round(state.actionReward[3]) + "    ");
            }
        }