Roulette Sim

Ruby code posted by Chris
created at 11 Aug 06:38

Edit | Back
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
class Roulette
  @fields = {0  => "green",
            1  => "red",
            2  => "black",
            3  => "red",
            4  => "black",
            5  => "red",
            6  => "black",
            7  => "red",
            8  => "black",
            9  => "red",
            10 => "black",
            11 => "red",
            12 => "black",
            13 => "red",
            14 => "black",
            15 => "red",
            16 => "black",
            17 => "red",
            18 => "black",
            19 => "red",
            20 => "black",
            21 => "red",
            22 => "black",
            23 => "red",
            24 => "black",
            25 => "red",
            26 => "black",
            27 => "red",
            28 => "black",
            29 => "red",
            30 => "black",
            31 => "red",
            32 => "black",
            33 => "red",
            34 => "black",
            35 => "red",
            36 => "black"}

public
  def Roulette.turn
    number = rand(@fields.length)
    @fields[number]
  end

  def Roulette.number color
    @fields[color]
  end

  def Roulette.probability type
    if (type == "number")
      (1/37)
    elsif (type == "color")
      (18/37)
    elsif (type == "red")
      (18/37)
    elsif (type == "black")
      (18/37)
    elsif (type == "dozen")
      (12/37)
    elsif (type == "odd")
      (18/37)
    elsif (type == "even")
      (18/37)
    elsif (type == "null")
      (1/37)
    end
  end
end
1.53 KB in 5 ms with coderay