Beispiel #1
0
        public string PrintBoard()
        {
            const int dimX = 5;
            const int dimY = 5;

            var stringBuilder = new StringBuilder();

            //upper board deliminations
            stringBuilder.Append(" + ");
            for (var i = 0; i < dimX; i++)
            {
                stringBuilder.Append($" {i} ");
            }

            stringBuilder.Append(" + ");
            stringBuilder.Append("\n");

            // board
            for (var y = dimY - 1; y >= 0; y--)
            {
                stringBuilder.Append($" {y} ");
                for (var x = 0; x < dimX; x++)
                {
                    var piece = Pieces.Find(p => p.PositionOnBoard.X == x && p.PositionOnBoard.Y == y);
                    if (piece == null)
                    {
                        stringBuilder.Append(" . ");
                        continue;
                    }

                    var marking = piece.Type == PieceTypeEnum.Pawn ? "p" : "k";
                    if (piece.Owner == CurrentlyPlaying)
                    {
                        marking = marking.ToUpper();
                    }

                    stringBuilder.Append($" {marking} ");
                }

                stringBuilder.Append($" {y} ");
                stringBuilder.Append("\n");
            }

            //lower board deliminations
            stringBuilder.Append(" + ");
            for (var i = 0; i < dimX; i++)
            {
                stringBuilder.Append($" {i} ");
            }

            stringBuilder.Append(" + ");
            stringBuilder.Append("\n");

            return(stringBuilder.ToString());
        }
Beispiel #2
0
        public bool HaveACheck()
        {
            var piece = Pieces.Find(x => x.IsKing());

            return(piece.IsInCheck());
        }