-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
panda, tiger, eagle levels #15
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
require_relative "move" | ||
class Turn | ||
attr_reader :winner | ||
def initialize(move_a, move_b) | ||
@move_a = move_a | ||
@move_b = move_b | ||
@winner = determine_winner | ||
attr_reader :fighter_a_move, :fighter_b_move | ||
def initialize(fighter_a, fighter_b) | ||
@fighter_a = fighter_a | ||
@fighter_b = fighter_b | ||
@fighter_a_move = [@fighter_a.strike, @fighter_a.block].sample | ||
@fighter_b_move = [@fighter_b.strike, @fighter_b.block].sample | ||
end | ||
|
||
private | ||
def determine_winner | ||
[@move_a, @move_b].sample | ||
end | ||
def tie | ||
[@fighter_a, @fighter_b].sample | ||
end | ||
|
||
def winner | ||
return tie if @fighter_a_move.type == :block and @fighter_b_move.type == :block | ||
@fighter_a_move.ranking > @fighter_b_move.ranking ? @fighter_a : @fighter_b | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
require 'rspec' | ||
require_relative "../lib/match" | ||
require_relative "../lib/turn" | ||
|
||
|
||
describe Match do | ||
let(:bob) { Fighter.new("bob") } | ||
|
@@ -27,4 +29,9 @@ | |
subject.stub(:winner_count_for_opponent).with(fred) {10} | ||
subject.winner.should eq(fred) | ||
end | ||
|
||
it 'should output the winner of each turn' do | ||
fixed_match = Match.new(bob, bob) | ||
expect(fixed_match.replay[0..1]).to eq(["Round 1 -- bob won!", "Round 2 -- bob won!"]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lol. way to go bob! |
||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
require 'rspec' | ||
require 'spec_helper' | ||
require_relative '../lib/move' | ||
|
||
describe Move do | ||
|
||
it "can be a strike" do | ||
it 'can be a strike' do | ||
Move.new(:strike).type.should eq(:strike) | ||
end | ||
it "can be a block" do | ||
it 'can be a block' do | ||
Move.new(:block).type.should eq(:block) | ||
end | ||
it "has a ranking" do | ||
it 'has a ranking' do | ||
(1..100).should include Move.new(stub).ranking | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require 'rspec' | ||
|
||
RSpec.configure do |config| | ||
# Use color in STDOUT | ||
config.color_enabled = true | ||
|
||
# Use color not only in STDOUT but also in pagers and files | ||
config.tty = true | ||
|
||
# Use the specified formatter | ||
config.formatter = :documentation # :progress, :html, :textmate | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,44 @@ | |
require_relative "../lib/turn" | ||
|
||
describe Turn do | ||
let(:strike_a) { Move.new(:strike) } | ||
let(:strike_b) { Move.new(:strike) } | ||
|
||
it "should have a winner" do | ||
[strike_a, strike_b].should include Turn.new(strike_a, strike_b).winner | ||
end | ||
let(:fighter_a) { Fighter.new('bob') } | ||
let(:fighter_b) { Fighter.new('fred') } | ||
let(:strike_a) {Move.new(:strike)} | ||
let(:strike_b) {Move.new(:strike)} | ||
let(:block_a) {Move.new(:block)} | ||
let(:block_b) {Move.new(:block)} | ||
|
||
subject { Turn.new(fighter_a, fighter_b) } | ||
|
||
it "should have a winner" do | ||
[fighter_a, fighter_b].should include subject.winner | ||
end | ||
|
||
it "should determine winner by rank on strike vs strike" do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hopefully this is what you meant be specific example: In turn.rb I create a turn with 2 Fighters. These fighters already have moves assigned on creation.
Are you saying I should have created a method #random on Turn that took 2 Moves so that when testing I could send in the Moves I want? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, so maybe instead of [move_a, move_b].sample You could have a method choose_random [move_a, move_b] And then you have full control over muhahahaha 🎉 |
||
# turn = Turn.new(fighter_a, fighter_b) | ||
strike_a.stub(:ranking) {99} | ||
strike_b.stub(:ranking) {1} | ||
subject.instance_variable_set(:@fighter_a_move, strike_a) | ||
subject.instance_variable_set(:@fighter_b_move, strike_b) | ||
expect(subject.winner).to eq(fighter_a) | ||
end | ||
|
||
it "should determine winner by rank on strike vs block" do | ||
# subject = subject.new(fighter_a, fighter_b) | ||
strike_a.stub(:ranking) {1} | ||
block_b.stub(:ranking) {99} | ||
subject.instance_variable_set(:@fighter_a_move, strike_a) | ||
subject.instance_variable_set(:@fighter_b_move, block_b) | ||
expect(subject.winner).to eq(fighter_b) | ||
end | ||
|
||
it "should determine winner on block vs block" do | ||
# subject = subject.new(fighter_a, fighter_b) | ||
block_a.stub(:ranking) {1} | ||
block_b.stub(:ranking) {99} | ||
subject.instance_variable_set(:@fighter_a_move, block_a) | ||
subject.instance_variable_set(:@fighter_b_move, block_b) | ||
expect([fighter_a, fighter_b]).to include(subject.winner) | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably want to use
&&
in most cases ofand
. Same with||
andor
(reasons: http://devblog.avdi.org/2010/08/02/using-and-and-or-in-ruby/)