Esempio n. 1
0
        private static void GetCacheLineEmptySumMerges(int line)
        {
            double sumPower   = Weights.SumPower;
            var    levels     = BitBoardHandler.ToLevels((Line)line);
            double lineSum    = 0;
            double lineEmpty  = 0;
            double lineMerges = 0;

            int preLevel = 0;
            int counter  = 0;

            for (int i = 0; i < 4; ++i)
            {
                int level = levels[i];
                lineSum += Math.Pow(level, sumPower);
                if (level == 0)
                {
                    ++lineEmpty;
                }
                else
                {
                    if (preLevel == level)
                    {
                        ++counter;
                    }
                    else if (counter > 0)
                    {
                        lineMerges += (1 + counter);
                        counter     = 0;
                    }
                    preLevel = level;
                }
            }
            if (counter > 0)
            {
                lineMerges += (1 + counter);
            }
            moveScores[line] +=
                lineEmpty * Weights.EmptyWeight
                + lineMerges * Weights.MergeWeight
                - lineSum * Weights.SumWeight;
        }
Esempio n. 2
0
        private static void GetCacheLineMono(int line)
        {
            double monoPower     = Weights.MoveMonoPower;
            var    levels        = BitBoardHandler.ToLevels((Line)line);
            double lineMonoLeft  = 0;
            double lineMonoRight = 0;

            for (int i = 1; i < 4; ++i)
            {
                if (levels[i - 1] > levels[i])
                {
                    lineMonoLeft += Math.Pow(levels[i - 1], monoPower) - Math.Pow(levels[i], monoPower);
                }
                else
                {
                    lineMonoRight += Math.Pow(levels[i], monoPower) - Math.Pow(levels[i - 1], monoPower);
                }
            }
            moveScores[line] -= Math.Min(lineMonoLeft, lineMonoRight) * Weights.MonoWeight;
        }
Esempio n. 3
0
        public void TestMaxValue()
        {
            var chessBoard = new ChessBoard();
            var levels     = ChessBoardHandler.GetRandomCountDistinctLevels();
            int maxLevel   = levels.Max();
            int levelIndex = 0;

            for (int row = 0; row < 4; ++row)
            {
                for (int col = 0; col < 4; ++col)
                {
                    if (levelIndex == levels.Length)
                    {
                        break;
                    }
                    chessBoard.AddNew(new Position(row, col), levels[levelIndex]);
                    ++levelIndex;
                }
            }
            Assert.AreEqual(chessBoard.MaxValue, BitBoardHandler.ToValue(maxLevel));
        }
Esempio n. 4
0
        private static void CacheLineSmooth(int line)
        {
            double smoothPower = Weights.SmoothPower;
            var    levels      = BitBoardHandler.ToLevels((Line)line);
            double lineSmooth  = 0;

            for (int i = 0; i < 3; ++i)
            {
                if (levels[i] > 0)
                {
                    for (int j = i + 1; j < 4; ++j)
                    {
                        if (levels[j] > 0)
                        {
                            lineSmooth -= Math.Pow(Math.Abs(levels[i] - levels[j]), smoothPower);
                            break;
                        }
                    }
                }
            }
            addScores[line] = lineSmooth * Weights.SmoothWeight;
        }