Beispiel #1
0
        void InitializeCheckerboard()
        {
            IMoveStrategy pawnMoveStrategy   = new PawnMoveStrategy();
            IMoveStrategy bishopMoveStrategy = new BishopMoveStrategy();
            IMoveStrategy knightMoveStrategy = new KnightMoveStrategy();
            IMoveStrategy rookMoveStrategy   = new RookMoveStrategy();
            IMoveStrategy kingMoveStrategy   = new KingMoveStrategy();
            IMoveStrategy queenMoveStrategy  = new QueenMoveStrategy();

            MainCheckerboard = new Checkerboard(new List <Pawn>()
            {
                new Pawn(new Position('h', 8), PawnColor.White, PawnType.King, kingMoveStrategy),
                new Pawn(new Position('h', 1), PawnColor.Black, PawnType.King, kingMoveStrategy),

                new Pawn(new Position('f', 6), PawnColor.White, PawnType.Pawn, pawnMoveStrategy),
                new Pawn(new Position('c', 3), PawnColor.White, PawnType.Pawn, pawnMoveStrategy),

                new Pawn(new Position('d', 4), PawnColor.Black, PawnType.Bishop, bishopMoveStrategy),
                new Pawn(new Position('e', 4), PawnColor.White, PawnType.Bishop, bishopMoveStrategy),

                new Pawn(new Position('e', 2), PawnColor.Black, PawnType.Knight, knightMoveStrategy),

                new Pawn(new Position('c', 6), PawnColor.Black, PawnType.Rook, rookMoveStrategy),

                new Pawn(new Position('a', 7), PawnColor.White, PawnType.Queen, queenMoveStrategy),
                new Pawn(new Position('e', 5), PawnColor.Black, PawnType.Queen, queenMoveStrategy),
            });

            var pieces = MainCheckerboard.GetAllPawns();

            PiecesOnBoard.Text = $"Pawns: {pieces.Count()}{Environment.NewLine}{Environment.NewLine}";

            foreach (var pawn in pieces)
            {
                PiecesOnBoard.Text += $"{pawn.PawnColor} {pawn.PawnType}, {pawn.Position.Letter}{pawn.Position.Digit},{Environment.NewLine}";
                var moves = pawn.GetAvailableMoves(MainCheckerboard);
                if (moves?.Any() == true)
                {
                    PiecesOnBoard.Text += $"Moves: ";
                    foreach (var move in moves)
                    {
                        PiecesOnBoard.Text += $"{move.NewPawnPos.Letter}{move.NewPawnPos.Digit}, ";
                    }
                    var takes = pawn.GetAvailableTakes(moves);
                    if (takes?.Any() == true)
                    {
                        PiecesOnBoard.Text += $"{Environment.NewLine}Takes: ";
                        foreach (var move in takes)
                        {
                            PiecesOnBoard.Text += $"{move.NewPawnPos.Letter}{move.NewPawnPos.Digit}, ";
                        }
                    }
                }
                PiecesOnBoard.Text += Environment.NewLine;
                PiecesOnBoard.Text += Environment.NewLine;
            }
        }
Beispiel #2
0
        static IEnumerable <Pawn> GetInitialPawns()
        {
            IMoveStrategy pawnMoveStrategy   = new PawnMoveStrategy();
            IMoveStrategy bishopMoveStrategy = new BishopMoveStrategy();
            IMoveStrategy knightMoveStrategy = new KnightMoveStrategy();
            IMoveStrategy rookMoveStrategy   = new RookMoveStrategy();
            IMoveStrategy kingMoveStrategy   = new KingMoveStrategy();
            IMoveStrategy queenMoveStrategy  = new QueenMoveStrategy();

            for (int x = 0; x < 8; x++)
            {
                yield return(new Pawn(new Position((char)x, 1), PawnColor.White, PawnType.Pawn, pawnMoveStrategy));

                yield return(new Pawn(new Position((char)x, 6), PawnColor.Black, PawnType.Pawn, pawnMoveStrategy));
            }

            yield return(new Pawn(new Position(0, 0), PawnColor.White, PawnType.Rook, rookMoveStrategy));

            yield return(new Pawn(new Position(7, 0), PawnColor.White, PawnType.Rook, rookMoveStrategy));

            yield return(new Pawn(new Position(0, 7), PawnColor.Black, PawnType.Rook, rookMoveStrategy));

            yield return(new Pawn(new Position(7, 7), PawnColor.Black, PawnType.Rook, rookMoveStrategy));

            yield return(new Pawn(new Position(1, 0), PawnColor.White, PawnType.Knight, knightMoveStrategy));

            yield return(new Pawn(new Position(6, 0), PawnColor.White, PawnType.Knight, knightMoveStrategy));

            yield return(new Pawn(new Position(1, 7), PawnColor.Black, PawnType.Knight, knightMoveStrategy));

            yield return(new Pawn(new Position(6, 7), PawnColor.Black, PawnType.Knight, knightMoveStrategy));

            yield return(new Pawn(new Position(2, 0), PawnColor.White, PawnType.Bishop, bishopMoveStrategy));

            yield return(new Pawn(new Position(5, 0), PawnColor.White, PawnType.Bishop, bishopMoveStrategy));

            yield return(new Pawn(new Position(2, 7), PawnColor.Black, PawnType.Bishop, bishopMoveStrategy));

            yield return(new Pawn(new Position(5, 7), PawnColor.Black, PawnType.Bishop, bishopMoveStrategy));

            yield return(new Pawn(new Position(3, 0), PawnColor.White, PawnType.Queen, queenMoveStrategy));

            yield return(new Pawn(new Position(3, 7), PawnColor.Black, PawnType.Queen, queenMoveStrategy));

            yield return(new Pawn(new Position(4, 0), PawnColor.White, PawnType.King, kingMoveStrategy));

            yield return(new Pawn(new Position(4, 7), PawnColor.Black, PawnType.King, kingMoveStrategy));
        }