Wig-Wug Simulator

C

Chris Shea

I have started a Wig-Wug (http://therubyist.com/homework/wig-wug/)  
simulator and thrown it on github (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 Gray 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
 
J

James Gray

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

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 Gray II
 
C

Chris Shea

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:

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 Gray 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
 
J

James Gray

I have started a Wig-Wug (http://therubyist.com/homework/wig-wug/)
simulator and thrown it on github (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 Gray 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

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 Gray 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?

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

James Edward Gray II
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,097
Latest member
RayE496148

Latest Threads

Top