Skip to content

Instantly share code, notes, and snippets.

@mikeebert
mikeebert / changekata_spec.rb
Created March 19, 2012 21:35
Coin Changer Kata
# Spec Step 1
describe CoinChanger do
it "should return a penny" do
CoinChanger.make_change(1).should == %w(p)
end
end
# Class Step 1 - after failed uninitialized constant, failed no method errors, failed wrong number of arguments and
# failed 'got nil expected ["p"]'
class CoinChanger
@mikeebert
mikeebert / gist:2410700
Created April 18, 2012 02:31
n queens loop
def coordinates_for_next_move
while attackable(@row,@column)
@column += 1 if @column < @size
while @column >= @size
@row = @positions.last[0]
@column = @positions.last[1] + 1
@positions.delete_at(@positions.count - 1)
end
end
place_next_queen
<div class="gist">https://gist.github.com/#INSERT GIST NUMBER HERE#</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script src="http://static.tumblr.com/fpifyru/VCxlv9xwi/writecapture.js"></script>
<script src="http://static.tumblr.com/fpifyru/AKFlv9zdu/embedgist.js"></script>
@mikeebert
mikeebert / gist:2725858
Created May 18, 2012 15:26
Unrefactored Minimax score and players
def set_min_and_max_players(board)
if board.next_player == :player1
@max_symbol = board.player1_symbol
@max_player = :player1
@min_symbol = board.player2_symbol
@min_player = :player2
elsif board.next_player == :player2
@max_symbol = board.player2_symbol
@max_player = :player2
@min_symbol = board.player1_symbol
@mikeebert
mikeebert / gist:2725900
Created May 18, 2012 15:36
Minimax Players
class MinimaxPlayer
attr_accessor :symbol, :starting_score
def initialize(symbol, score)
@symbol = symbol
@starting_score = score
end
end
class MinPlayer < MinimaxPlayer
def compare(best_score,new_score)
@mikeebert
mikeebert / gist:2726071
Created May 18, 2012 16:07
Refactored Minimax
def set_min_and_max_players(board)
@max = MaxPlayer.new(board.next_player_symbol, -50)
@min = MinPlayer.new(board.opponent_symbol, 50)
end
def minimax_score(board)
score = game_value(board)
return score unless score == -1 #-1 means a game is still in progress
player = set_player(board.next_player_symbol)
best_score = player.starting_score
require 'board'
class Game
attr_accesor :ui, :board
def initialize(ui)
@ui = ui
@board = Board.new(3)
end
end
@mikeebert
mikeebert / gist:2951966
Created June 19, 2012 02:25
sinatra cucumber env.rb file configuration
#where foundry below is the name of your main app file
require File.join(File.expand_path(File.dirname(__FILE__)),'../../foundry')
require "Capybara"
require "Capybara/cucumber"
require "rspec"
World do
Capybara.app = Foundry #where Foundry is the class in your main app file
@mikeebert
mikeebert / gist:2952016
Created June 19, 2012 02:43
Sinatra Rspec spec_helper (also using cucumber)
require File.join(File.expand_path(File.dirname(__FILE__)), '/../', 'foundry')
require 'sinatra'
require 'rack/test'
set :environment, :test
#specify that the app is a Sinatra app
def app
Sinatra::Application