public Move ParseMove(string san) { if (!(san.Length == 4 || san.Length == 2)) { return(null); } char[] sanChars = san.ToCharArray(); int moveShift = CurrentPlayer.Color == Color.White ? -1 : 1; int xIndex = sanChars[1] == 'x' ? 2 : 0; int finishX = sanChars[xIndex] - 'a'; int finishY = sanChars[xIndex + 1] - '1'; int startY = finishY + moveShift; int startX = finishX; if (startX < 0 || startX > Board.c_MAX_INDEX || startY < 0 || startY > Board.c_MAX_INDEX || finishX < 0 || finishX > Board.c_MAX_INDEX || finishY < 0 || finishY > Board.c_MAX_INDEX) { return(null); } Square finishSquare = Board.GetSquare(finishX, finishY); Square startSquare = Board.GetSquare(startX, startY); if (sanChars.Length == 4 && sanChars[1] == 'x') { startX = sanChars[0] - 'a'; startSquare = Board.GetSquare(startX, startY); if (SquareOccupiedByCurrentPlayer(startX, startY)) { if (SquareOccupiedByOtherPlayer(finishX, finishY)) { return(new Move(startSquare, finishSquare, true, false)); } else if (LastMove != null && LastMove.IsLong && SquareOccupiedByOtherPlayer(finishX, startY)) { return(new Move(startSquare, finishSquare, true, true)); } } return(null); } if (SquareOccupiedByCurrentPlayer(startX, startY)) { return(new Move(startSquare, finishSquare)); } else { int possibleY = CurrentPlayer.Color == Color.White ? 1 : Board.c_MAX_INDEX - 1; int actualY = finishY + (moveShift << 1); if (actualY >= 0 && actualY < Board.c_MAX_COORDINATE) { startSquare = Board.GetSquare(startX, actualY); if (actualY == possibleY && startSquare.IsOccupiedBy(CurrentPlayer.Color)) { return(new Move(startSquare, finishSquare)); } } } return(null); }
public static bool ValidSquare(Square x) { return(x.X >= 0 && x.X < Board.c_MaxCoord && x.Y >= 0 && x.Y < Board.c_MaxCoord); }
public static bool CheckSimpleCapture(Square to, Color playerColor) => (to.Color == playerColor.Inverse());
public static bool CheckForwardMove(Square to) => to.Color == Color.None;
public Move(Square from, Square to) : this(from, to, false, false) { }