View about_scoring_project.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require File.expand_path(File.dirname(__FILE__) + '/edgecase') | |
# Greed is a dice game where you roll up to five dice to accumulate | |
# points. The following "score" function will be used calculate the | |
# score of a single roll of the dice. | |
# | |
# A greed roll is scored as follows: | |
# | |
# * A set of three ones is 1000 points | |
# |
View greed.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Greed | |
# Greed is a dice game where you roll up to five dice to accumulate | |
# points. The following "score" function will be used calculate the | |
# score of a single roll of the dice. | |
# | |
# A greed roll is scored as follows: | |
# | |
# * A set of three ones is 1000 points | |
# | |
# * A set of three numbers (other than ones) is worth 100 times the |
View gist:894370
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def run | |
game_setup | |
run_the_game | |
restart while play_again? | |
rescue Exception | |
exit | |
end |
View gist:894373
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def game_setup | |
@player_one = setup_player(PLAYER_ONE,DEFAULT_PLAYER_ONE_MARK) | |
@player_two = setup_player(PLAYER_TWO,DEFAULT_PLAYER_TWO_MARK) | |
@board = Board.new(@player_one, @player_two) | |
end |
View gist:901565
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AIFactory | |
def create_ai(ai_type) | |
if ai_type == :unbeatable | |
ai = Minimax.new | |
elsif ai_type == :easy | |
ai = Random.new | |
end | |
ai | |
end | |
end |
View gist:901578
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UnbeatableFactory | |
def self.create | |
Minimax.new | |
end | |
end | |
class EasyFactory | |
def self.create | |
Random.new | |
end |
View gist:945540
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% chart = Gchart.bar( | |
# see http://code.google.com/apis/chart/docs/gallery/bar_charts.html for Google Charts API bar chart info | |
# | |
:grouped => 'true', | |
:bar_colors => "D6A061,331F08", | |
:bar_width_and_spacing => 'a,5,30', # bar width, spacing width, group spacing width | |
:size => '700x400', | |
:title => "Expected vs Actual Velocity", | |
:bg => 'FFFFFF00', # transparent | |
:legend => ['Expected', 'Actual'], |
View gist:963639
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<table class="board"> | |
<tr> | |
<%= render :partial => 'games/square', :locals => {:location => '0'}%> | |
<%= render :partial => 'games/square', :locals => {:location => '1'}%> | |
<%= render :partial => 'games/square', :locals => {:location => '2'}%> | |
</tr> | |
<tr> | |
<%= render :partial => 'games/square', :locals => {:location => '3'}%> | |
<%= render :partial => 'games/square', :locals => {:location => '4'}%> | |
<%= render :partial => 'games/square', :locals => {:location => '5'}%> |
View gist:963641
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe "games/_board.html.erb" do | |
before(:each) do | |
@ttt = mock(TicTacToe) | |
stub_template "games/_square.html.erb" => "<square/>" | |
end | |
it "displays 9 squares for a 3x3 board" do | |
render |
View gist:963645
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<td class="square"> | |
<% if @ttt.square_empty?(location.to_i) && @ttt.in_progress? %> | |
<%= submit_tag(location, :class => "square", :name => "location") %> | |
<% elsif !@ttt.square_empty?(location.to_i) %> | |
<%= @ttt.get_square_value(location.to_i) %> | |
<% elsif !(@ttt.in_progress?) %> | |
<% end%> | |
</td> |
OlderNewer