Exemplo n.º 1
0
        static void Simulate()
        {
            var heuristic = new GaHeuristic(-0.317854214844296, -0.548457056926845, -0.434173510009484, -0.640044465657585);
            //var heuristic = new YiyuanLeeHeuristic();
            //var heuristic = new ElTetrisHeuristic();
            //var heuristic = new ExperimentalHeuristic();
            //var heuristic = new MaxBergmarkHeuristic();

            var tetrisSearch = new TwoPieceSearch(heuristic);

            //var tetrisSearch = new OnePieceSearch(heuristic);
            //var tetrisSearch = new PredictiveSearch(heuristic);
            //tetrisSearch.Cache = true;
            //var tetrisSearch = new RecursiveSearch(heuristic);
            //tetrisSearch.Depth = 3;

            for (int i = 0; i < _games; i++)
            {
                Console.WriteLine($"Game {i + 1}");

                var tetrisSimulator = new TetrisSimulator();
                var engine          = new SimulatorEngine(tetrisSearch, tetrisSimulator);
                engine.FrameUpdateDelay = 1;
                engine.PauseTime        = 0;
                engine.Multiplayer      = false;
                //engine.MaxHeight = 10;
                engine.Render = false;

                engine.Run();
            }
        }
Exemplo n.º 2
0
        public double EvaluateFitness(Chromosome chromosome)
        {
            var p1 = chromosome.Genes[0].RealValue;
            var p2 = chromosome.Genes[1].RealValue;
            var p3 = chromosome.Genes[2].RealValue;
            var p4 = chromosome.Genes[3].RealValue;

            var heuristic = new GaHeuristic(p1, p2, p3, p4);
            var search    = new TwoPieceSearch(heuristic);
            var lines     = SimulateAvg(search, _games, _pieces);

            return(System.Math.Min((1.0 + lines) / 1000000.0, 1.0));
        }
Exemplo n.º 3
0
        public void Init()
        {
            _heuristic = new YiyuanLeeHeuristic();

            _twoPieceSearch         = new TwoPieceSearch(_heuristic);
            _predictiveSearch       = new PredictiveSearch(_heuristic);
            _predictiveSearch.Cache = false;
            _recursiveSearch        = new RecursiveSearch(_heuristic);
            _recursiveSearch.Depth  = 2;

            // init lookups
            var lookups = BoardLookups.Instance;
        }
Exemplo n.º 4
0
        public void SimpleSearchFull(Tetrimino current, Tetrimino next)
        {
            var simpleSearchLocal = new TwoPieceSearch(new YiyuanLeeHeuristic());

            var gameState = new GameState(current, next);

            _logger.Info(gameState);

            var result = simpleSearchLocal.Search(gameState);

            _logger.Info(result.GoalGameState);

            Assert.AreEqual(3, result.Moves.Count());
            Assert.AreEqual(Move.RotateCounterclockwise, result.Moves.ToList()[0]);
            Assert.AreEqual(Move.RotateCounterclockwise, result.Moves.ToList()[1]);
            Assert.AreEqual(Move.Drop, result.Moves.ToList()[2]);
        }
Exemplo n.º 5
0
        static TimeSpan MeasureSimpleSearch(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 TwoPieceSearch(heuristic);

            var sw = new Stopwatch();

            sw.Start();

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

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