コード例 #1
0
        private static void AddGameStateToList(InterpretedGameState interpretedGameState, ref List <InterpretedGameState> allGameStatesPossible, Point item, int number)
        {
            GameState clonedState2 = (GameState)interpretedGameState.GameState.Clone();

            clonedState2.SpawnTile(item, number);
            allGameStatesPossible.Add(new InterpretedGameState(clonedState2, interpretedGameState.Direction)
            {
                Depth = interpretedGameState.Depth
            });
        }
コード例 #2
0
        private static List <InterpretedGameState> GetAllRandomPossibleGameStates(InterpretedGameState interpretedGameState)
        {
            List <InterpretedGameState> allGameStatesPossible = new List <InterpretedGameState>();

            foreach (Point item in interpretedGameState.GameState.GetAvailablePositions())
            {
                AddGameStateToList(interpretedGameState, ref allGameStatesPossible, item, 2);
                AddGameStateToList(interpretedGameState, ref allGameStatesPossible, item, 4);
            }
            return(allGameStatesPossible);
        }
コード例 #3
0
        private static List <InterpretedGameState> GetPossibleGameStates(GameState gameState)
        {
            List <InterpretedGameState> possibleGameStates = new List <InterpretedGameState>();

            foreach (Direction direction in new Direction[] { Direction.Left, Direction.Right, Direction.Up, Direction.Down })
            {
                InterpretedGameState newGameState = CopyAndSlideTo(gameState, direction);
                if (!Equals(newGameState, null))
                {
                    possibleGameStates.Add(newGameState);
                }
            }
            return(possibleGameStates);
        }
コード例 #4
0
        private InterpretedGameState InterpreterV2(GameState gameState)
        {
            // get first possible gamestates
            List <InterpretedGameState> possibleGameStates    = GetPossibleGameStates(gameState);
            List <InterpretedGameState> allPossibleGameStates = RecursiveCheck(possibleGameStates);
            // find best reward for actions
            double highestValue = allPossibleGameStates.Max(pgs => pgs.GameState.Value);

            // upon choosing the best rewarded action, spawn a new tile
            Direction            bestDirection = allPossibleGameStates.First(pgs => pgs.GameState.Value == highestValue).Direction;
            InterpretedGameState bestGameState = possibleGameStates.Single(gs => gs.Direction == bestDirection);

            bestGameState.GameState.SpawnTile();
            return(bestGameState);
        }
コード例 #5
0
        private InterpretedGameState Interpreter(GameState gameState)
        {
            // determine possible actions
            List <InterpretedGameState> possibleGameStates = GetPossibleGameStates(gameState);

            // find best reward for actions
            double highestValue = possibleGameStates.Max(pgs => pgs.GameState.Value);

            // upon choosing the best rewarded action, spawn a new tile
            InterpretedGameState bestGameState = possibleGameStates.First(pgs => pgs.GameState.Value == highestValue);

            bestGameState.GameState.SpawnTile();

            return(bestGameState);
        }
コード例 #6
0
 public GameEnvironment(GameState startingState)
 {
     currentGameState = startingState;
     while (!IsGameOver(currentGameState))
     {
         Stopwatch stopwatch = new Stopwatch();
         stopwatch.Start();
         InterpretedGameState interpretedGameState = InterpreterV2(currentGameState);
         stopwatch.Stop();
         Debug.WriteLine($"Time Elapsed: {stopwatch.Elapsed}, Best Direction: {interpretedGameState.Direction}");
         Debug.WriteLine($"Current Score {interpretedGameState.GameState.Score}, Highest Tile: {interpretedGameState.GameState.HighestTile}");
         currentGameState = interpretedGameState.GameState;
         PrintGame();
         interpretedGameStates.Add(interpretedGameState);
     }
 }