예제 #1
0
        private static TesseraResult CheckInRange(Point[] points, PieceColor pieceColor)
        {
            TesseraResult result = new TesseraResult();

            if (points.Length == 6)
            {
                //makes sure the end points are open
                if (game.GetPieceAt(points[0]) == PieceColor.Empty && game.GetPieceAt(points[5]) == PieceColor.Empty)
                {
                    result.isTria    = true;
                    result.isTessera = true;
                    for (int i = 1; i < 5; i++)
                    {
                        if (game.GetPieceAt(points[i]) == PieceColor.Empty)
                        {
                            result.isTria    = result.isTessera ? true : false;
                            result.isTessera = false;
                        }
                        else if (game.GetPieceAt(points[i]) != pieceColor)
                        {
                            result.isTria    = false;
                            result.isTessera = false;
                        }
                    }
                }
            }
            return(result);
        }
예제 #2
0
        private static bool CheckTessera(int row, int col, PieceColor pieceColor)
        {
            TesseraResult result = new TesseraResult();


            // Up-Down
            for (int i = 0; i < 4 && !result.isTessera; i++)
            {
                bool    validRange = true;
                Point[] points     = new Point[6];
                for (int j = 0; j < 6 && validRange; j++)
                {
                    points[j]  = new Point(row - j + i + 1, col);
                    validRange = IsPointWithinBoard(points[j]);
                }
                if (!validRange)
                {
                    continue;
                }
                TesseraResult tesseraResult = CheckInRange(points, pieceColor);

                game.Tessera = tesseraResult.isTessera ? tesseraResult.isTessera : game.Tessera;
                game.Tria    = tesseraResult.isTria ? tesseraResult.isTria : game.Tria;

                if (tesseraResult.isTessera || tesseraResult.isTria)
                {
                    result = tesseraResult;
                }
            }
            // Left-Right
            for (int i = 0; i < 4 && !result.isTessera; i++)
            {
                bool    validRange = true;
                Point[] points     = new Point[6];
                for (int j = 0; j < 6 && validRange; j++)
                {
                    points[j]  = new Point(row, col - j + i + 1);
                    validRange = IsPointWithinBoard(points[j]);
                }
                if (!validRange)
                {
                    continue;
                }
                TesseraResult tesseraResult = CheckInRange(points, pieceColor);

                game.Tessera = tesseraResult.isTessera ? tesseraResult.isTessera : game.Tessera;
                game.Tria    = tesseraResult.isTria ? tesseraResult.isTria : game.Tria;

                if (tesseraResult.isTessera || tesseraResult.isTria)
                {
                    result = tesseraResult;
                }
            }
            // Diagonal \
            for (int i = 0; i < 4 && !result.isTessera; i++)
            {
                bool    validRange = true;
                Point[] points     = new Point[6];
                for (int j = 0; j < 6 && validRange; j++)
                {
                    points[j]  = new Point(row - j + i + 1, col - j + i + 1);
                    validRange = IsPointWithinBoard(points[j]);
                }
                if (!validRange)
                {
                    continue;
                }
                TesseraResult tesseraResult = CheckInRange(points, pieceColor);

                game.Tessera = tesseraResult.isTessera ? tesseraResult.isTessera : game.Tessera;
                game.Tria    = tesseraResult.isTria ? tesseraResult.isTria : game.Tria;

                if (tesseraResult.isTessera || tesseraResult.isTria)
                {
                    result = tesseraResult;
                }
            }
            // Diagonal /
            for (int i = 0; i < 4 && !result.isTessera; i++)
            {
                bool    validRange = true;
                Point[] points     = new Point[6];
                for (int j = 0; j < 6 && validRange; j++)
                {
                    points[j]  = new Point(row + j - i - 1, col - j + i + 1);
                    validRange = IsPointWithinBoard(points[j]);
                }
                if (!validRange)
                {
                    continue;
                }
                TesseraResult tesseraResult = CheckInRange(points, pieceColor);

                game.Tessera = tesseraResult.isTessera ? tesseraResult.isTessera : game.Tessera;
                game.Tria    = tesseraResult.isTria ? tesseraResult.isTria : game.Tria;

                if (tesseraResult.isTessera || tesseraResult.isTria)
                {
                    result = tesseraResult;
                }
            }

            return(result.isTessera || result.isTria);
        }