I have spent >1 hour or so and I have choose to make a way with all the possible outcomes.
Its horrible inefficient but with only 6 or less players in the game its fine. Currently the system creates a table inside a table with randomized numbers 1-6, (No Duplicates)
ex.
local Numbers= {
{1,3,6,2,5,4},
{6,5,4,2,1,3},
--etc... for how many combinations
}
Now I hit my next roadblock of taking all of the different possible team configurations and finding out which has the smallest difference other than doing 20 if statements, does anyone know how to take a list of many numbers and see which one is the lowest?
Also for those curious:
Current Progress, Use Expressive output or change if statement at bottom.
Matchmaking testing.rbxl (19.5 KB)
--(109 Lines)
local Values = {
Player1 = 10,
Player2 = 21,
Player3 = 12,
Player4 = 19,
Player5 = 15,
Player6 = 14
}
local x = 0--#Values
for i,v in pairs(Values) do
x +=1
end
--Factorial
local function factorial(n)
if (n == 0) then
return 1
else
return n * factorial(n - 1)
end
end
--
local Comination1 = factorial(x)
local Combination2 = factorial((x / 2))
local Combination3 = factorial( (x)-(x/2) )
local formula = (Comination1) / (Combination2*Combination3)
print(formula.." Different Combinations")
local DifferentCombinations = {}
--Solution1
local function randomnum()
return math.random(1,x)
end
local function getrandomorder()
local x1 = randomnum()
local x2 = randomnum()
while x2 == x1 do
x2 = randomnum()
wait()
end
if x > 2 then
local x3 = randomnum()
while x3 == x2 or x3 == x1 do
x3 = randomnum()
wait()
end
local x4 = randomnum()
while x4 == x3 or x4 == x2 or x4 == x1 do
x4 = randomnum()
wait()
end
if x > 4 then
local x5 = randomnum()
while x5 == x4 or x5 == x3 or x5 == x2 or x5 == x1 do
x5 = randomnum()
wait()
end
local x6 = randomnum()
while x6 == x5 or x6 == x4 or x6 == x3 or x6 == x2 or x6 == x1 do
x6 = randomnum()
wait()
end
return {x1,x2,x3,x4,x5,x6}
else
return {x1,x2,x3,x4}
end
else
return {x1,x2}
end
end
while #DifferentCombinations < formula do
local order = getrandomorder()
--Check if order is already used
--Get new values
local x1 = order[1]
local x2 = order[2]
local x3
local x4
local x5
local x6
if x > 2 then
x3 = order[3]
x4 = order[4]
if x > 4 then
x5 = order[5]
x6 = order[6]
end
end
local can = true
for q,z in pairs(DifferentCombinations) do
if z[1] == x1 and z[2] == x2 and z[3] == x3 and z[4] == x4 and z[5] == x5 and z[6] == x6 then--Change to be compatible with 2,4 in table
can = false
end
end
if can == true then
table.insert(DifferentCombinations,1,order)
end
wait()
end
print(DifferentCombinations)