Skip to content

Instantly share code, notes, and snippets.

class PBJ
attr_accessor :pbutter, :jelly
def initialize(pbutter, jelly)
@pbutter = pbutter
@jelly = jelly
end
def make
puts "Spread #{@pbutter} peanut butter and #{@jelly} jelly on bread. Bam!"
@rachaelsalter
rachaelsalter / king.rb
Created October 9, 2015 18:21
valid_move? King
class King < Piece
def self.type
where(type: 'king')
end
def valid_move?(x, y)
# King can move one square at a time in any direction. Move not valid if current position - new position
# is greater than the absolute value of 1.
return false if (self.x_position - x).abs > 1 || (self.y_position - y).abs > 1
@rachaelsalter
rachaelsalter / valid_move_pawn.rb
Created October 20, 2015 02:53
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.
@rachaelsalter
rachaelsalter / valid_move_pawn2.rb
Created October 29, 2015 01:19
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