擅长:python、mysql、java
<p>你可以用这样的方法:</p>
<pre><code>def GetNextPlayer(self, p, forward=True):
""" Return the player to the left of the specified player, skipping players who have been knocked out
"""
def get_next():
ref = p if forward else p + self.numberOfPlayers - 1
return p + 1
next = get_next()
# Skip any knocked-out players
while next != p and self.knockedOut[next]:
next = get_next()
return next
</code></pre>
<p>我已经分离了引用(从0开始的计数)和周期性属性(模运算)。也使它通用于向后和向前</p>