all_guess=[]
hidden_code="rroy"
kvChrCount={}
for i in hidden_code:
kvChrCount[i]=kvChrCount.get(i,0)+1
def main():
display_board()
guess_loop()
def guess_loop():
character=['r','o','y','g','b','v']
turn=1
while turn<=10:
guess=input(f'{turn}(roygbv):')
if len(guess)==4 :
all_guess.append(guess+'||'+getMask(guess))
turn+=1
display_board()
if guess==hidden_code:
print('You win!')
break
if turn>10:
print('You lose!')
def getMask(s) :
num=0
kv={}
for i in s:
kv[i]=kv.get(i,0)+1
if i in hidden_code and kv[i]<=kvChrCount[i]:
num+=1
mask=""
for i in range(0,4):
if i<num:
if hidden_code[i]==s[i]:
mask+="B"
else:
mask+="W"
else:
mask+="."
return mask
def display_board():
print('----------')
print('Code||Mark')
l=len(all_guess)
for i in range(0,10):
if i<l:
print(f'{all_guess[i]}')
else:
print('....||....')
print('----------')
main()