From 92d469aff0b7f02f692d37160e5d0230ce0beb87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Thu, 9 Nov 2023 15:34:03 +0100 Subject: FLNBotRules : protect _filter, _max, _min from empty spaces --- lib/colonial_twilight/fln_bot_rules.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/colonial_twilight/fln_bot_rules.rb b/lib/colonial_twilight/fln_bot_rules.rb index 8173d10..f82cb39 100644 --- a/lib/colonial_twilight/fln_bot_rules.rb +++ b/lib/colonial_twilight/fln_bot_rules.rb @@ -192,15 +192,21 @@ module ColonialTwilight # 8.1.2 - Procedure Guidelines def _filter(spaces, &block) + return spaces if spaces.empty? + (f = spaces.select(&block)).empty? ? spaces : f end def _max(spaces, sym) + return spaces if spaces.empty? + v = spaces.max { |a, b| a.send(sym) <=> b.send(sym) }.send(sym) spaces.select { |s| s.send(sym) == v } end def _min(spaces, sym) + return spaces if spaces.empty? + v = spaces.min { |a, b| a.send(sym) <=> b.send(sym) }.send(sym) spaces.select { |s| s.send(sym) == v } end -- cgit v1.1-2-g2b99