Beispiel #1
0
        public void ReLoadGame()
        {
            //Loads Font
            header1 = _content.Load<SpriteFont>("Header1");

            //Loads the Player
            if (IsSmartTrial) { _player = new Player(boardY - 1, SCREEN, 160); }  // should reference default player speed - DMC
            else { _player = new Player(boardY - 1, SCREEN, FAST_SPEED); }
            _player.LoadContent(_content);

            //Load Game Control
            // gameInfo = new GameControl();
            gameInfo.setSeed(settingMenu.seed);
            gameInfo.SetOutputList(_player.playerLog);
            gameInfo.UpdateScore(_player.Score);
            gameInfo.SetStatus("");
            gameInfo.SetLearningTrialDisplay(gameCounter, QLearningTrials, QLearning, winCounter);
            gameInfo.Show();

            //Loads the Board
            Sprite mRoom = new Sprite();
            bool visible = settingMenu.allVisible;
            bool autoPlay = settingMenu.autoPlay;
            Random rand = new Random(settingMenu.seed);

            //Gets the # of pits, wumpus, and gold
            //  double pitLow = (((double)boardX * (double)boardY) / 100) * settingMenu.pitLower;
            // double pitHigh = (((double)boardX * (double)boardY) / 100) * settingMenu.pitHigher;

            // Get the original count
            int pits = originalPits.Count;
            int wumpus = originalWumpi.Count;
            int gold = originalGold.Count;

            bool top = false;
            bool bottom = false;
            bool left = false;
            bool right = false;

            //Prepares the tiles
            for (int x = 0; x < boardX; x++)
            {
                for (int y = 0; y < boardY; y++)
                {
                    string _resource;
                    if (x == 0 & y == 0)
                    {
                        _resource = "RoomTileLeftTop";
                        left = true;
                        top = true;
                        bottom = false;
                        right = false;
                    }
                    else if (x == 0 & y == boardY - 1)
                    {
                        _resource = "RoomTileLeftBot";
                        bottom = true;
                        left = true;
                        right = false;
                        top = false;
                    }
                    else if (x == boardX - 1 && y == 0)
                    {
                        _resource = "RoomTileRightTop";
                        right = true;
                        top = true;
                        left = false;
                        bottom = false;
                    }
                    else if (x == boardX - 1 && y == boardY - 1)
                    {
                        _resource = "RoomTileRightBot";
                        right = true;
                        bottom = true;
                        left = false;
                        top = false;
                    }
                    else if (x == 0)
                    {
                        _resource = "RoomTileLeft";
                        left = true;
                        top = false;
                        bottom = false;
                        right = false;

                    }
                    else if (y == 0)
                    {
                        _resource = "RoomTileTop";
                        top = true;
                        bottom = false;
                        left = false;
                        right = false;

                    }
                    else if (y == boardY - 1)
                    {
                        _resource = "RoomTileBot";
                        bottom = true;
                        top = false;
                        left = false;
                        right = false;

                    }
                    else if (x == boardX - 1)
                    {
                        _resource = "RoomTileRight";
                        right = true;
                        top = false;
                        bottom = false;
                        left = false;

                    }
                    else
                    {
                        _resource = "RoomTile";
                        top = false;
                        bottom = false;
                        left = false;
                        right = false;
                    }
                    mBoard[x, y] = new Tile(x, y, visible, top, bottom, right, left);
                    mBoard[x, y].LoadContent(_content, _resource);
                    if (y == boardY - 1 && x == 0)
                    {
                        mBoard[x, y]._explored = true;
                    }
                }
            }

            //Prepares the Pits
            while (pits != 0)
            {
                int x = originalPits[pits - 1].X;
                int y = originalPits[pits - 1].Y;

                EntityPit ep = new EntityPit(x, y, visible);
                ep.LoadContent(_content);
                entityMap[x, y] = ep;
                if (x - 1 >= 0) mBoard[x - 1, y]._breeze = true;
                if (y - 1 >= 0) mBoard[x, y - 1]._breeze = true;
                if (x + 1 < boardX) mBoard[x + 1, y]._breeze = true;
                if (y + 1 < boardY) mBoard[x, y + 1]._breeze = true;
                pits--;

            }

            //Prepares the Gold
            while (gold != 0)
            {
                int x = originalGold[gold - 1].X;
                int y = originalGold[gold - 1].Y;

                EntityGold eg = new EntityGold(x, y, visible);
                eg.LoadContent(_content);
                entityMap[x, y] = eg;
                mBoard[x, y]._gold = true;  // added for agents
                gold--;

            }
            //Prepares the Wumpus
            while (wumpus != 0)
            {
                int x = originalWumpi[wumpus - 1].X;
                int y = originalWumpi[wumpus - 1].Y;

                EntityWumpus ep = new EntityWumpus(x, y, visible);
                ep.LoadContent(_content);
                entityMap[x, y] = ep;
                if (x - 1 >= 0) mBoard[x - 1, y]._stench = true;
                if (y - 1 >= 0) mBoard[x, y - 1]._stench = true;
                if (x + 1 < boardX) mBoard[x + 1, y]._stench = true;
                if (y + 1 < boardY) mBoard[x, y + 1]._stench = true;
                wumpus--;

            }
            // sets the base  - DMC
            mBoard[0, 4].IsBase = true;

            // Set the reward state to not carrying gold (needed to know which Q tables to use)
            PlayerCarryingGold = false;
               // LastAction.CurrentCommand = Action.Command.None;
        }
