public static List <IChinesePiece> GetBetween(this IChinesePiece piece, IChinesePiece another, Chessboard chessboard) { var pos1 = chessboard.FindPos(piece); var pos2 = chessboard.FindPos(another); var list = new List <IChinesePiece>(); if (pos1.Valid() && pos2.Valid()) { if (pos1 == pos2) { return(list); } if (pos1.X == pos2.X) { var x = pos1.X; for (var i = (pos1.Y > pos2.Y ? pos2 : pos1).Y + 1; i < (pos1.Y > pos2.Y ? pos1 : pos2).Y; i++) { var currentPiece = chessboard.GetPiece(new Point(x, i)); if (currentPiece.NotEmptyPiece()) { list.Add(currentPiece); } } } else if (pos1.Y == pos2.Y) { var y = pos1.Y; for (var i = (pos1.X > pos2.X ? pos2 : pos1).X; i < (pos1.X > pos2.X ? pos1 : pos2).X; i++) { var currentPiece = chessboard.GetPiece(new Point(i, y)); if (currentPiece.NotEmptyPiece()) { list.Add(currentPiece); } } } return(list); } throw new InvalidOperationException(); }