Skip to content

Instantly share code, notes, and snippets.

@rachaelsalter
Created October 20, 2015 02:53
Show Gist options
  • Save rachaelsalter/c5ffe4ebfeb045725fe4 to your computer and use it in GitHub Desktop.
Save rachaelsalter/c5ffe4ebfeb045725fe4 to your computer and use it in GitHub Desktop.
Valid move for Pawn logic
class Pawn < Piece
def valid_move?(x,y)
#First move. Allowed to move 1 or 2 spaces.
if self.x_position #how to say this is the first move??
return false if (self.x_position - x).abs > 2 || (self.y_position - y).abs > 2
#All moves. Allowed to move 1 space.
return false if (self.x_position - x).abs > 1 || (self.y_position - y).abs > 1
#Up 1 and horizonal to capture.
#Cannot capture vertically.
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment