# Wig-Wug Simulator

**URL:** <https://www.ruby-forum.com/t/wig-wug-simulator/145928>\
**Category:** Ruby\
**Created:** [August 15, 2008, 5:22am UTC](https://www.ruby-forum.com/t/wig-wug-simulator/145928 "2008-08-15T05:22:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bbazzarrakk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bbazzarrakk](https://www.ruby-forum.com/u/bbazzarrakk)\
**Post date:** [August 15, 2008, 5:22am UTC](https://www.ruby-forum.com/t/wig-wug-simulator/145928/1 "2008-08-15T05:22:18Z")

</div>

I have started a Wig-Wug ([therubyist.com](http://therubyist.com/homework/wig-wug/))  
simulator and thrown it on github  
([GitHub - JEG2/wig-wug: An unofficial simulator for the first homework assignment (August issue) in The Rubyist.](http://github.com/JEG2/wig-wug/tree/master)  
). It probably still has issues, but it may be of interest to others  
playing with the problem. It includes a map and a digger class I  
wrote that does badly on that map. Enjoy.

James Edward G. II

---

<div class="post-metadata">

**Author:** ![bbazzarrakk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bbazzarrakk](https://www.ruby-forum.com/u/bbazzarrakk)\
**Post date:** [August 15, 2008, 6:10pm UTC](https://www.ruby-forum.com/t/wig-wug-simulator/145928/2 "2008-08-15T18:10:38Z")

</div>

On Aug 14, 9:19 pm, James G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

---

<div class="post-metadata">

**Author:** ![bbazzarrakk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bbazzarrakk](https://www.ruby-forum.com/u/bbazzarrakk)\
**Post date:** [August 15, 2008, 6:15pm UTC](https://www.ruby-forum.com/t/wig-wug-simulator/145928/3 "2008-08-15T18:15:54Z")

</div>

On Aug 14, 9:19 pm, James G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have started a Wig-Wug ([therubyist.com](http://therubyist.com/homework/wig-wug/))  
> simulator and thrown it on github ([GitHub - JEG2/wig-wug: An unofficial simulator for the first homework assignment (August issue) in The Rubyist.](http://github.com/JEG2/wig-wug/tree/master)  
> ). It probably still has issues, but it may be of interest to others  
> playing with the problem. It includes a map and a digger class I  
> wrote that does badly on that map. Enjoy.
> 
> James Edward G. II

Sorry for the empty message. Hit send WAY too early.

I mean to send this patch, which lets your game server not crash if a  
player ends up on the edge of the map:

91a92

> ```
> return 'E' if x == -1 || y == -1 || x == @width || y == @height
> 
> ```

Chris

---

<div class="post-metadata">

**Author:** ![bbazzarrakk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bbazzarrakk](https://www.ruby-forum.com/u/bbazzarrakk)\
**Post date:** [August 15, 2008, 10:23pm UTC](https://www.ruby-forum.com/t/wig-wug-simulator/145928/4 "2008-08-15T22:23:44Z")

</div>

On Aug 15, 2008, at 11:12 AM, Chris S. wrote:

> I mean to send this patch, which lets your game server not crash if a  
> player ends up on the edge of the map:
> 
> 91a92
> 
> > ```
> > return 'E' if x == -1 || y == -1 || x == @width || y == @height
> > 
> > ```

Interesting. Is this a patch to Map#[]? I wouldn’t think it would be  
needed, due to lines 46-50 of game.rb. Am I missing something?

James Edward G. II

---

<div class="post-metadata">

**Author:** ![bbazzarrakk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bbazzarrakk](https://www.ruby-forum.com/u/bbazzarrakk)\
**Post date:** [August 15, 2008, 11:23pm UTC](https://www.ruby-forum.com/t/wig-wug-simulator/145928/5 "2008-08-15T23:23:30Z")

</div>

On Aug 15, 2:20 pm, James G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Interesting. Is this a patch to Map#[]? I wouldn’t think it would be  
> needed, due to lines 46-50 of game.rb. Am I missing something?
> 
> James Edward G. II

Yes. That was for Map#[]. But taking that out and going back to  
game.rb, I added “pp surrounding” after surrounding gets settled, and  
you can see that there’s something up:

$ ./bin/wig-wug -w 2 -h 2 ~/Desktop/bots/digger.rb [15:06:44]  
FO  
OR  
Surprise: Starts at x=1, y=0.

Turn 1  
[[“E”, “E”, “E”], [“F”, “P”, nil], [“O”, “R”, nil]]  
Surprise: (down) Reached the ruby.

Result: Surprise won.

I think the issue is that Comparable#between? includes both endpoints,  
so if a bot is on the bottom edge of the map, the Map ends up asking  
for points not on the map. And those will be nil if the player’s on  
the right edge, and will raise a NoMethodError for nil[] if it’s on  
the bottom edge.

Subtracting one from width and height when they appear as arguments to  
#between? on line 46 of game.rb should actually take care of it better  
than what I suggested earlier.

Or am I missing something now?

Chris

---

<div class="post-metadata">

**Author:** ![bbazzarrakk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bbazzarrakk](https://www.ruby-forum.com/u/bbazzarrakk)\
**Post date:** [August 15, 2008, 11:58pm UTC](https://www.ruby-forum.com/t/wig-wug-simulator/145928/6 "2008-08-15T23:58:37Z")

</div>

On Aug 15, 2008, at 4:17 PM, Chris S. wrote:

> > > > playing with the problem. It includes a map and a digger class I  
> > > > 91a92  
> > > > game.rb, I added “pp surrounding” after surrounding gets settled, and
> 
> than what I suggested earlier.
> 
> Or am I missing something now?

I think you are exactly right. I’ve committed the fix. Thanks!

James Edward G. II
