Commit 4cae51e9 authored by 罗颖骄's avatar 罗颖骄

Feat: 计分方式3-第二轮排放金币越排在前面的人越吃亏的bug解决

parent cb67e02d
...@@ -43,15 +43,29 @@ namespace Lottery ...@@ -43,15 +43,29 @@ namespace Lottery
//开始计分,该循环表示计分规则 //开始计分,该循环表示计分规则
//获取从www.random.org生成的真随机数 //获取从www.random.org生成的真随机数
IReadOnlyList<int> randoms = RandomOrg.GetRandomsAsync(persons.Count).Result; IReadOnlyList<int> randoms = RandomOrg.GetRandomsAsync(persons.Count).Result;
Random updateRandom = new Random();
for (int j = 0; j < persons.Count; j++) for (int j = 0; j < persons.Count; j++)
{ {
//计分方式1:根据返回的随机数加金币 //计分方式1:根据返回的随机数加金币
//计分方式2:看命 //计分方式2:看命
//计分方式3:随即加上一个人的金币,看能否逆袭 //计分方式3:随即加上一个人的金币,看能否逆袭
//其他方式:可在下方对NewGrade属性进行操作 //其他方式:可在下方对NewGrade属性进行操作
if (i > 1)
{
// 计分方式3:bug——第二轮发金币时越排在前面的人获取到的上上一轮的NewGrade可能性越大,越排在后面的人获取到上轮NewGrade
// 解决策略->当前面的人抽取到前面已更新的OldGrade则照旧;若抽到后面的人,则增加一次计分方式1操作以此弥补差值
int randomIndex = randoms[j] - 1 >= j ? updateRandom.Next(j) : randoms[j] - 1;
int randomValue = randomIndex == 0 ? randoms[j] : persons[randomIndex].OldGrade;
persons[j].NewGrade += (randoms[j] +
(Math.Abs(persons[j].GetHashCode() << 1) % persons.Count) +
randomValue);
}
else
{
persons[j].NewGrade += (randoms[j] + persons[j].NewGrade += (randoms[j] +
(Math.Abs(persons[j].GetHashCode() << 1) % persons.Count) + (Math.Abs(persons[j].GetHashCode() << 1) % persons.Count) +
persons[randoms[j] - 1].OldGrade); persons[randoms[j] - 1].OldGrade);
}
if (i == 3 && persons[j].BaseGrade > 0) if (i == 3 && persons[j].BaseGrade > 0)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment