Beispiel #1
0
        //
        // Summary:
        //     The basic constructor of a DraughtsMatch.s
        public DraughtsMatch()
        {
            //
            // Place the red pieces in their initial positions and place the piece in a collection.
            for (int arrRow = 0; arrRow <= 3; arrRow++)
            {
                //
                // Explanation about the value to be assigned to arrColumn variable:
                //
                // Arrray's odd lines will have their frist pieces in column 0,
                // while Even lines will have the frist pieces in the array column 1.
                for (int arrColumn = 1 - arrRow % 2; arrColumn < Board.Width; arrColumn += 2)
                {
                    Board.PlacePiece(
                        new Pawn(new TwoDimensionsArrayPosition(arrRow, arrColumn).ToBoardPosition(Board.Height), Board, Team.Red),
                        new TwoDimensionsArrayPosition(arrRow, arrColumn).ToBoardPosition(Board.Height));

                    RedPieces.Add(Board.Pieces(arrRow, arrColumn));
                }
            }

            //
            // Place the white pieces in their initial positions and place the piece in a collection.
            for (int arrRow = 6; arrRow < Board.Height; arrRow++)
            {
                //
                // Explanation about the value to be assigned to arrColumn variable:
                //
                // Arrray's odd lines will have their frist pieces in column 0,
                // while Even lines will have the frist pieces in the array column 1.
                for (int arrColumn = 1 - arrRow % 2; arrColumn < Board.Width; arrColumn += 2)
                {
                    Board.PlacePiece(
                        new Pawn(new TwoDimensionsArrayPosition(arrRow, arrColumn).ToBoardPosition(Board.Height), Board, Team.White),
                        new TwoDimensionsArrayPosition(arrRow, arrColumn).ToBoardPosition(Board.Height));

                    WhitePieces.Add(Board.Pieces(arrRow, arrColumn));
                }
            }

            Round      = 1;
            TurnPlayer = Team.White;
        }
Beispiel #2
0
        //
        // Summary:
        //     Make the move, this also includes catching a possible piece in the process.
        //
        // Parameters:
        //   origin:
        //     The piece that will make its move.
        //
        //   target:
        //     The position of the final destination of the Piece origin.
        public void MakeMovement(Piece origin, BoardPosition target)
        {
            TwoDimensionsArrayPosition originArrPos = origin.BoardPosition.ToArrayPosition(Board.Height);
            TwoDimensionsArrayPosition targetArrPos = target.ToArrayPosition(Board.Height);

            // If the target results in a capture
            if (Math.Abs(originArrPos.Row - targetArrPos.Row) >= 2)
            {
                // The 'P' represents a piece, not a Pawn itself or a Dame, and the 'E' an enemy piece.
                //
                // 4---1
                // -E-E-
                // --P--
                // -E-E-
                // 3---2

                TwoDimensionsArrayPosition piece2BCapPos;
                // Locate and set the position of the piece to be captured
                if ((originArrPos.Column - targetArrPos.Column) <= -2) // NE && SE
                {
                    if ((originArrPos.Row - targetArrPos.Row) >= 2)    // NE (1)
                    {
                        piece2BCapPos = new TwoDimensionsArrayPosition(targetArrPos.Row + 1, targetArrPos.Column - 1);
                    }
                    else // SE (2)
                    {
                        piece2BCapPos = new TwoDimensionsArrayPosition(targetArrPos.Row - 1, targetArrPos.Column - 1);
                    }
                }
                else // SW && NW
                {
                    if ((originArrPos.Row - targetArrPos.Row) <= -2) // SW (3)
                    {
                        piece2BCapPos = new TwoDimensionsArrayPosition(targetArrPos.Row - 1, targetArrPos.Column + 1);
                    }
                    else // NW (4)
                    {
                        piece2BCapPos = new TwoDimensionsArrayPosition(targetArrPos.Row + 1, targetArrPos.Column + 1);
                    }
                }


                if (TurnPlayer == Team.Red)
                {
                    WhitePieces.Remove(Board.TakePiece(piece2BCapPos));
                }
                else
                {
                    RedPieces.Remove(Board.TakePiece(piece2BCapPos));
                }

                // Take the origin from the board and place it in the target
                Board.PlacePiece(Board.TakePiece(origin.BoardPosition), target);
            }
            else
            {
                // Take the origin from the board and place it in the target
                Board.PlacePiece(Board.TakePiece(origin.BoardPosition), target);
            }

            // If the Red pawn or a White pawn is in its promotion area it'll be promoted
            switch (Board.Pieces(target))
            {
            case Pawn _ when Board.Pieces(target).Team == Team.Red && target.Row == 1:
            case Pawn _ when Board.Pieces(target).Team == Team.White && target.Row == 10:
                Promotion(Board.Pieces(target) as Pawn);

                break;
            }
        }