score = 0
matchPts = 1 // by default, we add 1
for (x,y) in zip(seqA,seqB):
if x == y:
score = score + matchPts
matchPts = 3
if x !=y :
score = score - 1
matchPts = 1
对于多个连续比赛,可以引入更复杂的奖励等级,但需要做一些更改:
score = 0
consecutiveMatches = 0
for (x,y) in zip(seqA,seqB):
if x == y:
consecutiveMatches += 1
reward = 1
if consecutiveMatches == 2:
reward = 3;
if consecutiveMatches > 2 :
reward = 5;
if consecutiveMatches > 5 :
reward = 100; // jackpot ;-)
// etc.
score += reward
else:
score -= 1
consecutiveMatches = 0
可能有更直接的方法,但明确也不坏。
加法的思想引入了一个变量,它告诉我们下次匹配时要加多少。你知道吗
对于多个连续比赛,可以引入更复杂的奖励等级,但需要做一些更改:
保存最后一场比赛的结果。你知道吗
相关问题 更多 >
编程相关推荐