Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            RessourceLoad.InitMap();

            Console.WriteLine(TestScore());
            // Feel free to use all the function below in order to train your players
        }
Exemplo n.º 2
0
        protected override void Update(GameTime gameTime)
        {
            Console.Write("\r\r\r\r\r\r" + P1.GetScore() + "        ");

            if (_manualMode)
            {
                P1.ReceiveOrder(Keyboard.GetState().IsKeyDown(Keys.Left), Keyboard.GetState().IsKeyDown(Keys.Right),
                                Keyboard.GetState().IsKeyDown(Keys.Up), Keyboard.GetState().IsKeyDown(Keys.R));
            }
            else
            {
                P1.PlayAFrame();
            }

            //game
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||
                Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            if (Keyboard.GetState().IsKeyDown(Keys.F))
            {
                graphics.ToggleFullScreen();
            }

            int FrameNb = RessourceLoad.GetCurrentMap().Timeout;

            _currentFrame++;
            if (_currentFrame > FrameNb)
            {
                Exit();
            }
            base.Update(gameTime);
        }
Exemplo n.º 3
0
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
            _spriteBatch.Begin();
            // init
            _appearances_dico["tiles.png"].DisplayMap(_spriteBatch, RessourceLoad.GetCurrentMap(), P1.Position);

            String spriteToLoad = "";

            switch (P1.lastDir)
            {
            case Player.Direction.left:
                spriteToLoad = "Aelita move left.png";
                break;

            case Player.Direction.right:
                spriteToLoad = "Aelita move right.png";
                break;

            case Player.Direction.none:
                spriteToLoad = "Aelita idle.png";
                break;
            }

            _appearances_dico[spriteToLoad].DisplayAppearance(_spriteBatch,
                                                              P1.Position.X * RessourceLoad.GetCurrentMap().Width, P1.Position.Y * WindowCellHeight);
            Thread.Sleep(30);
            //end
            _spriteBatch.End();
            base.Draw(gameTime);
        }
Exemplo n.º 4
0
        // Students will not use that

        /*
         *
         * private static void MultiTrain(int nb, bool mutations)
         * {
         *  Factory.SetPathLoadAndSave(PathForTest);
         *  Factory.Init();
         *  Factory.TrainAllMaps(nb, mutations);
         *  Factory.PrintScore();
         *  Factory.SaveState();
         * }
         */

        public static float TestScore()
        {
            Assert.AreEqual(true, File.Exists(PathBotToSubmit));

            Factory.SetListPlayer(SaveAndLoad.Load(PathBotToSubmit));
            var ply = Factory.GetBestPlayer();
            int sum = 0;

            foreach (var tuple in RessourceLoad.MapGet())
            {
                RessourceLoad.SetCurrentMap(tuple.Key);
                int FrameNb = RessourceLoad.GetCurrentMap().Timeout;
                ply.ResetScore();
                ply.SetStart(RessourceLoad.GetCurrentMap());
                for (int j = 0; j < FrameNb; j++)
                {
                    ply.PlayAFrame();
                }
                sum += ply.GetScore();

                ply.SetStart(RessourceLoad.GetCurrentMap());
            }
            float result = (float)sum / 45000;

            if (result < 0)
            {
                result = 0;
            }
            else if (result > 1)
            {
                result = 1;
            }
            return(result);
        }
Exemplo n.º 5
0
 protected override void Initialize()
 {
     if (P1 is null)
     {
         throw new Exception("Missing player in game !");
     }
     RessourceLoad.SetApperance(graphics, ref _appearances_dico);
     base.Initialize();
 }
Exemplo n.º 6
0
        /// <summary>
        /// This function allows you to try the game
        /// </summary>
        private static void PlayAsHuman()
        {
            Game1  game   = new Game1();
            Player player = new Player();

            player.SetStart(RessourceLoad.GetCurrentMap());
            game.SetPlayer(player, true);
            game.Run();
        }
Exemplo n.º 7
0
/*
 *      private static void TrainMt(int n)
 *      {
 *          Factory.SetPathLoadAndSave(PathForTest);
 *          Factory.Init();
 *          Factory.TrainMt(n);
 *          Factory.PrintScore();
 *          Factory.SaveState();
 *      }
 *
 *      private static void NewTrainMt(int n)
 *      {
 *          Factory.SetPathLoadAndSave(PathForTest);
 *          Factory.Init();
 *          Factory.TrainMt(n, false);
 *          Factory.PrintScore();
 *          Factory.SaveState();
 *      }*/

        /// <summary>
        /// Show the current best player
        /// </summary>
        private static void Showbest()
        {
            Game1 game = new Game1();

            Factory.SetPathLoadAndSave(PathForTest);
            Factory.Init();
            Factory.GetBestPlayer().SetStart(RessourceLoad.GetCurrentMap());
            game.SetPlayer(Factory.GetBestPlayer());
            game.Run();
        }
Exemplo n.º 8
0
 public static void PrintScore(bool extended = false)
 {
     SimpleSort();
     for (int i = 0; i < _listPlayer.Count; i++)
     {
         Console.WriteLine("Player " + i + " has a score of " + _listPlayer[i].GetScore());
         if (extended)
         {
             _listPlayer[i].SetStart(RessourceLoad.GetCurrentMap());
             var plop = _listPlayer[i].UseBrain(RessourceLoad.GetCurrentMap()
                                                .GetMapAround(_listPlayer[i].Position.X, _listPlayer[i].Position.Y));
             plop.Print();
         }
     }
 }
Exemplo n.º 9
0
        public static void Train(int generationNumber, bool replaceWithMutation = true)
        {
            int FrameNb = RessourceLoad.GetCurrentMap().Timeout;

            for (int i = 0; i < generationNumber; i++)
            {
                // Console.WriteLine("\nTraining " + (i + 1) + "/" + generationNumber);
                for (int k = 0; k < _listPlayer.Count; k++)
                {
                    // Console.Write("\r\r\r\r\r\r" + k * 100 / _listPlayer.Count + "%    ");
                    _listPlayer[k].ResetScore();
                    _listPlayer[k].SetStart(RessourceLoad.GetCurrentMap());
                    for (int j = 0; j < FrameNb; j++)
                    {
                        _listPlayer[k].PlayAFrame();
                    }
                    _listPlayer[k].SetStart(RessourceLoad.GetCurrentMap());

                    //   Console.Write("\r\r\r\r\r\rDONE.");
                }

                Regenerate(replaceWithMutation);
            }
        }