Пример #1
0
        //bitwise operation - places a '1' at any bit that's not symmetric
        public void UpdateSymmetry(TTTIndividualSymmetry symmetry)
        {
            if (!symmetry.isSymmetric)
            {
                bitwiseSymmetryCheck |= (1 << checks[symmetry]);
            }
            else
            {
                bitwiseSymmetryCheck &= ~(1 << checks[symmetry]);
            }

            //If all bits are 0, there's symmetry
            isSymmetric = (bitwiseSymmetryCheck == 0);
        }
Пример #2
0
 public void AddSymmetry(TTTIndividualSymmetry symmetry)
 {
     checks.Add(symmetry, checks.Count);
 }
Пример #3
0
        //register all types of symmetries the board can have
        void SetSymmetries()
        {
            symmetryTypes = new List <TTTBoardSymmetryCheck>();

            TTTBoardSymmetryCheck XaxisSymmetry                = new TTTBoardSymmetryCheck();
            TTTBoardSymmetryCheck YaxisSymmetry                = new TTTBoardSymmetryCheck();
            TTTBoardSymmetryCheck DiagonalBackSlashSymmetry    = new TTTBoardSymmetryCheck();
            TTTBoardSymmetryCheck DiagonalForwardSlashSymmetry = new TTTBoardSymmetryCheck();
            TTTBoardSymmetryCheck QuarterRotationalSymmetry    = new TTTBoardSymmetryCheck();
            TTTBoardSymmetryCheck HalfRotationalSymmetry       = new TTTBoardSymmetryCheck();

            symmetryTypes.Add(XaxisSymmetry);
            symmetryTypes.Add(YaxisSymmetry);
            symmetryTypes.Add(DiagonalBackSlashSymmetry);
            symmetryTypes.Add(DiagonalForwardSlashSymmetry);
            symmetryTypes.Add(QuarterRotationalSymmetry);
            symmetryTypes.Add(HalfRotationalSymmetry);

            TTTIndividualSymmetry sym;

            //All the extra set up is taken care of in the TTTIndividualSymmetry constructor, so we only have to worry about whats sets of squares here are symmetrical
            for (int i = 0; i < boardLength; ++i)
            {
                for (int j = 0; j < boardLength / 2; ++j)
                {
                    sym = new TTTIndividualSymmetry(new TTTSquare[] { board[i][j], board[i][boardLength - 1 - j] }, XaxisSymmetry);
                }
            }

            for (int i = 0; i < boardLength / 2; ++i)
            {
                for (int j = 0; j < boardLength; ++j)
                {
                    sym = new TTTIndividualSymmetry(new TTTSquare[] { board[i][j], board[boardLength - 1 - i][j] }, YaxisSymmetry);
                }
            }

            for (int i = 0; i < boardLength; ++i)
            {
                for (int j = 0; j < i; ++j)
                {
                    sym = new TTTIndividualSymmetry(new TTTSquare[] { board[i][j], board[j][i] }, DiagonalForwardSlashSymmetry);
                }
            }

            for (int i = 0; i < boardLength; ++i)
            {
                for (int j = boardLength - 1; j >= boardLength - i; --j)
                {
                    sym = new TTTIndividualSymmetry(new TTTSquare[] { board[i][j], board[boardLength - 1 - j][boardLength - 1 - i] }, DiagonalBackSlashSymmetry);
                }
            }

            for (int i = 0; i < (boardLength + 1) / 2; ++i)
            {
                for (int j = 0; j < boardLength / 2; ++j)
                {
                    sym = new TTTIndividualSymmetry(
                        new TTTSquare[] { board[i][j], board[boardLength - 1 - j][i], board[boardLength - 1 - i][boardLength - 1 - j], board[j][boardLength - 1 - i] },
                        QuarterRotationalSymmetry
                        );
                }
            }

            for (int i = 0; i < (boardLength * boardLength) / 2; ++i)
            {
                sym = new TTTIndividualSymmetry(new TTTSquare[] { board[i / boardLength][i % boardLength], board[boardLength - 1 - i / boardLength][boardLength - 1 - i % boardLength] }, HalfRotationalSymmetry);
            }
        }