Beispiel #1
0
        public override bool Movable(IPosition iSource, IPosition iTarget, IPieceColorMap iPieceColorMap)
        {
            // if the target has a piece of the same side, not movable
            if (iPieceColorMap.PieceColorMap[iTarget.Row, iTarget.Column] == this.Color)
            {
                return(false);
            }

            bool movable = true;

            if (!(
                    (iTarget.Row == iSource.Row - 1 && iTarget.Column == iSource.Column - 2) ||
                    (iTarget.Row == iSource.Row - 1 && iTarget.Column == iSource.Column + 2) ||
                    (iTarget.Row == iSource.Row - 2 && iTarget.Column == iSource.Column - 1) ||
                    (iTarget.Row == iSource.Row - 2 && iTarget.Column == iSource.Column + 1) ||
                    (iTarget.Row == iSource.Row + 1 && iTarget.Column == iSource.Column - 2) ||
                    (iTarget.Row == iSource.Row + 1 && iTarget.Column == iSource.Column + 2) ||
                    (iTarget.Row == iSource.Row + 2 && iTarget.Column == iSource.Column - 1) ||
                    (iTarget.Row == iSource.Row + 2 && iTarget.Column == iSource.Column + 1)
                    ))
            {
                movable = false;
            }

            return(movable);
        }
Beispiel #2
0
        public override bool Movable(IPosition iSource, IPosition iTarget, IPieceColorMap iPieceColorMap)
        {
            // if the target has a piece of the same side, not movable
            if (iPieceColorMap.PieceColorMap[iTarget.Row, iTarget.Column] == this.Color)
            {
                return(false);
            }

            bool movable = true;

            // if the target is not at the same row or same column as the source,
            // return false
            if (iTarget.Row != iSource.Row && iTarget.Column != iSource.Column)
            {
                movable = false;
            }
            else if (iTarget.Row == iSource.Row && iTarget.Column != iSource.Column)
            {
                // moving horizontally
                // check if there is a piece in between source and target
                int  low            = iSource.Column < iTarget.Column ? iSource.Column : iTarget.Column;
                int  high           = iSource.Column > iTarget.Column ? iSource.Column : iTarget.Column;
                bool pieceInBetween = false;
                for (int i = low + 1; i <= high - 1; i++)
                {
                    if (iPieceColorMap.PieceColorMap[iTarget.Row, i] != PIECE_COLOR.Empty)
                    {
                        pieceInBetween = true;
                        break;
                    }
                }
                if (pieceInBetween == true)
                {
                    movable = false;
                }
            }
            else if (iTarget.Row != iSource.Row && iTarget.Column == iSource.Column)
            {
                // moving vertically
                // check if there is a piece in between source and target
                int  low            = iSource.Row < iTarget.Row ? iSource.Row : iTarget.Row;
                int  high           = iSource.Row > iTarget.Row ? iSource.Row : iTarget.Row;
                bool pieceInBetween = false;
                for (int i = low + 1; i <= high - 1; i++)
                {
                    if (iPieceColorMap.PieceColorMap[i, iSource.Column] != PIECE_COLOR.Empty)
                    {
                        pieceInBetween = true;
                        break;
                    }
                }
                if (pieceInBetween == true)
                {
                    movable = false;
                }
            }

            return(movable);
        }
Beispiel #3
0
        public override bool Movable(IPosition iSource, IPosition iTarget, IPieceColorMap iPieceColorMap)
        {
            bool movable = true;

            if (iTarget.Column == iSource.Column)
            {
                if (iTarget.Row == iSource.Row + _direction)
                {
                    if (iPieceColorMap.PieceColorMap[iTarget.Row, iTarget.Column] != PIECE_COLOR.Empty)
                    {
                        movable = false;
                    } // else nothing to do
                }
                else if (iTarget.Row == iSource.Row + 2 * _direction)
                {
                    if (_firstMove)
                    {
                        if (
                            iPieceColorMap.PieceColorMap[iSource.Row + _direction, iSource.Column] != PIECE_COLOR.Empty ||
                            iPieceColorMap.PieceColorMap[iSource.Row + 2 * _direction, iSource.Column] != PIECE_COLOR.Empty)
                        {
                            movable = false;
                        } // else nothing to do
                    }
                    else
                    {
                        movable = false;
                    }
                }
                else
                {
                    movable = false;
                }
            }
            else if (
                iTarget.Column == iSource.Column + 1 ||
                iTarget.Column == iSource.Column - 1)
            {
                // moving diagonally
                if (iPieceColorMap.PieceColorMap[iTarget.Row, iTarget.Column] == this.Color ||
                    iPieceColorMap.PieceColorMap[iTarget.Row, iTarget.Column] == PIECE_COLOR.Empty)
                {
                    // capture only
                    movable = false;
                } // else nothing to do
            }
            else
            {
                movable = false;
            }

            return(movable);
        }
Beispiel #4
0
        public override bool Movable(IPosition iSource, IPosition iTarget, IPieceColorMap iPieceColorMap)
        {
            // if the target has a piece of the same side, not movable
            if (iPieceColorMap.PieceColorMap[iTarget.Row, iTarget.Column] == this.Color)
            {
                return(false);
            }

            bool movable = true;

            // if the target is not in diagonal,
            // return
            if (Math.Abs(iTarget.Row - iSource.Row) != Math.Abs(iTarget.Column - iSource.Column))
            {
                movable = false;
            }
            else
            {
                int distance = Math.Abs(iTarget.Row - iSource.Row);
                int dr       = (iTarget.Row - iSource.Row) > 0 ? 1 : -1;
                int dc       = (iTarget.Column - iSource.Column) > 0 ? 1 : -1;
                // check if there is a piece in between source and target
                bool pieceInBetween = false;
                for (int i = 1; i < distance - 1; i++)
                {
                    if (iPieceColorMap.PieceColorMap[iSource.Row + i * dr, iSource.Column + i * dc] != PIECE_COLOR.Empty)
                    {
                        pieceInBetween = true;
                        break;
                    }
                }
                if (pieceInBetween == true)
                {
                    movable = false;
                }
            }

            return(movable);
        }
Beispiel #5
0
 public override bool Movable(IPosition iSource, IPosition iTarget, IPieceColorMap iPieceColorMap)
 {
     throw new NotImplementedException();
 }