Good development plan

Game sweepstakes simply limit security at the end of the realization of
the original xiaoyanzi521 finally released on 2014-03-02 20:53:29 read the number 1044 collection
launched
  colleagues said: "The lower limit of minimum guarantee is not the first time before many times, how many times not before The second, and so on. " First contact without understanding what it means when the lower limit of insurance at the end, because I "many times before" it wrong, I understand it has become "the props to be drawn up before many times", but "many times before" means how many times a player lottery draw. After figuring out that the lower limit of minimum guarantee is very simple.

  The lower limit of the project is implemented as security at the end, very simple. The first is the number of lottery players to be recorded. Then configure the required lower limit of the minimum guarantee of props. Finally, according to the number of lottery player determines insured props can bottom to the player. Due to very simple, direct paste the code a Lua script.


- [[
Date: February 12, 2014
Program: The game limit lottery security at the end.
]]


-------------------------------------------------- -----
- configuration
ProbabilityConf =
{
- [[lower limit of the minimum guarantee Description: for a given props, certainly not repeatedly before 1st, not sure how many times before the 2nd, ...]]
lowerItems =
{
{
ID = 117,
- [[Note: the first 5 certainly not the first time, the first 10 of this second certainly not, certainly not before 13 3rd, there is no limitation behind]]
Grade = . 5 {, 10, 13 is,},
},
{
ID = 1 18,
Grade = {15, 25, 35, 40, 60,},
},
},

- [[lottery article, since a random number is taken [1,10000] in, so the total rate value of the article needs to be 10,000. Important items arranged at both ends,
the order of items to consider when configured pumping mediator bottom article, if the article is security at the end can not be extracted, returned when a next return prop prop very common. ]]
Rewards =
{
- [[{ID = 111, name = "item_111", 100 = Rate,},
{ID = 112, name = "item_112", 200 is Rate =,},
{ID = 113, name = "item_113", Rate = 300,},
{ID = 114, name = "item_114", Rate = 400,},
{ID = 115, name = "item_115", Rate = 1000,},
{ID = 1 16, name = "item_116", rate = 1100 ,},]] - little less items, the probability of important items larger configuration, in order to test
{ID = 119, name = "item_119", Rate = 1000,},
{ID = 117 , name = "item_117", Rate = 4000,},
{1 18 = ID, name = "item_118", Rate = 4000,},
{ID = 120, name = "item_120",

}


-------------------------------------------------- -----
- script
ProbabilityFunc = {}

ProbaData = {} - used to store data
- [[
ProbaData.Lower [id]: id number of records to be drawn.
ProbaData.LoterryTimes: The total number of lottery players.
]]

- Function: Set a random seed value.
= Function ProbabilityFunc.InitRandom (SEED)
local curTime = os.time ()
SEED SEED = or curTime

--print("ProbabilityFunc.InitRandom: seed = "..seed)
math.randomseed(seed)
end


- [[
Function: returns the [min, max] interval within the random number.
]]
ProbabilityFunc.GetRandomNumber = function (min, max)
local Math.random = Random (min, max)

--print("ProbabilityFunc.GetRandomNumber: random = "..random)
return random
end


- [[
function: to see whether the index is the lower limit of the minimum guarantee items. liyan
Returns:
Parameter 1: true / nil.
]]
ProbabilityFunc.IsLowerItem = function (ID)
for _, One in ipairs (ProbabilityConf.lowerItems) do
IF == ID one.id the then
return One
End
End
return
End


- [[
Function: index corresponding to whether the items may be extracted.
Returns:
Parameter 1: true / nil, true indicates article may be extracted, nil indicates not be extracted.
]]
ProbabilityFunc.CanBeGiven = function (ID)
- whether it is a bottom limit security article
local oneLower = ProbabilityFunc.IsLowerItem (ID)
IF Not oneLower the then return to true End

local lowerIndex = ProbaData.Lower[id]
local needChouJiangTime = oneLower.grade[lowerIndex+1]
--print("lowerIndex = "..lowerIndex)
--print("needChouJiangTime = "..needChouJiangTime)
--print("ProbaData.LoterryTimes = "..ProbaData.LoterryTimes)
if not needChouJiangTime then return true end --已经突破了下限保底

- greater than the value in the configuration, can be extracted
return needChouJiangTime <ProbaData.LoterryTimes
End


- [[
function: articles in this sweepstakes obtained.
Returns:
Parameter 1: ProbabilityConf.rewards the index.
]]
ProbabilityFunc.GetItem = function ()
local ProbabilityFunc.GetRandomNumber Random = (. 1, 10000)
Print ( "ProbabilityFunc.GetItem: Random =" ..random)

local value, index = 0, 0
for I, ItemInfo in ipairs (ProbabilityConf .rewards) do
index I =
value = value + itemInfo.rate
IF value> = Random and ProbabilityFunc.CanBeGiven (itemInfo.id) the then
--print ( "ProbabilityFunc.GetItem: I =" ..i)
return I
End
End

return index
end


- Function: print information according to index items.
= Function ProbabilityFunc.PrintItem (index)
local ProbabilityConf.rewards ItemInfo = [index]

if not itemInfo then
print("ProbabilityFunc.PrintItem: invalid index "..index)
return
end

local str = string.format("you have id = %d, name = %s", itemInfo.id, itemInfo.name)
print(str)
end


- Function: After the first draw, record some information.
= Function ProbabilityFunc.RecordAfter (index)
- Record player lottery number
ProbaData.LoterryTimes = ProbaData.LoterryTimes + 1

- record-keeping bottom article is drawn
local ProbabilityConf.rewards ItemInfo = [index]
IF the then ItemInfo
IF ProbaData.Lower [itemInfo.id] the then
ProbaData.Lower [itemInfo.id] = ProbaData.Lower [itemInfo.id] +. 1
End
End
End


- Function: lottery business.
= Function ProbabilityFunc.Lottery (NUM)
local STR = String.Format ( "% D you have have Times", NUM)
Print (STR)

for i = 1, num do
local index = ProbabilityFunc.GetItem()
ProbabilityFunc.RecordAfter(index)

ProbabilityFunc.PrintItem(index)
end

--debug, do not need it, you can comment out the call this function
ProbabilityFunc.Debug ()
End


- Function: initialize data.
= Function ProbabilityFunc.InitData ()
ProbaData.Lower = {}

for _, oneItem in ipairs(ProbabilityConf.lowerItems) do
ProbaData.Lower[oneItem.id] = 0
end
ProbaData.LoterryTimes = 0
end


ProbabilityFunc.Debug = function()
print("\n-----ProbabilityFunc.Debug----")

local str = string.format("DEBUG: you have loterry %d times", ProbaData.LoterryTimes)
print(str)
for _, oneItem in ipairs(ProbabilityConf.lowerItems) do
print(oneItem.id, ProbaData.Lower[oneItem.id])
end

print("-----ProbabilityFunc.Debug----\n")
end


- Function: Initialization
ProbabilityFunc.Init = function ()
ProbabilityFunc.InitRandom ()
ProbabilityFunc.InitData ()
End


- Function: script entry function
ProbabilityFunc.main = function ()
ProbabilityFunc.Init ()

local read
while true do
print("Enter a number to start, or 'quit' to exit:")
read = io.read()
if read == "quit" then break end
--------------------------------------------

ProbabilityFunc.Lottery(tonumber(read))
print()
end

print("Exit!!!")
end


ProbabilityFunc.main
() ----------------
Disclaimer: This article is CSDN blogger "xiaoyanzi521 'original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/iirecord/article/details/20306421

Guess you like

Origin www.cnblogs.com/vana/p/12203818.html