private bool CanMoveKnight(FigureModel figure, Vector to) { var x = Math.Abs(figure.Position.X - to.X); var y = Math.Abs(figure.Position.Y - to.Y); if (x == 2 && y == 1 || x == 1 && y == 2) { return(true); } return(false); }
//Fixed private bool CanMoveQueen(FigureModel figure, Vector to) { if (Math.Abs(figure.Position.X - to.X) == Math.Abs(figure.Position.Y - to.Y)) { return(CanMoveBishop(figure, to)); } else { return(CanMoveRook(figure, to)); } }
//Fixed private bool CanMoveBishop(FigureModel figure, Vector to) { for (byte i = 1; i <= Math.Abs(figure.Position.X - to.X); i++) { if ((figure.Position.X + i == to.X && figure.Position.Y + i == to.Y) || (figure.Position.X - i == to.X && figure.Position.Y - i == to.Y) || (figure.Position.X + i == to.X && figure.Position.Y - i == to.Y) || (figure.Position.X - i == to.X && figure.Position.Y + i == to.Y)) { return(true); } } return(false); }
public SquareModel(FigureModel figure) { this.Position = figure.Position; this.Figure = figure; }