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

Warrior cannot differentiate between monsters (patch prototype inside) #59

Open
dpritchett opened this issue Dec 8, 2012 · 0 comments

Comments

@dpritchett
Copy link

a_slime_draws_near.png

In playing with my own Warrior I decided I wanted to teach him how to recognize individual monsters and remember them from turn to turn. I checked the RubyWarrior source and discovered that the monster objects persist from turn to turn but that they don't offer #hash methods to remember them by. I monkeypatched Unit and Space and it had the desired effect. I'd like to submit a pull request to add this functionality (with specs) but before I do I'd like confirmation from a maintainer that this won't violate the spirit of the game. Sample monkey patches are below

Thanks!

require 'securerandom'

module RubyWarrior
  module Units
    class Base
      def unique_id
        @uuid ||= SecureRandom.uuid
      end

      def eql?(other_unit)
        self.hash == other_unit.hash
      end

      def hash
        self.unique_id.hash
      end
    end
  end

  class Space
    def unique_id
      @uuid ||= SecureRandom.uuid
    end

    def eql?(other_space)
      self.hash == other_space.hash
    end

    # Not sure about this part but my code didn't work when 
    # I tried to only put the monster hashes on the units themselves.
    #
    def hash
      self.unit.hash || self.unique_id.hash
    end
  end
end
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

No branches or pull requests

1 participant