'How to reset the score to old | snake and ladder

I am trying to implement a scenario , if a player gets 6 on dice rolled will be getting to play again the game until its not 6 and control goes to player 2

If he/she gets 6 on dice continuous 3 times then need to reset the score to old one

which as the score before the dice was rolled as 6

For example :

player 1 : score : 10 
player 1 : dice rolled 6 -> score : 10 + 6  : 16
player 1 : again turn got to player he / she as rolled again 6 on dice : score : 16 + 6 : 22
player 1 : again turn got to player he / she as rolled again 6 on dice : score : 10  [ 3 times continues player got 6 ]

My Code :

import random

flag = 0
get_count_of_six = []
get_score = []
counter = 1 
p1 = 0
p1_score = 0


while True:

  if flag == 0:

    dc = 6

    if dc == 6:

      p1_score = p1 + dc
      get_score.append(p1_score)
      get_count_of_six.append(counter)
      counter = counter + 1

      if get_count_of_six.count(dc) == 3:
        
        print(get_score[0])
        break;

      else:
        
        flag = 0
        
print(p1_score)

My Code does not work as expected !!!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source