#Chess Game - Ruby - HELP!

6 messages · Page 1 of 1 (latest)

broken basin
#

Am stuck with the last two tests: getting a correct message for moves to A2 and H8. I don't understand: my function valid_square? works independently, but not in the if statement. Am I not calling it correctly? Please help 🙂

module Chess
  RANKS = 1..8
  FILES = 'A'..'H'

  def self.valid_square?(rank, file)
    RANKS.include?(rank) && FILES.include?(file)
  end

  def self.nick_name(first_name, last_name)
    first_name[0..1].upcase + last_name[-2..-1].upcase
  end

  def self.move_message(first_name, last_name, square)
    if valid_square?(square[1], square[0])
      "#{nick_name(first_name, last_name)} moved to #{square}"
    else
      "#{nick_name(first_name, last_name)} attempted to move to #{square}, but that is not a valid square"
    end
  end
end
burnt flare
#

RANKS is a range of integers, square is a string, which I think in Ruby is a sequence of unicode characters. That might be the problem in your solution

low geyser
#

What is the error message?

broken basin
#

Code Run

assert_equal "JOOE moved to A2", Chess.move_message("John", "Doe", "A2")

Test Failure

Expected: "JOOE moved to A2"
  Actual: "JOOE attempted to move to A2, but that is not a valid square"
#

The error message isn't very helpful. My move_message function is returning the wrong option from if/else.

#

The first function valid_square? works fine, so checking if values are in the ranges of integers and strings seems to work... wait: do I have to do a type conversion on one half of the "square" variable before passing it to the function?