Beispiel #1
0
 /// <summary>
 ///     Adds a tile in a random position
 /// </summary>
 public void Move(GridModel grid)
 {
     var cells = grid.AvailableCells();
     if (cells.Any())
     {
         int value = _rand.NextDouble() < _percentageOfValue1 ? 1 : 2;
         var tile = new TileModel(value);
         var position = cells[_rand.Next(cells.Length)];
         tile.Position = position;
     }
 }
Beispiel #2
0
        private double Minimizer(GridModel grid, int depth, double alpha, double beta)
        {
            // computer's turn, we'll do heavy pruning to keep the branching factor low
            var availableCells = grid.AvailableCells().ToList();

            // try out all combinations possible
            foreach (var value in new int[] { 1, 2 })
            {
                foreach (CellModel cell in availableCells)
                {
                    var tile = new TileModel(value);
                    tile.Position = cell;
                    beta = Math.Min(beta, AlphaBetaSearch(grid, depth, true, alpha, beta));
                    tile.Position = null;

                    if (beta < alpha) // pruning
                    {
                        return alpha;
                    }
                }
            }

            /*
            // try a 2 and 4 in each cell and measure how annoying it is
            // with metrics from eval
            //var scores = { 2: [], 4: [] };
            foreach (var value in new int[] { 1, 2 })
            {
                foreach (CellModel cell in availableCells)
                {
                    scores[value].push(null);

                    var tile = new TileModel(value);
                    tile.Position = cell;

                    scores[value][i] = -grid.Smoothness() + grid.Islands();

                    tile.Position = null;
                }
            }

            // now just pick out the most annoying moves
            var candidates = new List<CellModel>();
            var maxScore = Math.Max(Math.Max(null, scores[2]), Math.Max(null, scores[4]));
            foreach (var value in new int[] { 1, 2 })
            {
                for (var i = 0; i < scores[value].length; i++)
                {
                    if (scores[value][i] >= maxScore)
                    {
                        candidates.Add(cells[i]);
                    }
                }
            }

            // search on each candidate
            foreach (CellModel position in candidates)
            {
      
            }
             */
            return beta;
        }