math.randomseed(os.time())
deck = {}
function gen_deck()
local deck = {}
for i = 1, 20 do
deck[i] = {I = i; T = '-'}
end
for i = 21, 60 do
deck[i] = {I = i, T = 'O'}
end
return deck
end
function tcard(card)
return card.T .. string.format(' ( %2.f )', card.I)
end
function print_deck(deck)
for i = 1, 60 do
print(tcard(deck[i]))
end
end
function print_decks(deck, deck2)
print("---")
for i = 1, 60 do
print(tcard(deck[i]), "\t", tcard(deck2[i]))
end
end
function mash_deck(deck)
-- New deck to move cards into
local new_deck = {}
-- The last card that we pick up
local cut_index = math.random(22, 30)
-- How many to leave undisturbed when moving the cut block over
local undisturbed_count = math.random(3, 16)
-- Start with the undistrubed cards
for i = 1, undisturbed_count do
new_deck[i] = deck[cut_index + i]
end
-- Now do the mash zone
local insert_index = cut_index + undisturbed_count + 1
local insert_size = 60 - undisturbed_count - cut_index
local mashed_from_block = 0
local mashed_from_insert = 0
while true do
-- Add a card from the block
if mashed_from_block >= cut_index then break end
mashed_from_block = mashed_from_block + 1
local card_from_block = deck[mashed_from_block]
table.insert(new_deck, card_from_block)
-- Possibly, add another card from the block
if math.random() < 1/10 then
if mashed_from_block >= cut_index then break end
mashed_from_block = mashed_from_block + 1
local card_from_block = deck[mashed_from_block]
table.insert(new_deck, card_from_block)
end
-- Add a card from the insert into
if mashed_from_insert < insert_size then
local card = deck[insert_index + mashed_from_insert]
mashed_from_insert = mashed_from_insert + 1
table.insert(new_deck, card)
end
-- Maybe add another card from the insert into
if math.random() < 1/10 and mashed_from_insert < insert_size then
local card = deck[insert_index + mashed_from_insert]
mashed_from_insert = mashed_from_insert + 1
table.insert(new_deck, card)
end
end
-- Add any unused insert cards
while mashed_from_insert < insert_size do
local card = deck[insert_index + mashed_from_insert]
mashed_from_insert = mashed_from_insert + 1
table.insert(new_deck, card)
end
-- update deck
return new_deck
end
function fischer_shuffle(deck)
for i = 59, 0, -1 do
local j = math.random(0, i)
deck[j+1], deck[i+1] = deck[i+1], deck[j+1]
end
return deck
end
local deck1 = gen_deck()
for i = 1, 6 do
deck1 = mash_deck(deck1)
end
local deck2 = gen_deck()
deck2 = fischer_shuffle(deck2)
--print_decks(deck1, deck2)
counts = {}
for i = 1, 60 do
counts[i] = 0
end
local times = 60000
for i = 1, times do
local deck = gen_deck()
for i = 1, 5 do
deck = mash_deck(deck)
end
counts[deck[1].I] = counts[deck[1].I] + 1
end
for i = 1, 60 do
print(" "..string.format('%.2fx', counts[i]/(times/60)))
end
--[[
cut_index
| Cut Block
|.------^----.
|||||||||||||||||||||||||
(Remaining cards) |
(Cut Block) undisturbed_count
|||||||||||||| |
vvvv .-^-.
|||||||||||
(Remaining cards to mash into)
34, 7
24, 8
28, 17
27, 8
23, 17
25, 14
(22, 30), (3, 16)
]]