私は以下のコードを持っており、それをもっと短くしようとしています。 whileループとforループを使ってみましたが、動作させることはできません。私もここでStackoverflowを検索し、列挙とサイクルループを見つけましたが、エラーを取得し続けるか、一般的に私がやっていることを知らない。これを短縮する方法はありますか?コードをループを使って短くすることはできますか?
私はpygame互換バージョンとidlexでpython 3.2を歌います。
players = [npc1,npc2,npc3,human] # these are classes
# sets new order of players after being mixed
first_player = players[0]
second_player = players[1]
third_player = players[2]
fourth_player = players[3]
# sets players prey...goes one ahead in the index, wrap around at end
first_players_prey = players[1]
second_players_prey = players[2]
third_players_prey = players[3]
fourth_players_prey = players[0]
# sets players predator, goes back one in the index, wrap around
first_players_predator = players[3]
second_players_predator = players[0]
third_players_predator = players[1]
fourth_players_predator = players[2]
# sets players grand prey/predator while only 4 players, goes 2 ahead/back in index, wrap around
first_players_grand_prey_predator = players[2]
second_players_grand_prey_predator = players[3]
third_players_grand_prey_predator = players[0]
fourth_players_grand_prey_predator = players[1]
個別の変数を16個作成しているので、コードを短くするためにそれをループすることはできません。 –