Пример #1
0
        public void Go(Point point)
        {
            var previousPoint = _currentPosition;

            _currentPosition = point;
            Gameboard.MoveFeagure(point, this);

            if (_type == FeagureType.Pawn)
            {
                if (_color == Common.Color.White && point.Y == 0 || _color == Color.Black && point.Y == Gameboard.BoardSize - 1)
                {
                    throw new RequireExchangeException {
                              Color = _color
                    }
                }
                ;
            }

            if (Gameboard.CheckFatality(_color))
            {
                throw new FatalityException {
                          WinColor = _color
                }
            }
            ;

            Trace.TraceInformation("{0} {1} from {2} goto {3}", _color, _type, previousPoint, point);
        }
Пример #2
0
        public bool CanGo(Point point, bool checkKing = false)
        {
            var canGo = _possibleMoves(_currentPosition).Contains(point);

            if (!canGo)
            {
                return(false);
            }

            if (_type == FeagureType.King)
            {
                canGo = !Gameboard.IsKingBecamaUnderAttack(point, _color);
                if (canGo && Gameboard.Busy(point) == ColorHelper.GetOpposite(_color))
                {
                    canGo = !Gameboard.IsProtectedPoint(point);
                }
            }

            if (checkKing && _type != FeagureType.King && Gameboard.IsKingUnderAttack(_color, point, this))
            {
                return(false);
            }

            return(canGo);
        }
Пример #3
0
        internal Chessman(Point position, FeagureType type, Color color)
        {
            Width = Height = 70;

            _currentPosition = position;

            InitFeagure(type, color);

            Gameboard.AddFeagure(position, this);
        }
Пример #4
0
        static IEnumerable <Point> KnightMoves(Point currentPoint, Color color)
        {
            var points = new[]
            {
                new Point(currentPoint.X + 1, currentPoint.Y - 2)
                , new Point(currentPoint.X + 2, currentPoint.Y - 1)
                , new Point(currentPoint.X + 2, currentPoint.Y + 1)
                , new Point(currentPoint.X + 1, currentPoint.Y + 2)

                , new Point(currentPoint.X - 1, currentPoint.Y - 2)
                , new Point(currentPoint.X - 2, currentPoint.Y - 1)
                , new Point(currentPoint.X - 2, currentPoint.Y + 1)
                , new Point(currentPoint.X - 1, currentPoint.Y + 2)
            };

            return(points.Where(_ => Gameboard.Busy(_) != color));
        }
Пример #5
0
        static IEnumerable <Point> BlackPawnMoves(Point currentPoint)
        {
            var result = new List <Point>();

            //Forward move
            if (currentPoint.Y == 1)
            {
                var firstStep = new Point(currentPoint.X, 2);
                if (Gameboard.Busy(firstStep) == Color.None)
                {
                    result.Add(firstStep);

                    var secondStep = new Point(currentPoint.X, 3);
                    if (Gameboard.Busy(secondStep) == Color.None)
                    {
                        result.Add(secondStep);
                    }
                }
            }
            else
            {
                var step = new Point(currentPoint.X, currentPoint.Y + 1);

                if (Gameboard.Busy(step) == Color.None)
                {
                    result.Add(step);
                }
            }

            //Kill move
            var rightKill = new Point(currentPoint.X + 1, currentPoint.Y + 1);

            if (Gameboard.Busy(rightKill) == Color.White)
            {
                result.Add(rightKill);
            }
            var leftKill = new Point(currentPoint.X - 1, currentPoint.Y + 1);

            if (Gameboard.Busy(leftKill) == Color.White)
            {
                result.Add(leftKill);
            }

            return(result);
        }
Пример #6
0
        /// <summary>
        /// Check and add move for long run feagures (bishop, rook, queen)
        /// </summary>
        /// <returns>If true can continue, if false need to break cycle</returns>
        static bool AddMoveIfNeeded(List <Point> result, int x, int y, Color color)
        {
            var point     = new Point(x, y);
            var busyColor = Gameboard.Busy(point);

            if (busyColor == color)
            {
                return(false);
            }

            result.Add(point);

            if (busyColor != Color.None && Gameboard.BusyType(point) == FeagureType.King)
            {
                return(true);
            }

            return(busyColor == Color.None);
        }
Пример #7
0
        static IEnumerable <Point> KingMoves(Point currentPoint, Color color)
        {
            IEnumerable <Point> points = new[]
            {
                new Point(currentPoint.X, currentPoint.Y - 1)
                , new Point(currentPoint.X + 1, currentPoint.Y - 1)
                , new Point(currentPoint.X + 1, currentPoint.Y)
                , new Point(currentPoint.X + 1, currentPoint.Y + 1)
                , new Point(currentPoint.X, currentPoint.Y + 1)
                , new Point(currentPoint.X - 1, currentPoint.Y + 1)
                , new Point(currentPoint.X - 1, currentPoint.Y)
                , new Point(currentPoint.X - 1, currentPoint.Y - 1)
            };

            //TODO: not under attack
            points = points.Where(_ => Gameboard.Busy(_) != color).ToList();

            return(points);
        }