public void AddRook(Color color) { while (true) { Console.Write($"Podaj pozycje wiezy o kolorze {color}: "); string consoleNotationPosition = Console.ReadLine(); if (consoleNotationPosition.Length == 2) { int? x = ToProgramNotation.FromX(consoleNotationPosition[0]); int? y = ToProgramNotation.FromY(consoleNotationPosition[1]); Piece rook; if (x != null && y != null) { rook = new Rook(new Position(x.Value, y.Value), color); Board hipoteticalBoard = this.DeepCopy(); hipoteticalBoard.pieces.Add(rook); if (ReturnPieceByPosition(rook.position) == null && !hipoteticalBoard.IsCheck(ColorControl.OppositeColor(color))) { pieces.Add(rook); break; } } } } }
public Move?ReturnMoveFromConsoleNotation(string consoleNotation) { char charStartX, charStartY, charEndX, charEndY; if (consoleNotation.Length == 5) //normal (mine) notation { charStartX = consoleNotation[0]; charStartY = consoleNotation[1]; charEndX = consoleNotation[3]; charEndY = consoleNotation[4]; } else if (consoleNotation.Length == 4) //shorter notation { charStartX = consoleNotation[0]; charStartY = consoleNotation[1]; charEndX = consoleNotation[2]; charEndY = consoleNotation[3]; } else { return(null); } int?startX, startY, endX, endY; startX = ToProgramNotation.FromX(charStartX); startY = ToProgramNotation.FromY(charStartY); endX = ToProgramNotation.FromX(charEndX); endY = ToProgramNotation.FromY(charEndY); if (startX == null || startY == null || endX == null || endY == null) { return(null); } Position startPosition = new Position((int)startX, (int)startY); Position endPosition = new Position((int)endX, (int)endY); Piece? piece = ReturnPieceByPosition(startPosition); if (piece != null) { return(new Move(piece, endPosition)); } return(null); }
public void AddKing(Color color) { while (true) { Console.Write($"Podaj pozycje krola o kolorze {color}: "); string consoleNotationPosition = Console.ReadLine(); if (consoleNotationPosition.Length == 2) { int? x = ToProgramNotation.FromX(consoleNotationPosition[0]); int? y = ToProgramNotation.FromY(consoleNotationPosition[1]); List <Position> attackedPositions = AllAttackedPositions(ColorControl.OppositeColor(color)); if (x != null && y != null) { Position position = new Position(x.Value, y.Value); if (ReturnPieceByPosition(position) == null && !attackedPositions.Contains(position)) { pieces.Add(new King(new Position(x.Value, y.Value), color)); break; } } } } }