public IEnumerable <ChessRecord> GetChessRecords(PieceColor color)
 {
     for (var i = 0; i < GameParams.BoardWidth; i++)
     {
         for (var j = 0; j < GameParams.BoardHeight; j++)
         {
             var point     = new PiecePoint(i, j);
             var pieceInfo = GetPieceInfo(point);
             if (pieceInfo.IsBlank() || pieceInfo.PieceColor != color)
             {
                 continue;
             }
             var piece         = new ChessPiece(point, pieceInfo);
             var allBasePieces = piece.AllBasePieces;
             foreach (var selectPiece in allBasePieces)
             {
                 if (selectPiece == null)
                 {
                     continue;
                 }
                 var actionPoints = GetActionPoints(selectPiece);
                 foreach (var targetPoint in actionPoints)
                 {
                     var record = GetChessRecord(selectPiece, targetPoint);
                     yield return(record);
                 }
             }
         }
     }
 }
        public ChessRecord GetChessRecord(ChessPiece selectPiece, PiecePoint targetPoint)
        {
            var targetPieceInfo = GetPieceInfo(targetPoint);
            var targetPiece     = new ChessPiece(targetPoint, targetPieceInfo);
            var chessRecord     = new ChessRecord(selectPiece, targetPiece);

            return(chessRecord);
        }
        private static int GetValueOfType(PieceType type, PiecePoint point)
        {
            if (ValueRules.ContainsKey(type))
            {
                return(ValueRules[type][point.Y, point.X]);
            }
            var baseTypes = type.BaseTypes;

            return(GetValueOfType(baseTypes[0], point) + GetValueOfType(baseTypes[1], point));
        }
        private static LegalFlag GetLegalFlag(ChessBoard board, ChessPiece piece, PiecePoint point)
        {
            LegalFlag flag = LegalFlag.None;

            if (piece.ActionArea.IsPointInArea(point))
            {
                var wayPieceInfo = board.GetPieceInfo(point);
                if (wayPieceInfo.IsBlank())
                {
                    flag = LegalFlag.Blank;
                }
                else if (piece.CanEat(wayPieceInfo))
                {
                    flag = LegalFlag.Eatting;
                }
                else if (piece.CanFuse(wayPieceInfo))
                {
                    flag = LegalFlag.Fusion;
                }
            }
            return(flag);
        }
 public void SetPieceInfo(PiecePoint point, PieceInfo info)
 {
     BoardPieces[point.X, point.Y] = info;
 }
 public PieceInfo GetPieceInfo(PiecePoint point)
 {
     return(BoardPieces[point.X, point.Y]);
 }
        private static bool IsLegalPointNotBlank(ChessBoard board, ChessPiece piece, PiecePoint point)
        {
            var flag = GetLegalFlag(board, piece, point);

            return(IsLegalPointNotBlank(flag));
        }
        private static HashSet <PiecePoint> GetActionPointsAroundEye(
            ChessBoard board,
            ChessPiece piece,
            Direction[] wayDirections,
            PiecePoint eyePoint,
            bool isStepPiece = true,
            bool isCannon    = false,
            bool isKing      = false,
            bool addition    = false)
        {
            var actionWays = new HashSet <PiecePoint>();

            foreach (var wayDirection in wayDirections)
            {
                var wayPoint = eyePoint ?? piece.PiecePoint;
                do
                {
                    wayPoint = wayPoint.GetPointInDirection(wayDirection);
                    var flag = GetLegalFlag(board, piece, wayPoint);
                    if (!IsLegal(flag) || (flag == LegalFlag.Eatting && isCannon && !addition))
                    {
                        break;
                    }
                    actionWays.Add(wayPoint);
                    if (IsLegalPointNotBlank(flag))
                    {
                        break;
                    }
                } while (!isStepPiece);
                if (isCannon)
                {
                    do
                    {
                        wayPoint = wayPoint.GetPointInDirection(wayDirection);
                    }while (IsLegalPoint(board, piece, wayPoint));
                    if (IsLegalPointNotBlank(board, piece, wayPoint))
                    {
                        actionWays.Add(wayPoint);
                    }
                }
            }
            if (isKing)
            {
                var pieceInfo = new PieceInfo();
                var wayPoint  = piece.PiecePoint;
                var direction = wayPoint.Y < 5 ? Direction.Up : Direction.Down;
                do
                {
                    wayPoint = wayPoint.GetPointInDirection(direction);
                    if (!ActionAreaRule.FullArea.IsPointInArea(wayPoint))
                    {
                        break;
                    }
                    pieceInfo = board.GetPieceInfo(wayPoint);
                } while (pieceInfo.IsBlank());
                if (pieceInfo.PieceType == PieceType.King)
                {
                    actionWays.Add(wayPoint);
                }
            }
            return(actionWays);
        }
 public ChessPiece(PiecePoint point, PieceType type, PieceColor color) : this(point, new PieceInfo(type, color))
 {
 }
 public ChessPiece(PiecePoint point, PieceInfo info)
 {
     PiecePoint = point;
     PieceInfo  = info;
 }