Skip to content

Instantly share code, notes, and snippets.

@mscoutermarsh
Forked from rachaelsalter/valid_move_pawn2.rb
Created October 29, 2015 18:29
Show Gist options
  • Save mscoutermarsh/3ef41e8d46db5cdbae8f to your computer and use it in GitHub Desktop.
Save mscoutermarsh/3ef41e8d46db5cdbae8f to your computer and use it in GitHub Desktop.
Valid_move_pawn2
class Pawn < Piece
def first_move?(y)
#Allowed to move 1 or 2 spaces.
if (color: :white && y_position: 1) || (color: :black && y_position: 6)
return true
if (y_position - y) < 3
else
return false
end
end
end
def all_moves?
#Allowed to move 1 space only.
return false if (x_position - x).abs > 1 || (y_position - y).abs > 1
end
end
#Up 1 and horizonal to capture.
#Cannot capture vertically.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment