From 0e957eeac265cc4af64c674cea0cb042783c937a Mon Sep 17 00:00:00 2001 From: Peter Lewis Date: Thu, 22 Mar 2012 00:46:53 +0000 Subject: [PATCH 1/3] This should fix the out of bounds crash --- contestants/wmrug/two_minutes_to_chocolate_player.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contestants/wmrug/two_minutes_to_chocolate_player.rb b/contestants/wmrug/two_minutes_to_chocolate_player.rb index 47dd546..c819c8f 100644 --- a/contestants/wmrug/two_minutes_to_chocolate_player.rb +++ b/contestants/wmrug/two_minutes_to_chocolate_player.rb @@ -98,10 +98,10 @@ def update_probability_grid(state) if @probability_grid[@last_shot.x][@last_shot.y + 1] @probability_grid[@last_shot.x][@last_shot.y - 1] += PROBABILTY_STEP unless @probability_grid[@last_shot.x][@last_shot.y + 1] ==0 end - if @probability_grid[@last_shot.x - 1][@last_shot.y] + if @probability_grid[@last_shot.x - 1] && @probability_grid[@last_shot.x - 1][@last_shot.y] @probability_grid[@last_shot.x - 1][@last_shot.y] += PROBABILTY_STEP unless @probability_grid[@last_shot.x - 1][@last_shot.y] ==0 end - if @probability_grid[@last_shot.x + 1][@last_shot.y] + if @probability_grid[@last_shot.x + 1] && @probability_grid[@last_shot.x + 1][@last_shot.y] @probability_grid[@last_shot.x + 1][@last_shot.y] += PROBABILTY_STEP unless @probability_grid[@last_shot.x + 1][@last_shot.y] ==0 end end From 7db1491d96a313774e8b011056f5a487f37b5866 Mon Sep 17 00:00:00 2001 From: Peter Lewis Date: Thu, 22 Mar 2012 01:19:52 +0000 Subject: [PATCH 2/3] Fix wrong sign --- contestants/wmrug/two_minutes_to_chocolate_player.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contestants/wmrug/two_minutes_to_chocolate_player.rb b/contestants/wmrug/two_minutes_to_chocolate_player.rb index c819c8f..5f5e0d1 100644 --- a/contestants/wmrug/two_minutes_to_chocolate_player.rb +++ b/contestants/wmrug/two_minutes_to_chocolate_player.rb @@ -96,7 +96,7 @@ def update_probability_grid(state) # @file.puts "AFTER:" + @probability_grid[@last_shot.x][@last_shot.y - 1].to_s # @file.puts "-------------" if @probability_grid[@last_shot.x][@last_shot.y + 1] - @probability_grid[@last_shot.x][@last_shot.y - 1] += PROBABILTY_STEP unless @probability_grid[@last_shot.x][@last_shot.y + 1] ==0 + @probability_grid[@last_shot.x][@last_shot.y + 1] += PROBABILTY_STEP unless @probability_grid[@last_shot.x][@last_shot.y + 1] ==0 end if @probability_grid[@last_shot.x - 1] && @probability_grid[@last_shot.x - 1][@last_shot.y] @probability_grid[@last_shot.x - 1][@last_shot.y] += PROBABILTY_STEP unless @probability_grid[@last_shot.x - 1][@last_shot.y] ==0 From 5df5b7858e33ff11411dc84706f71a9f91383884 Mon Sep 17 00:00:00 2001 From: Peter Lewis Date: Thu, 22 Mar 2012 01:20:34 +0000 Subject: [PATCH 3/3] Aaargh... cope with x and y swapping between action and state. --- contestants/wmrug/two_minutes_to_chocolate_player.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contestants/wmrug/two_minutes_to_chocolate_player.rb b/contestants/wmrug/two_minutes_to_chocolate_player.rb index 5f5e0d1..c6a8387 100644 --- a/contestants/wmrug/two_minutes_to_chocolate_player.rb +++ b/contestants/wmrug/two_minutes_to_chocolate_player.rb @@ -74,7 +74,9 @@ def take_turn(state, ships_remaining) # ships_remaining is an array of the remaining opponents ships # return [x,y] # your next shot co-ordinates - return [@last_shot.x, @last_shot.y] + # For some bug-knows-why reason, x and y are swapped between the action and + # state :-/ + return [@last_shot.y, @last_shot.x] end def update_probability_grid(state)