Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Open
dpritchett opened this Issue · 0 comments

1 participant

@dpritchett

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
Something went wrong with that request. Please try again.