Example #1
0
        private long SingleHeuristic(byte lastMoveMark, int i0, int j0, byte goodMark)
        {
            long[] sums = new long[4] {
                1, 1, 1, 1
            };
            long[] lens = new long[4] {
                1, 1, 1, 1
            };
            long[]         gaps = new long[4];
            RowOpenClose[] ends = new RowOpenClose[8];
            for (int i = 1; i <= 5; ++i)
            {
                this.CheckCellInRow(goodMark, i0 + i, j0, 0, 0, lens, sums, ends, gaps);
                this.CheckCellInRow(goodMark, i0 - i, j0, 0, 1, lens, sums, ends, gaps);
                this.CheckCellInRow(goodMark, i0, j0 + i, 1, 2, lens, sums, ends, gaps);
                this.CheckCellInRow(goodMark, i0, j0 - i, 1, 3, lens, sums, ends, gaps);
                this.CheckCellInRow(goodMark, i0 + i, j0 + i, 2, 4, lens, sums, ends, gaps);
                this.CheckCellInRow(goodMark, i0 - i, j0 - i, 2, 5, lens, sums, ends, gaps);
                this.CheckCellInRow(goodMark, i0 + i, j0 - i, 3, 6, lens, sums, ends, gaps);
                this.CheckCellInRow(goodMark, i0 - i, j0 + i, 3, 7, lens, sums, ends, gaps);
            }

            for (int i = 0; i < ends.Length; ++i)
            {
                if (ends[i] == RowOpenClose.Unknown)
                {
                    ends[i] = RowOpenClose.Open;
                }
            }

            long globalSum     = 0;
            int  sumMore3Count = 0;

            for (int i = 0; i < sums.Length; ++i)
            {
                var weightedSum = this.GetWeightedSum(lastMoveMark, goodMark, lens[i], sums[i], gaps[i], ends[i * 2], ends[(i * 2) + 1], ref sumMore3Count);
                if (weightedSum >= long.MaxValue / 10000)
                {
                    return(weightedSum);
                }

                globalSum += weightedSum;
            }

            return(globalSum);
        }
Example #2
0
        private long GetWeightedSum(byte lastMoveMark, byte goodMark, long len, long sum, long gap, RowOpenClose end1, RowOpenClose end2, ref int sumMore3Count)
        {
            if (len < 5)
            {
                sum = 0;
            }

            if (gap == 1)
            {
                sum--;
            }

            if (gap > 1)
            {
                sum = 1;
            }

            if (sum >= 5)
            {
                return((long.MaxValue / 10000) + 3);
            }

            if (this.IsHaveAdvantage(lastMoveMark, goodMark) && sum == 4 && (end1 == RowOpenClose.Open || end2 == RowOpenClose.Open))
            {
                return((long.MaxValue / 10000) + 2);
            }

            if (this.IsHaveAdvantage(lastMoveMark, goodMark) && sum == 3 && (end1 == RowOpenClose.Open && end2 == RowOpenClose.Open))
            {
                return((long.MaxValue / 10000) + 1);
            }

            if (sum == 4 && end1 == RowOpenClose.Open && end2 == RowOpenClose.Open)
            {
                return((long.MaxValue / 10000) + 2);
            }

            if (sum >= 3 && end1 == RowOpenClose.Open && end2 == RowOpenClose.Open)
            {
                sumMore3Count++;
                if (sumMore3Count >= 2)
                {
                    return((long.MaxValue / 10000) + 1);
                }
            }

            long weightedSum = sum;

            if (end1 == RowOpenClose.Close && end2 == RowOpenClose.Close)
            {
                weightedSum *= 1;
            }
            else if (end1 == RowOpenClose.Close || end2 == RowOpenClose.Close)
            {
                weightedSum *= 10;
            }
            else
            {
                weightedSum *= 100;
            }

            if (this.IsHaveAdvantage(lastMoveMark, goodMark))
            {
                weightedSum *= 1000;
            }

            return(weightedSum);
        }