Example #1
0
        /// <summary>
        /// Checks if King can find a capture on the given diagonal
        /// </summary>
        /// <param name="diagonaleCells"></param>
        /// <param name="opponent"></param>
        /// <param name="endPoints"></param>
        /// <param name="takenPoint"></param>
        /// <param name="taken"></param>
        /// <param name="originalPosition"></param>
        /// <returns></returns>
        private bool CanKingCaptureDiagonale(List <Point> diagonaleCells, Player opponent,
                                             out List <Point> endPoints, out Point?takenPoint,
                                             List <Point> taken, Point originalPosition)
        {
            endPoints  = new List <Point>();
            takenPoint = null;
            bool anyCaputeExist     = false;
            bool nextPieceReached   = false;
            bool diagonalEndReached = false;
            int  moveEndPosition    = 1;

            int      diagonalIndex;
            CellData cellData;

            if (IsPieceFoundOnDiagonal(diagonaleCells, out diagonalIndex, out cellData))
            {
                moveEndPosition = diagonalIndex + 1;

                if (moveEndPosition < diagonaleCells.Count)
                {
                    do
                    {
                        bool nearestIsOpponent = cellData.Player == opponent;

                        bool nextIsEmpty = !Pieces.Any(x => x.Pos.Equals(diagonaleCells[moveEndPosition]) && !x.IsHighlight) ||
                                           (diagonaleCells[moveEndPosition].Equals(originalPosition));
                        //original position shuold be empty at the time of move;
                        bool isNotTakenYet = !taken.Contains(diagonaleCells[0]);

                        diagonalEndReached = moveEndPosition == diagonaleCells.Count - 1;
                        nextPieceReached   = !nextIsEmpty;

                        bool can = false;

                        if (nearestIsOpponent && nextIsEmpty && isNotTakenYet)
                        {
                            anyCaputeExist = true;
                            can            = true;
                        }

                        if (can)
                        {
                            endPoints.Add(diagonaleCells[moveEndPosition]);
                            takenPoint = cellData.Pos;
                        }

                        moveEndPosition++;
                    } while (!diagonalEndReached && !nextPieceReached);
                }
            }
            return(anyCaputeExist);
        }
Example #2
0
        /// <summary>
        /// Checks if the place is valid to move piece
        /// </summary>
        /// <param name="endPoint"></param>
        /// <returns></returns>
        private bool IsValidArrangeMove(Point endPoint)
        {
            //only dark cells
            if (!_darkCells.Contains(endPoint))
            {
                return(false);
            }

            //only free cells
            if (Pieces.Any(x => x.Pos.Equals(endPoint) && !x.IsHighlight))
            {
                return(false);
            }


            return(true);
        }
Example #3
0
        private bool IsValidPlayMove(Point startPoint, Point endPoint, CellData activePiece)
        {
            throw new NotImplementedException("IsValidPlayMove not implemented yet");

            //only dark cells
            if (!_darkCells.Contains(endPoint))
            {
                return(false);
            }

            //only free cells
            if (Pieces.Any(x => x.Pos.Equals(endPoint) && !x.IsHighlight))
            {
                return(false);
            }

            //men only move forward
            if (activePiece.Type == PieceType.Man)
            {
                //white - up
                if (activePiece.Player == Player.White)
                {
                    if (startPoint.Y <= endPoint.Y)
                    {
                        return(false);
                    }
                }
                //black - down
                else
                {
                    if (startPoint.Y >= endPoint.Y)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Example #4
0
        /// <summary>
        /// Checks if Man can find a capture on the given diagonal
        /// </summary>
        /// <param name="diagonaleCells"></param>
        /// <param name="opponent"></param>
        /// <param name="endPoint"></param>
        /// <param name="takenPoint"></param>
        /// <param name="taken"></param>
        /// <param name="originalPosition"></param>
        /// <returns></returns>
        private bool CanManCaptureDiagonale(List <Point> diagonaleCells, Player opponent,
                                            out Point?endPoint, out Point?takenPoint,
                                            List <Point> taken, Point originalPosition)
        {
            endPoint   = null;
            takenPoint = null;

            //nearest is opponent and next is free
            bool nearestIsOpponent = Pieces.Any(x => x.Pos.Equals(diagonaleCells[0]) && !x.IsHighlight && x.Player == opponent);
            bool nextIsEmpty       = !Pieces.Any(x => x.Pos.Equals(diagonaleCells[1]) && !x.IsHighlight) ||
                                     (diagonaleCells[1].Equals(originalPosition));//original position shuold be empty at the time of move

            bool isNotTakenYet = !taken.Contains(diagonaleCells[0]);

            bool can = nearestIsOpponent && nextIsEmpty && isNotTakenYet;

            if (can)
            {
                endPoint   = diagonaleCells[1];
                takenPoint = diagonaleCells[0];
            }

            return(can);
        }
Example #5
0
 public bool TurnIsOver()
 {
     return(!Pieces.Any(p => p.WaitingForMove));
 }
Example #6
0
 public bool IsEmpty(BoardPosition pos) => !Pieces.Any(p => p.Position == pos);