Beispiel #1
0
        public Visualizer(BasePacman pacman = null)
        {
            InitializeComponent();
            KeyDown           += new KeyEventHandler(keyDownHandler);
            Picture.MouseDown += new MouseEventHandler(mouseDownHandler);
            Picture.MouseMove += new MouseEventHandler(mouseMoveHandler);
            // load images
            sprites = Util.LoadImage("sprites.png");
            // initialize graphics
            image = new Bitmap(Picture.Width, Picture.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            g     = Graphics.FromImage(image);
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
            //g.ScaleTransform(2.0f, 2.0f);
            gameState = new GameState();

            this.Width  = gameState.Map.PixelWidth + 7;            // screenplayer test
            this.Height = gameState.Map.PixelHeight + 49;          // screenplayer test
            //gameState.PacmanMortal = false;
            gameState.StartPlay();
            gameState.GameOver += new EventHandler(gameOverHandler);

            if (pacman != null)
            {
                controller           = pacman;
                gameState.Controller = pacman;
            }

            // IMPORTANT SETTINGS AREA //
            // try load controller
            //tryLoadController("SmartDijkstraPac");
            // load stream
            // tryLoadStream("best22030");
            // start timer ( must always be the last to be started! )

            int myData = 0;             // dummy data

            tickHandler = new TimerEventHandler(tick);
            fastTimer   = timeSetEvent(50, 50, tickHandler, ref myData, 1);

            /*gameState.Ghosts[1].Enabled = false;
            *  gameState.Ghosts[2].Enabled = false;
            *  gameState.Ghosts[3].Enabled = false;*/
        }
Beispiel #2
0
        public Visualizer(string Agent, string AgentFile)
        {
            InitializeComponent();
            KeyDown           += new KeyEventHandler(keyDownHandler);
            Picture.MouseDown += new MouseEventHandler(mouseDownHandler);
            Picture.MouseMove += new MouseEventHandler(mouseMoveHandler);
            // load images
            sprites = Util.LoadImage("sprites.png");
            // initialize graphics
            image = new Bitmap(Picture.Width, Picture.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            g     = Graphics.FromImage(image);
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
            //g.ScaleTransform(2.0f, 2.0f);
            // gamestate
            gameState   = new GameState();
            this.Width  = gameState.Map.PixelWidth + 7;            // screenplayer test
            this.Height = gameState.Map.PixelHeight + 49;          // screenplayer test
            //gameState.PacmanMortal = false;
            gameState.StartPlay();
            gameState.GameOver += new EventHandler(gameOverHandler);

            // IMPORTANT SETTINGS AREA //
            //tryLoadController("LucPac");

            //gameState.Controller = tryLoadController("LucPac");


            //gameState.Controller = tryLoadNNController("MMPac", NNValues);

            this.AgentFile = AgentFile;

            if (Agent == "")
            {
                Console.WriteLine("Choose an AI agent to control Pacman:");
                Console.WriteLine(" 1 - LucPacScripted");
                Console.WriteLine(" 2 - LucPac (MCTS)");
                Console.WriteLine(" 3 - MMLocPac (Evolved Neural Network) from .nn file");
                Console.WriteLine(" 4 - MMLocPacMemory (Evolved Neural Network) from .nn file");
                Console.WriteLine(" 5 - SimRandom");
                Console.WriteLine(" 6 - UncertainAgent");
                Console.WriteLine(" 7 - LucPacMCTS2");

                Selection = int.Parse(Console.ReadKey().KeyChar.ToString());
            }
            else
            {
                Selection = int.Parse(Agent);
            }

            gameState.Controller = GetResetController();

            //gameState.Controller = tryLoadNNController("MMPac", "NeuralNetwork.nn");
            //gameState.Controller = tryLoadController("LucPacScripted");

            //
            //
            //gameState.Controller = new MMMCTS();

            //gameState.Controller = new MMPac.MMPac(NNValues);
            //((MMPac.MMPac)gameState.Controller).SaveWeights("NeuralNetwork.nn");

            //
            //controller = gameState.Controller;

            int myData = 0; // dummy data

            tickHandler = new TimerEventHandler(tick);
            fastTimer   = timeSetEvent(50, 50, tickHandler, ref myData, 1);
            //
        }