Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Knight#valid_move? could potentially be simplified #53

Open
olleicua opened this issue Mar 11, 2017 · 0 comments
Open

Knight#valid_move? could potentially be simplified #53

olleicua opened this issue Mar 11, 2017 · 0 comments
Assignees

Comments

@olleicua
Copy link

I think the approach you have used here makes more sense for the knight than it does for the king but I think there might still be a simpler way. It's up to you how you want to do this but consider the following:

class Knight
  def valid_move?(x, y)
    dx = (x_position - x).abs
    dy = (y_position - y).abs

    super(x, y) && [dx, dy].sort == [1, 2]
  end
end

Also you don't need to call within_chessboard? as that is covered by super

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants