Source

puzzle_nodes / 13 / lib / pawn.rb

Full commit
class Pawn < Piece
  moves :forward, 1
  moves :forward, 2, :when => :first_move
  captures :diagonally_forward, 1
end

class Rook
  moves :forward
  moves :backward
  moves :sideways
  captures :forward
  captures :backward
  captures :sideways
end

class Bishop
  moves :diagonally_forward
  moves :diagonally_backward
  captures :diagonally_forward
  captures :diagonally_backward
end

class King
  moves :forward, 1, :when => :avoids_check
  moves :backward, 1, :when => :avoids_check
  moves :sideways, 1, :when => :avoids_check
  moves :diagonally_forward, 1, :when => :avoids_check
  moves :diagonally_backward, 1, :when => :avoids_check
  moves :forward, 1, :when => :avoids_check
  moves :backward, 1, :when => :avoids_check
  moves :sideways, 1, :when => :avoids_check
  moves :diagonally_forward, 1, :when => :avoids_check
  moves :diagonally_backward, 1, :when => :avoids_check
end

class Queen
  moves :forward
  moves :backward
  moves :diagonally_forward
  moves :diagonally_backward

  captures :forward
  captures :backward
  captures :diagonally_forward
  captures :diagonally_backward
end

class Knight
  jumps :forward, 2, :then => [:sideways, 3]
  jumps :backward, 2, :then => [:sideways, 3]
  jumps :forward, 2, :then => [:sideways, 2]
  jumps :backward, 3, :then => [:sideways, 2]
end