diff options
Diffstat (limited to 'internal/casino/roulette.go')
| -rw-r--r-- | internal/casino/roulette.go | 71 |
1 files changed, 23 insertions, 48 deletions
diff --git a/internal/casino/roulette.go b/internal/casino/roulette.go index 252ac4c..109306a 100644 --- a/internal/casino/roulette.go +++ b/internal/casino/roulette.go @@ -306,19 +306,17 @@ func rouletteAdjacent(a, b string, double bool) bool { return (dc == 1 && dr == 0) || (dc == 0 && dr == 1) } -// The zero lane spans all three numbered rows, so 0 splits with 1, 2 and 3. -// On an American felt the two zeros are adjacent to each other as well. +// European zero touches 1, 2 and 3. On the American layout, 0 +// touches 1 and 2; 00 touches 2 and 3. The zeros also touch each other. func rouletteZeroAdjacent(a, b string, double bool) bool { - neighbors := func(other string) bool { - if other == "0" || other == "00" { - return double - } - return other == "1" || other == "2" || other == "3" + if b == "0" || b == "00" { + a, b = b, a } - if a == "0" || a == "00" { - return neighbors(b) + if !double { + return a == "0" && (b == "1" || b == "2" || b == "3") } - return neighbors(a) + return (a == "0" && (b == "00" || b == "1" || b == "2")) || + (a == "00" && (b == "0" || b == "2" || b == "3")) } func rouletteIsStreet(nums []string) bool { @@ -352,6 +350,7 @@ func rouletteIsCorner(nums []string, double bool) bool { if !double && rouletteIsFirstFour(nums) { return true } + minCol, maxCol, minRow, maxRow := 12, -1, 3, -1 cells := map[[2]int]bool{} for _, s := range nums { c, r, ok := rouletteNumberCell(s) @@ -359,26 +358,10 @@ func rouletteIsCorner(nums []string, double bool) bool { return false } cells[[2]int{c, r}] = true + minCol, maxCol = min(minCol, c), max(maxCol, c) + minRow, maxRow = min(minRow, r), max(maxRow, r) } - if len(cells) != 4 { - return false - } - cols, rows := map[int]bool{}, map[int]bool{} - for cell := range cells { - cols[cell[0]] = true - rows[cell[1]] = true - } - if len(cols) != 2 || len(rows) != 2 { - return false - } - for c := range cols { - for r := range rows { - if !cells[[2]int{c, r}] { - return false - } - } - } - return true + return len(cells) == 4 && maxCol-minCol == 1 && maxRow-minRow == 1 } func rouletteIsFirstFour(nums []string) bool { @@ -427,30 +410,22 @@ func rouletteIsLine(nums []string) bool { return c2-c1 == 1 } -// A trio is any three distinct pockets drawn from 0, 00 and the first street -// (1,2,3) that includes at least one zero. It pays the same 11:1 as a street. +// Trios cover touching zero-edge intersections, not arbitrary selections +// from the zeros and the first street. func rouletteIsTrio(nums []string, double bool) bool { if len(nums) != 3 { return false } - hasZero := false - for _, s := range nums { - switch s { - case "0": - hasZero = true - case "00": - if !double { - return false - } - hasZero = true - default: - v, err := strconv.Atoi(s) - if err != nil || v < 1 || v > 3 { - return false - } - } + set := map[string]bool{} + for _, n := range nums { + set[n] = true + } + if double { + return (set["0"] && set["1"] && set["2"]) || + (set["0"] && set["00"] && set["2"]) || + (set["00"] && set["2"] && set["3"]) } - return hasZero + return set["0"] && set["2"] && (set["1"] || set["3"]) } // The basket is the American five-number 0/00/1/2/3 bet, which pays a short |
