Exemplo n.º 1
0
        public TetrisSimulator(GameState gameState = null)
        {
            var board     = new Board();
            var piece     = new Piece();
            var nextPiece = Tetriminos.GetRandom();

            GameState = gameState ?? new GameState(board, piece, nextPiece)
            {
                StartLevel = 9
            };
        }
Exemplo n.º 2
0
        public TetrisSimulator InHeartMode()
        {
            var board     = new Board();
            var piece     = new Piece();
            var nextPiece = Tetriminos.GetRandom();

            GameState = new GameState(board, piece, nextPiece)
            {
                StartLevel = 9, HeartMode = true
            };
            return(this);
        }
Exemplo n.º 3
0
        public void SimpleSearchRandomBoards()
        {
            int maxHeight = 15;

            for (int i = 0; i < 100; i++)
            {
                var board   = TestHelper.GetRandomBoard(maxHeight);
                var current = Tetriminos.GetRandom();
                var next    = Tetriminos.GetRandom();

                var gameState = new GameState(board, current, next);
                var result    = _twoPieceSearch.Search(gameState);
            }
        }
Exemplo n.º 4
0
        private IEnumerable <GameState> GenerateGameStates(int number)
        {
            var random = new Random(123);

            for (int i = 0; i < number; i++)
            {
                var board     = new Board().Random(random);
                var piece     = new Piece(Tetriminos.GetRandom(random));
                var nextPiece = Tetriminos.GetRandom(random);

                var gameState = new GameState(board, piece, nextPiece);

                yield return(gameState);
            }
        }
Exemplo n.º 5
0
        public void PredictiveSearchAllSeven_Parallel()
        {
            Tetrimino current = Tetriminos.GetRandom();

            Task <SearchResult>[] tasks = new Task <SearchResult> [Tetriminos.All.Length];
            foreach (var next in Tetriminos.All)
            {
                tasks[(int)next] = Task.Factory.StartNew(() =>
                {
                    var gameState = new GameState(current, next);

                    return(_predictiveSearch.Search(gameState));
                });
            }

            Task.WaitAll(tasks);
        }
Exemplo n.º 6
0
        static TimeSpan MeasurePredictiveSearch(int number)
        {
            var gamestates = Enumerable.Range(0, number)
                             .Select(x => new Board().Random())
                             .Select(x => new GameState(x, Tetriminos.GetRandom(), Tetriminos.GetRandom()))
                             .ToList();

            var heuristic = new YiyuanLeeHeuristic();
            var search    = new PredictiveSearch(heuristic);

            var sw = new Stopwatch();

            sw.Start();

            foreach (var gamestate in gamestates)
            {
                var result = search.Search(gamestate);
            }

            sw.Stop();
            return(sw.Elapsed);
        }