Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local module = {}
- --local cards = {"d5", "h4", "c10", "s10", "h1", "d4"}
- local combos = { {1,2},{1,3},{1,4},{1,5},{2,3},{2,4},{2,5},{3,4},{3,5},{4,5},
- {1,2,3},{1,2,4},{1,2,5},{1,3,4},{1,3,5},{1,4,5},{2,3,4},{2,3,5},{2,4,5},{3,4,5},
- {1,2,3,4},{1,2,3,5},{1,2,4,5},{1,3,4,5},{2,3,4,5},{1,2,3,4,5} }
- local tossCombos = {
- {1,2,3,4},{1,2,3,5},{1,2,3,6},{1,2,4,5},{1,2,4,6},{1,2,5,6},{1,3,4,5},{1,3,4,6},{1,3,5,6},
- {1,4,5,6},{2,3,4,5},{2,3,4,6},{2,3,5,6},{2,4,5,6},{3,4,5,6}
- }
- -----------------------------------------------------------------------------
- function fixCards(cards,justNumbers) --justNumbers is by default, true
- local newCardsTable = {}
- local justNumbers = not justNumbers
- for i,v in pairs(cards) do
- table.insert(newCardsTable,(justNumbers and tonumber((v:gsub("%a",""))) or v ) )
- end
- table.sort(newCardsTable)
- return newCardsTable
- end
- function getPointsFrom15(cards)
- local pointsFrom15 = 0
- for a,n in pairs(combos) do
- local num = 0
- for i,v in pairs(n) do
- local card = cards[v]
- card = (card and card >= 10 and 10 or card)
- num = (card and num + card or 0)
- end
- pointsFrom15 = (num == 15 and (pointsFrom15 + 2) or pointsFrom15)
- end
- return pointsFrom15
- end
- function getPointsFromPairs(cards)
- local pointsFromPairs = 0
- for a,n in pairs(cards) do
- for i,v in pairs(cards) do
- pointsFromPairs = (((v == n) and a~=i) and (pointsFromPairs + 1) or pointsFromPairs)
- --it counts each pair twice, so only add 1
- end
- end
- return pointsFromPairs
- end
- function runWasCounted(runsCounted,newRun)
- local blank,timesOccurred = runsCounted:gsub(newRun,"")
- if timesOccurred >= 1 then
- return true
- else
- return false
- end
- end
- function getPointsFromRuns(cards)
- --print(table.concat(cards,', '))
- local points = 0
- local runsCounted = ""
- for a = 1, #cards do
- for b = (a + 1), #cards do
- for c = (b + 1), #cards do
- for d = (c + 1), #cards do
- if (cards[a] + 1 == cards[b] and cards[b] + 1 == cards[c] and cards[c] + 1 == cards[d]) then
- points = points + 4
- runsCounted = runsCounted..a..b..c..d..","
- end
- end
- points = ( (cards[a] + 1 == cards[b] and cards[b] + 1 == cards[c] and not runWasCounted(runsCounted,a..b..c) ) and (points + 3) or points)
- end
- end
- end
- if (cards[1] + 1 == cards[2] and cards[2] + 1 == cards[3] and cards[3] + 1 == cards[4] and cards[4] + 1 == cards[5]) then
- points = 5
- end
- return points
- end
- function allSuitsAreTheSame(cards)
- local suit = cards[1]:gsub("%d","")
- local points = 0
- for a = 1,4 do
- print(cards[a])
- local cardSuit = cards[a]:gsub("%d","")
- points = (suit == cardSuit and points + 1 or points)
- end
- local lastCardSuit = (cards[5] and cards[5]:gsub("%d","") or nil)
- points = (points == 4 and points or 0)
- points = ((points == 4 and lastCardSuit and suit == lastCardSuit) and (points + 1) or points)
- return points
- end
- function getKnobs(cards)
- local jackSuits = {}
- for i = 1, 4 do
- if tonumber((cards[i]:gsub("%a",""))) == 11 then --if card is jack
- local jackSuit = cards[i]:gsub("%d","")
- table.insert(jackSuits,jackSuit)
- end
- end
- for a = 1, #jackSuits do
- local suit = (cards[5] and cards[5]:gsub("%d","") or nil)
- if suit and jackSuits[a] == suit then
- return 1
- end
- end
- return 0
- end
- function module:getPoints(cards,index,place)
- local bonus = allSuitsAreTheSame(cards)
- local knobs = getKnobs(cards)
- local cards = fixCards(cards)
- --[[
- print("Points from suits: "..bonus)
- print("Points from knobs: "..knobs)
- print("Points from making 15: "..getPointsFrom15(cards))
- print("Points from pairs: "..getPointsFromPairs(cards))
- print("Points from Runs: "..getPointsFromRuns(cards)) --]]
- --script:ClearAllChildren()
- --local newPointsValue = Instance.new("IntValue", place)
- --newPointsValue.Name = "Value"..index
- --print(getPointsFrom15(cards) + getPointsFromPairs(cards) + getPointsFromRuns(cards) + bonus + knobs)
- return (getPointsFrom15(cards) + getPointsFromPairs(cards) + getPointsFromRuns(cards) + bonus + knobs)
- end
- function getExpectedValue(cards,knownCards,theValuesShouldBePrinted) --4 cards
- local t={"h","d","s","c"}
- --print("#cards = "..#cards)
- local function differentCardsCheck(knownCards,card2BChecked)
- for a,v in pairs(knownCards) do
- if v == card2BChecked then
- return false
- end
- end
- return true
- end
- local ExpectedValue = 0
- for a=1,13 do
- for b=1,4 do
- if differentCardsCheck(knownCards,(t[b]..a)) then --if it is an unknown card
- cards[5] = (t[b]..a)
- if theValuesShouldBePrinted then
- print(table.concat(cards,", "))
- print((module:getPoints(cards)))
- end
- ExpectedValue = (module:getPoints(cards) * (1/46)) + ExpectedValue
- end
- end
- end
- cards[5] = nil
- return ExpectedValue
- end
- function module:tossCards2Crib(cards,placeForValue) --cribOwner = true for self, cribOwner = false for oppoenent
- table.sort(cards, function(a, b) return tonumber((a:gsub("%a",""))) > tonumber((b:gsub("%a",""))) end)
- local bestHand = {}
- bestHand["Points1"] = 0
- --[[local ExpectedValues = {}
- local function round3Places(x)
- return (x + 0.0005 - (x + 0.0005) % .001)
- end--]]
- local index = 2
- for a,v in pairs(tossCombos) do
- local handPoints = getExpectedValue( { cards[v[1]],cards[v[2]],cards[v[3]],cards[v[4]] },cards )
- --table.insert(ExpectedValues,round3Places(handPoints))
- if bestHand["Points1"] < handPoints then
- bestHand["Points1"] = handPoints
- bestHand["Combo1"] = a
- --[[for a = 2,15 do
- bestHand["Combo"..a] = nil
- bestHand["Points"..a] = nil
- end
- elseif bestHand["Points1"] == handPoints then
- bestHand["Points"..index] = handPoints
- bestHand["Combo"..index] = a
- index = index + 1
- --]]
- end
- end
- --[[
- local besthands = 0
- for a,v in pairs(bestHand) do
- besthands = besthands + .5
- end
- print("BestHandLength: "..besthands)
- --]]
- local keepCards = {cards[tossCombos[bestHand["Combo1"]][1]],cards[tossCombos[bestHand["Combo1"]][2]],cards[tossCombos[bestHand["Combo1"]][3]],cards[tossCombos[bestHand["Combo1"]][4]]}
- for a=4,1,-1 do
- table.remove(cards,tossCombos[bestHand["Combo1"]][a])
- end
- --local tossCards = fixCards(cards,true)
- -- for a,v in pairs(tossCombos[bestHand["Combo1"]]) do --{1,3,5,6}
- -- table.remove(tossCards,v)
- -- end
- --print(getExpectedValue(keepCards,cards)) --,true
- local info = Instance.new("IntValue")
- info.Name = "CardInstructions"
- local keepCardInfo = Instance.new("StringValue")
- local tossCardInfo = Instance.new("StringValue")
- keepCardInfo.Name = "keepCards"
- tossCardInfo.Name = "tossCards"
- keepCardInfo.Value = game.HttpService:JSONEncode(keepCards)
- tossCardInfo.Value = game.HttpService:JSONEncode(cards)
- info.Parent = placeForValue
- keepCardInfo.Parent = info
- tossCardInfo.Parent = info
- return keepCards,cards --second value is tossCards
- end
- return module
Advertisement
Add Comment
Please, Sign In to add comment