diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2023-11-09 15:34:03 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2023-11-09 15:34:03 +0100 |
commit | 92d469aff0b7f02f692d37160e5d0230ce0beb87 (patch) | |
tree | 4002ddffc902f82a891a00bbb49bbb4c70e45f60 /lib/colonial_twilight | |
parent | 073dca3a5d42204952eeeb0fcbefa753466efc2e (diff) | |
download | colonial-twilight-92d469aff0b7f02f692d37160e5d0230ce0beb87.zip colonial-twilight-92d469aff0b7f02f692d37160e5d0230ce0beb87.tar.gz |
FLNBotRules : protect _filter, _max, _min from empty spaces
Diffstat (limited to 'lib/colonial_twilight')
-rw-r--r-- | lib/colonial_twilight/fln_bot_rules.rb | 6 |
1 files changed, 6 insertions, 0 deletions
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 |