private void MoveKing(int x_white, int y_white, int fileIndex, int rankIndex, Board board, HashSet <string> positions) { int x = IsWhite ? x_white : -x_white; int y = IsWhite ? y_white : -y_white; Field newField = board[fileIndex + x][rankIndex + y]; ControlledSquares.Add(newField.Name); if (newField.Content == null) { if (KingNewPositionIsSafe(newField.Name, board)) { positions.Add(newField.Name); } } else { bool z = IsWhite ? !(newField.Content.IsWhite) : newField.Content.IsWhite; if (z && newField.Content.GetType() != typeof(King)) { if (KingNewPositionIsSafe(newField.Name, board)) { positions.Add(newField.Name); } } } }
public void MoveOne(int x_white, int y_white, ref int file, ref int rank, ref bool canMove, ref bool kingInTheWay, Board board, HashSet <string> positions) { int x = IsWhite ? x_white : -x_white; int y = IsWhite ? y_white : -y_white; Field newField = board[file + x][rank + y]; ControlledSquares.Add(newField.Name); if (newField.Content == null) { if (!kingInTheWay) { positions.Add(newField.Name); } file += x; rank += y; } else { bool z = IsWhite ? !(newField.Content.IsWhite) : newField.Content.IsWhite; if (z) { if (newField.Content.GetType() != typeof(King)) { if (!kingInTheWay) { positions.Add(newField.Name); } canMove = false; } else { if (IsWhite) { Program.Game.BlackKingIsInCheck = true; } else { Program.Game.WhiteKingIsInCheck = true; } Program.Game.CurrentPlayerPiecesAttackingTheKing.Add(this); kingInTheWay = true; file += x; rank += y; } } else { canMove = false; } } }
private void MovePawn(int x_white, int y_white, int fileIndex, int rankIndex, Board board, HashSet <string> positions) { int x = IsWhite ? x_white : -x_white; int y = IsWhite ? y_white : -y_white; Field newField = board[fileIndex + x][rankIndex + y]; if (x_white == 0) { if (y_white == 2) { int z = IsWhite ? -1 : 1; if ((board[fileIndex][rankIndex + y + z].Content == null) && (newField.Content == null)) { positions.Add(newField.Name); } } if (y_white == 1) { if (newField.Content == null) { positions.Add(newField.Name); } } } if ((x_white == -1 || x_white == 1) && y_white == 1) { ControlledSquares.Add(newField.Name); if (newField.Content != null) { bool z = IsWhite ? !(newField.Content.IsWhite) : newField.Content.IsWhite; if (z) { if (newField.Content.GetType() != typeof(King)) { positions.Add(newField.Name); } else { if (IsWhite) { Program.Game.BlackKingIsInCheck = true; } else { Program.Game.WhiteKingIsInCheck = true; } Program.Game.CurrentPlayerPiecesAttackingTheKing.Add(this); } } } } }