Beispiel #2
0
        public void LoadGame()
        {
            if (QLearning) { SetupQLearning(); } // added for Q learning....... // DMC

            //Loads Font
            header1 = _content.Load<SpriteFont>("Header1");

            //Loads the Player
            if (QLearning) { _player = new Player(boardY - 1, SCREEN, FAST_SPEED); }   // fast for QLearning  - DMC
            else { _player = new Player(boardY - 1, SCREEN); } // else regular speed & DStar by default- DMC
            _player.LoadContent(_content);

            //Load Game Control
            gameInfo = new GameControl();
            gameInfo.setSeed(settingMenu.seed);
            gameInfo.SetOutputList(_player.playerLog);
            gameInfo.UpdateScore(_player.Score);
            gameInfo.SetStatus("");
            if (QLearning) { gameInfo.SetLearningTrialDisplay(gameCounter, QLearningTrials, QLearning, winCounter); }  // added Q Learning display
            gameInfo.Show();

            //Loads the Board
            Sprite mRoom = new Sprite();
            bool visible = settingMenu.allVisible;
            bool autoPlay = settingMenu.autoPlay;
            Random rand = new Random(settingMenu.seed);

            //Gets the # of pits, wumpus, and gold
            double pitLow = (((double)boardX * (double)boardY) / 100) * settingMenu.pitLower;
            double pitHigh = (((double)boardX * (double)boardY) / 100) * settingMenu.pitHigher;
            int pits = rand.Next((int)pitLow, (int)pitHigh);
            int wumpus = settingMenu.wumpus;
            int gold = settingMenu.gold;

            bool top = false;
            bool bottom = false;
            bool left = false;
            bool right = false;
            //Prepares the tiles
            for (int x = 0; x < boardX; x++)
            {
                for (int y = 0; y < boardY; y++)
                {
                    string _resource;
                    if (x == 0 & y == 0)
                    {
                        _resource = "RoomTileLeftTop";
                        left = true;
                        top = true;
                        bottom = false;
                        right = false;
                    }
                    else if (x == 0 & y == boardY - 1)
                    {
                        _resource = "RoomTileLeftBot";
                        bottom = true;
                        left = true;
                        right = false;
                        top = false;
                    }
                    else if (x == boardX - 1 && y == 0)
                    {
                        _resource = "RoomTileRightTop";
                        right = true;
                        top = true;
                        left = false;
                        bottom = false;
                    }
                    else if (x == boardX - 1 && y == boardY - 1)
                    {
                        _resource = "RoomTileRightBot";
                        right = true;
                        bottom = true;
                        left = false;
                        top = false;
                    }
                    else if (x == 0)
                    {
                        _resource = "RoomTileLeft";
                        left = true;
                        top = false;
                        bottom = false;
                        right = false;

                    }
                    else if (y == 0)
                    {
                        _resource = "RoomTileTop";
                        top = true;
                        bottom = false;
                        left = false;
                        right = false;

                    }
                    else if (y == boardY - 1)
                    {
                        _resource = "RoomTileBot";
                        bottom = true;
                        top = false;
                        left = false;
                        right = false;

                    }
                    else if (x == boardX - 1)
                    {
                        _resource = "RoomTileRight";
                        right = true;
                        top = false;
                        bottom = false;
                        left = false;

                    }
                    else
                    {
                        _resource = "RoomTile";
                        top = false;
                        bottom = false;
                        left = false;
                        right = false;
                    }
                    mBoard[x, y] = new Tile(x, y, visible, top, bottom, right, left);
                    mBoard[x, y].LoadContent(_content, _resource);
                    if (y == boardY - 1 && x == 0)
                    {
                        mBoard[x, y]._explored = true;
                    }
                }
            }

            //Prepares the Pits
            while (pits != 0)
            {
                int x = rand.Next(0, boardX);
                int y = rand.Next(0, boardY);
                if (entityMap[x, y] == null && !(x == 0 && y == boardY - 1))
                {
                    EntityPit ep = new EntityPit(x, y, visible);
                    ep.LoadContent(_content);
                    entityMap[x, y] = ep;
                    if (x - 1 >= 0) mBoard[x - 1, y]._breeze = true;
                    if (y - 1 >= 0) mBoard[x, y - 1]._breeze = true;
                    if (x + 1 < boardX) mBoard[x + 1, y]._breeze = true;
                    if (y + 1 < boardY) mBoard[x, y + 1]._breeze = true;
                    pits--;
                    if (QLearning) { originalPits.Add(new Point(x, y)); }// record pits for repeated trials - DMC
                }
            }

            //Prepares the Gold
            while (gold != 0)
            {
                int x = rand.Next(0, boardX);
                int y = rand.Next(0, boardY);
                if (entityMap[x, y] == null && !(x == 0 && y == boardY - 1))
                {
                    EntityGold eg = new EntityGold(x, y, visible);
                    eg.LoadContent(_content);
                    entityMap[x, y] = eg;
                    mBoard[x, y]._gold = true;
                    gold--;
                    if (QLearning) { originalGold.Add(new Point(x, y)); } // record gold for repeated trials - DMC
                }
            }

            //Prepares the Wumpus
            while (wumpus != 0)
            {
                int x = rand.Next(0, boardX);
                int y = rand.Next(0, boardY);
                if (entityMap[x, y] == null && !(x == 0 && y == boardY - 1))
                {
                    EntityWumpus ep = new EntityWumpus(x, y, visible);
                    ep.LoadContent(_content);
                    entityMap[x, y] = ep;
                    if (x - 1 >= 0) mBoard[x - 1, y]._stench = true;
                    if (y - 1 >= 0) mBoard[x, y - 1]._stench = true;
                    if (x + 1 < boardX) mBoard[x + 1, y]._stench = true;
                    if (y + 1 < boardY) mBoard[x, y + 1]._stench = true;
                    wumpus--;
                    if (QLearning) { originalWumpi.Add(new Point(x, y)); }// record wumpi for repeated trials - DMC
                }
            }

            // sets the base  - DMC
            mBoard[0, 4].IsBase = true;
        }