lib/bridge/constants.rb in bridge-0.1.4 vs lib/bridge/constants.rb in bridge-0.2.0
- old
+ new
@@ -48,36 +48,54 @@
SIDES = %w{NS EW}
# All possible vullnerabilites
VULNERABILITIES = ["NONE", SIDES, "BOTH"].flatten
+ # Matches 2S, 7NT, 1C
+ BID_REGEXP = Regexp.new %q{(?<bid>([1-7])([CDHS]|NT))}
+
+ # Matches X, XX
+ MODIFIER_REGEXP = Regexp.new %q{(?<modifier>(X{1,2}))}
+
+ # Matches X, XX
+ DIRECTION_REGEXP = Regexp.new %q{(?<direction>([NESW]))}
+
+ # Matches =, -12, +4
+ RESULT_REGEXP = Regexp.new %q{(?<result>(=|\+[1-6]|-\d{1,2}))}
+
+ # Matches 7NTXE, 1SXXS
+ CONTRACT_REGEXP = Regexp.new %Q{(?<contract>#{BID_REGEXP}#{MODIFIER_REGEXP}?#{DIRECTION_REGEXP})}
+
+ # Matches 1SE=, 7NTXXS-2
+ SCORE_REGEXP = Regexp.new %Q{(?<score>#{CONTRACT_REGEXP}#{RESULT_REGEXP})}
+
module Points
IMPS =
{
- 0..10 => 0,
- 20..40 => 1,
- 50..80 => 2,
- 90..120 => 3,
- 130..160 => 4,
- 170..210 => 5,
- 220..260 => 6,
- 270..310 => 7,
- 320..360 => 8,
- 370..420 => 9,
- 430..490 => 10,
- 500..590 => 11,
- 600..740 => 12,
- 750..890 => 13,
- 900..1090 => 14,
- 1100..1290 => 15,
- 1300..1490 => 16,
- 1500..1740 => 17,
- 1750..1990 => 18,
- 2000..2240 => 19,
- 2250..2490 => 20,
- 2500..2990 => 21,
- 3000..3490 => 22,
- 3500..3990 => 23,
+ 0..10 => 0,
+ 20..40 => 1,
+ 50..80 => 2,
+ 90..120 => 3,
+ 130..160 => 4,
+ 170..210 => 5,
+ 220..260 => 6,
+ 270..310 => 7,
+ 320..360 => 8,
+ 370..420 => 9,
+ 430..490 => 10,
+ 500..590 => 11,
+ 600..740 => 12,
+ 750..890 => 13,
+ 900..1090 => 14,
+ 1100..1290 => 15,
+ 1300..1490 => 16,
+ 1500..1740 => 17,
+ 1750..1990 => 18,
+ 2000..2240 => 19,
+ 2250..2490 => 20,
+ 2500..2990 => 21,
+ 3000..3490 => 22,
+ 3500..3990 => 23,
4000..15200 => 24
}
class Chicago
# values in array: [not-vulnerable, vulnerable]
POINTS =