Skip to content

Instantly share code, notes, and snippets.

View kenmazaika's full-sized avatar

ken mazaika kenmazaika

View GitHub Profile
@kenmazaika
kenmazaika / README.md
Last active August 29, 2015 14:20
How `is_obstructed?` Should Work

Board

Note: I'm using standard chess notation to describe the action at a high level. You will use your standard x/y 0-7 notation. Below is not valid code, but merely used to communicate the idea.

is_obstructed? A6 -> C4 => false
is_obstructed? F1 -> D3 => true
is_obstructed? A1 -> A4 => true
is_obstructed? D4 -> B5 => Raise an Error Message # invalid input.  Not diagnal, horizontal, or vertical.
is_obstructed? A8 -> A6 => false # note: this is not an obstruction. This has a piece in the destination, but not in between the pieces.
@kenmazaika
kenmazaika / game.rb
Created May 6, 2015 18:45
Populate the Board of a Chess Game
class Game < ActiveRecord::Base
# all the associations, etc.
after_create :populate_board!
def populate_board!
# this should create all 32 pieces with their initial X/Y coordinates.
end
end
class Card
attr_accessor :rank, :suit
def initialize(rank, suit)
self.rank = rank
self.suit = suit
end
def output_card
puts "#{self.rank} of #{self.suit}"
def kid_eat(food)
veggies = ["Lettuce", "Carrot", "Broccoli", "Onion"]
fruits = ["Apple", "orange", "Mango", "Pineapple"]
if veggies.include?(food)
4.times do
puts "Gross, I hate #{food}"
end
elsif fruits.include?(food)
puts "How about we a make a smoothie with #{food}?"
class Card
attr_accessor :rank, :suit
def initialize(rank, suit)
@rank = rank
@suit = suit
end
def output_card
puts "#{self.rank} of #{self.suit}"
class Card
attr_accessor :rank, :suit
def initialize(rank, suit)
@rank = rank
@suit = suit
end
def output_card
puts "#{self.rank} of #{self.suit}"
class Card
attr_accessor :rank, :suit
def initialize(rank, suit)
@rank = rank
@suit = suit
end
def output_card
puts "#{self.rank} of #{self.suit}"
def reverse_list!(head, previous_element = nil)
next_iter = head.next_element # keep track of next iteration step
head.next_element = previous_element # flip-flip list pointer
return head if next_iter.nil? # return results accumulator if done
reverse_list!(next_iter, head) # otherwise, recursive traversal
end
require 'rubygems'
require 'cowsay'
puts Cowsay::Character::Cow.say "Thumbs Up, You're Awesome!"
puts
puts "-------------------------------"
sleep(3)
puts Cowsay::Character::Cow.say "I mean MOOOOO!"
class Node
attr_accessor :value, :next_node
def initialize(value, next_node)
@value = value
@next_node = next_node
end
def print_values
print "#{self.value}-->"