Example #1
0
        /// <summary>
        /// Calculate index of pattern (unique id of pattern)
        /// <para>Trả về index (unique id) của 1 pattern cụ thể (pattern = patternShape & gameBoard)</para>
        /// </summary>
        public static int CalculatePatternCode(this PatternShape ps, BitBoard bitBoard)
        {
            // ---------- Version của thầy ----------
            // var len = ps.ArrayBitCells.Length;
            // var pattern = new int[len];
            // for (var i = 0; i < len; i++)
            //     pattern[i] = bitBoard.GetPieceAt(ps.ArrayBitCells[i]);
            //
            // var result = 0;
            // for (var i = 0; i < len; i++)
            //     result += pattern[len - i - 1] * MathUtils.Power3(i);

            // ---------- Version của nhóm - ra kết quả giống thầy, nhưng optimized, không cần dùng array ----------
            var result = 0;
            var len    = ps.ArrayBitCells.Length;

            for (var i = 0; i < len; i++)
            {
                var cellPos   = ps.ArrayBitCells[i];
                var cellValue = bitBoard.GetPieceAt(cellPos);
                result += cellValue * MathUtils.Power3(len - i - 1);
            }

            return(result);
        }
Example #2
0
        [NonSerialized] public Dictionary <int, float> GammaDenominator; // Mẫu số: SUM(Cij/E)

        public PatternMining(PatternShape patternShape)
        {
            PatternShape = patternShape;

            Gamma            = new Dictionary <int, float>();
            Win              = new Dictionary <int, ushort>();
            Candidate        = new Dictionary <int, ushort>();
            GammaDenominator = new Dictionary <int, float>();
        }
Example #3
0
        private static PatternShape CopyByFlipSubDiagonal(this PatternShape ps)
        {
            var targetBitCell = ps.TargetBitCell.FlipDiagA1H8();
            var bitCellArray  = new ulong[ps.ArrayBitCells.Length];

            for (var i = 0; i < bitCellArray.Length; i++)
            {
                bitCellArray[i] = ps.ArrayBitCells[i].FlipDiagA1H8();
            }
            return(new PatternShape(bitCellArray, targetBitCell));
        }
Example #4
0
        private static PatternShape CopyByFlipHorizontal(this PatternShape ps)
        {
            var targetBitCell = ps.TargetBitCell.MirrorHorizontal();
            var bitCellArray  = new ulong[ps.ArrayBitCells.Length];

            for (var i = 0; i < bitCellArray.Length; i++)
            {
                bitCellArray[i] = ps.ArrayBitCells[i].MirrorHorizontal();
            }
            return(new PatternShape(bitCellArray, targetBitCell));
        }
Example #5
0
        public static string HumanReadablePatternCode(this PatternShape ps, int patternCode)
        {
            var str = new StringBuilder(ps.ArrayBitCells.Length);

            for (var i = 0; i < ps.ArrayBitCells.Length; i++)
            {
                str.Insert(0, patternCode % 3);
                patternCode /= 3;
            }

            return(str.ToString());
        }
Example #6
0
        /// <summary>
        /// Create List of pattern flipped/mirrored/rotated
        /// <para>Tạo ra các pattern được flip/mirror/rotate, rồi bỏ tất cả vào 1 List, trả về List</para>
        /// </summary>
        public static List <PatternShape> Sym8(this PatternShape ps)
        {
            var result = new List <PatternShape>();
            var ps2    = ps.CopyByFlipMainDiagonal();

            result.Add(ps);
            result.Add(ps.CopyByFlipVertical());
            result.Add(ps.CopyByFlipHorizontal());
            result.Add(ps.CopyByFlipSubDiagonal());
            result.Add(ps2);
            result.Add(ps2.CopyByFlipVertical());
            result.Add(ps2.CopyByFlipHorizontal());
            result.Add(ps2.CopyByFlipSubDiagonal());
            return(result);
        }
Example #7
0
        // Kiem tra xem pattern hien tai co phai la cha (chứa) pattern other hay khong.
        public static bool Contains(this PatternShape ps, PatternShape other)
        {
            if (ps.TargetBitCell != other.TargetBitCell)
            {
                return(false);
            }

            foreach (var pos in other.ArrayBitCells)
            {
                if (Array.IndexOf(ps.ArrayBitCells, pos) < 0)
                {
                    return(false);
                }
            }

            return(true);
        }
Example #8
0
 /// <summary>
 /// Return index of bitCell in BitCellsArray
 /// </summary>
 public static int IndexOfBitCell(this PatternShape ps, ulong bitCell)
 {
     return(Array.IndexOf(ps.ArrayBitCells, bitCell));
 }