A
A
Anton2016-07-04 19:13:05
ruby
Anton, 2016-07-04 19:13:05

What will the roulette algorithm look like?

I want to write a game - roulette, for the browser. Nothing serious - just for educational purposes.
The problem arises precisely in the algorithm, because in roulette there is, for example, a chance of winning red or black.
For example, there is this field:

1	2	3	4	5	6	7
8	9	10	11	12	13	14

1 - red; 14 - black. Alternating.
For example, "1 to 7" for reds and "8 to 14" for blacks. And by the way, what chance should zero have? One to one?
In general, in this matter, the betting process itself is unimportant. It is important what number (color) will fall out.
I hope I've made it clear what I'm interested in.
Please help me figure this out.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
Oleg, 2016-07-04
@politon

random is enough

A
Alexey, 2016-07-04
@alsopub

Create an array: 0(green), 1(red), 2(black), 3(red), 4(black)...
You will end up with 15 elements.
The chance of each individual is 1/15, the chance of red is 7/15, the chance of black is 7/15.
Choose something like random(0...14).

Дмитрий, 2016-07-14
@Virviil

Ячейка задаётся так:

cell = {number: 1, color: :red, parity: odd, size: small, dozen: 1, sixline: 1, corner: 1, street: 1, split: 1}
# соответственно для всех видов ставок

Ставка задаётся так же:
# ставим на пару с единицей (на границу 1 и 2) - шанс выигрыша = 17 к 1
bet = {number: nil, color: nil, parity: nil, size: nil, dozen: nil, sixline: nil, corner: nil, street: nil, split: 1}

Проверяем совпадение:
def match?(cell, bet) do
    !cell.keys.all?{|key| cell[key] != bet[key]}
end

Для того, чтобы выпала ячейка - создаём массив из всех таких возможных ячеек, а потом рандомом выбираем номер.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question