Пример #1
0
        //A priority is chosen based on the highest priority of all squares
        //Assuming the board is symmetrical, only the highest priority square will get chosen by the AI
        public TTTIndividualSymmetry(TTTSquare[] testedSquares, TTTBoardSymmetryCheck owner)
        {
            squares   = testedSquares;
            mainOwner = owner;

            for (int i = 0; i < squares.Length; ++i)
            {
                squares[i].symmetries.Add(this);
                if (symmetryPriority < squares[i].priority)
                {
                    symmetryPriority = squares[i].priority;
                }
            }

            owner.AddSymmetry(this);
            UpdateSymmetry();
        }
Пример #2
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);
            }
        }