Skip to content
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

A lot of questions. need to go over it again #13

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

A lot of questions. need to go over it again #13

wants to merge 4 commits into from

Conversation

mikeadeleke
Copy link

Submitting a pull request would not even be a good avenue because I do not believe I understood this assignment. However, it gives the ability for you to see what I have so far. What do I need to go over if these are my questions:

  1. Refactoring a line to add in a "13.times do" statement
  2. Move ranking

@@ -6,6 +6,15 @@
puts "What is your second fighter's name?"
fighter_b = $stdin.gets

match = Match.new(Fighter.new(fighter_a), Fighter.new(fighter_b))
match = Match.new(Fighter.new(fighter_a), Fighter.new(fighter_b)) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be extremely difficult to full off -- you'd need to have a block on initialize ("new").

But, instead, I think you want "tap" here .... think of tap like this:

class Thermometer
  attr_accessor :temp
end


gauge = Thermometer.new.tap{|t| t.temp = 95}

# OR

gauge = Thermometer.new.tap do |t| 
  t.temp = 95
end

gauge.temp
=> 95

tldr: match = Match.new(Fighter.new(fighter_a), Fighter.new(fighter_b)).tap |match| do

@jwo
Copy link
Member

jwo commented Dec 10, 2013

Not sure what you meant by "Move ranking" -- can you expand?

@mikeadeleke
Copy link
Author

Almost done on the Panda level but running into an undefined local variable for "fighter_a".

Yeah I am a little confused with the Tiger level question:

  1. Instead of randomly selecting the winner of a turn, use the Move's ranking to determine a winner

@jwo
Copy link
Member

jwo commented Dec 11, 2013

Instead of randomly selecting the winner of a turn, use the Move's ranking to determine a winner

In https://github.com/RubyoffRails/Episode2/blob/master/lib/turn.rb there's this code:

def determine_winner
  [@move_a, @move_b].sample
end    

This just gets a random move between a and b. Instead, it should determine based on the move's ranking:

class Move

        attr_reader :type, :ranking
        def initialize(type)
                @type = type
                @ranking = rand(100)
        end

end

So the ranking is just random. Instead, decide on what @type is. Like a strike is 50, a block is 40, a sweep_the_leg is 60. Or something.

@mikeadeleke
Copy link
Author

Okay things are a little more clear. What would be a good way to generate a random move now?


match = Match.new(Fighter.new(@fighter_a), Fighter.new(@fighter_b)) do
3.times.map do
match = Match.new
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A match should contain 13 rounds. Each round has a move by each player

Remember, when you puts "Fighter A -- #{@fighter_a.name} -- won" -- that should be a replay of the game's results. Not looping through and doing it,.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. what do you mean by replay instead of looping? do you mean that there should be a line where there is a rematch instead of spitting out the same result?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean that that I should be able to view the results, and then pass the match object to you, and then you view the same results. 

It means you have to store the rounds in an array for the match.

On Thu, Dec 12, 2013 at 7:41 PM, Mike Adeleke [email protected]
wrote:

  • def initialize
  •    @strike = strike
    
  •    @block = block
    
  •    @leg_sweep = leg_sweep
    
  • end
  • def moves
  •    strike = 50
    
  •    block = 40
    
  •    leg_sweep = 60
    
  • end
    +end

+match = Match.new(Fighter.new(@fighter_a), Fighter.new(@fighter_b)) do

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking, maybe I should make a new method called "rounds" that has an array. I also now have a "moves" method. I can call "values" on moves and pass in the values. Is that what you were thinking?

leg_sweep = 60
end

def moves
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can tell you're lost here.

So, first question: why are you not using the provided Move class? lib/move.rb

second, if you have some possible moves, it should look like

def possible_moves
  {strike: 50, block: 40, leg_sweep: 60}
end

Later, when you need to randomly pick one of those? A hash can turn into an array

Hash[possible_moves.to_a.sample(1)]

Try it out: http://rubyfiddle.com/riddles/d041c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants