Esempio n. 1
0
        public void UpdateGame(GameTime gametime)
        {
            //Updates the player
            _player.Update(gametime, mBoard[(int)_player.PosX, _player.PosY]);
            this.gameInfo.SetStatus(_player.playerLoc);

            //Checks if a Transition was just made, if so prepares for the next transition
            if (boardTransition == false && _player.transition == false)
            {
                boardTransition = true;
            }
            screenTransition();
            //Checks if a player is between tiles, currently also manages if a player is moving into a tile that they would die in
            if (_player.isBetweenTiles())
            {
                try
                {
                    mBoard[(int)_player.DestinationX, _player.DestinationY]._explored = true;
                    if (entityMap[(int)_player.DestinationX, _player.DestinationY] != null && _player.goingToDie == false)
                    {
                        entityMap[(int)_player.DestinationX, _player.DestinationY].visible = true;
                        if (entityMap[(int)_player.DestinationX, _player.DestinationY].Kill == true)
                        {
                            _player.goingToDie = true;
                            if (entityMap[(int)_player.DestinationX, _player.DestinationY].ENTITY_ASSETNAME == "Wumpus")
                            {
                                _player.playerLog.Add("Player Killed by Wumpus!");
                            }
                            else
                            {
                                _player.playerLog.Add("Player killed by Pit!");
                            }
                            _player.listUpdated = true;
                            _player.Score       = 0;

                            // Record reward for Q learning & play again - DMC
                            if (QLearning)
                            {
                                EndGameCarryingGold = PlayerCarryingGold;
                                EndGameRewardState  = RewardState.PlayerDied;
                                EndGameAction       = LastAction;
                                EndGameX            = _player.PosX;
                                EndGameY            = _player.PosY;
                                currentRewardState  = RewardState.PlayerDied;
                                PlayAgain();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    _player.playerLog.Add("Error: " + ex.Message);
                }
            }

            //If the player fired an arrow, check which direction it was fired, then check if a wumpus was
            // within 5ish blocks in that direction (might make an infinite arrow range option later, on larger maps it could make searching
            // for many wumpus' more reasonable)
            if (_player.firedArrow == true)
            {
                if (_player.lastAction.CurrentCommand == Action.Command.ShootLeft)
                {
                    int check;
                    if (_player.PosX - 5 >= 0)
                    {
                        check = _player.PosX - 5;
                    }
                    else
                    {
                        check = 0;
                    }
                    for (int x = _player.PosX; x >= check; x--)
                    {
                        checkWumpus(x, true);
                    }
                }
                else if (_player.lastAction.CurrentCommand == Action.Command.ShootRight)
                {
                    int check;
                    if (_player.PosX + 5 <= boardX)
                    {
                        check = _player.PosX + 5;
                    }
                    else
                    {
                        check = boardX;
                    }
                    for (int x = _player.PosX; x < check; x++)
                    {
                        checkWumpus(x, true);
                    }
                }
                else if (_player.lastAction.CurrentCommand == Action.Command.ShootUp)
                {
                    int check;
                    if (_player.PosY - 5 >= 0)
                    {
                        check = _player.PosY - 5;
                    }
                    else
                    {
                        check = 0;
                    }
                    for (int y = _player.PosY; y >= check; y--)
                    {
                        checkWumpus(y, false);
                    }
                }
                else if (_player.lastAction.CurrentCommand == Action.Command.ShootDown)
                {
                    int check;
                    if (_player.PosY + 5 <= boardY)
                    {
                        check = _player.PosY + 5;
                    }
                    else
                    {
                        check = boardY;
                    }
                    for (int y = _player.PosY; y < boardY; y++)
                    {
                        checkWumpus(y, false);
                    }
                }
                _player.ArrowReset();
            }
            //If picking_up and there is treasure, pick it up
            if (_player.picking_up == true && entityMap[_player.PosX, _player.PosY] != null && entityMap[_player.PosX, _player.PosY].ENTITY_ASSETNAME == "Treasure")
            {
                entityMap[_player.PosX, _player.PosY] = null;
                _player.Score += boardX * boardY * 2;
                _player.playerLog.Add("Player picked up the Gold! +" + boardX * boardY * 2 + " Points");
                _player.listUpdated = true;

                // Record reward for Q learning - DMC
                if (QLearning)
                {
                    LastCarryingGold   = false;
                    currentRewardState = RewardState.PickedUpGold;
                }
            }
            // Record reward for Q learning - DMC
            else if (QLearning && _player.PosX == 0 && _player.PosY == (boardY - 1) && Game.Instance.PlayerCarryingGold)
            {
                _player.playerLog.Add("Player reached Base with GOLD! ");
                //  _player.listUpdated = true;
                currentRewardState = RewardState.FoundBaseWithGold;
                LastCarryingGold   = true;
            }
            else
            {
                _player.picking_up = false;

                // Record reward for Q learning - DMC
                if (QLearning)
                {
                    if (Game.Instance.GetTile(_player.PosX, _player.PosY)._gold&& entityMap[_player.PosX, _player.PosY] != null && !PlayerCarryingGold && currentRewardState == RewardState.Playing)
                    {
                        LastCarryingGold   = false;
                        currentRewardState = RewardState.FoundGold;
                    }
                    _player.playerLog.Add(currentRewardState.ToString());
                }
            }
            //If player is going to die, and they are at destination (wumpus or pit), Kill them
            if (_player.goingToDie == true && _player.DestinationX == _player.PosX && _player.DestinationY == _player.PosY)
            {
                _player.dead();

                // Record reward for Q learning - DMC
                if (QLearning)
                {
                    EndGameCarryingGold = PlayerCarryingGold;
                    EndGameRewardState  = RewardState.PlayerDied;
                    EndGameAction       = LastAction;
                    EndGameX            = _player.PosX;
                    EndGameY            = _player.PosY;
                    currentRewardState  = RewardState.PlayerDied;
                    _player.playerLog.Add(currentRewardState.ToString());
                }
            }
            //If player's score < 0 kill them
            if (_player.Score < 0)
            {
                _player.dead();
                _player.goingToDie = true;
                _player.playerLog.Add("Player Starved to Death!");
                _player.listUpdated = true;

                // Record reward for Q learning - DMC
                if (QLearning)
                {
                    // If you starve, don't apply the penalty to this action... just terminate the trial - DMC
                    currentRewardState = RewardState.Playing;
                    _player.playerLog.Add(currentRewardState.ToString());
                    PlayAgain();
                }
            }
            //Updates the List and score!
            if (_player.listUpdated == true)
            {
                gameInfo.UpdateList();
                gameInfo.UpdateScore(_player.Score);
                _player.listUpdated = false;
            }
            //Calculates the lighting
            calcLight();
        }
Esempio n. 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;
        }
Esempio n. 3
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;
        }