jeudi 20 mai 2021

Recreation of a wordpuzzle game

I am trying to code a wordpuzzle game, this is a snippet of the code I am stuck on, I feel like I have tried everything.

answers are a list of the words that are available to be found in the puzzle and their coordinates and the directions they are in. The answers present here are a snippet for testing purposes. What seems to happen is that the user can find a correct answer ("this is working"), but after an attempt of guesses (usually wrong ones) it says the answer is not a word even if it is present.

The program prints the available answers after each round for testing purposes.

answers=[(2, 12, 'up', 'reduce'), (11, 0, 'left', 'cherimolla'), (7, 12, 'up', 'leopardbane'), (9, 12, 'upleft', 'bionomical')]
guess = []
move = False

players=[]
players.append("Stephan")

while True:
  print(answers)
  for i in players:
    move = False
    guess=input("Player " + str(i) + "'s name: make a guess:")
    guesses=guess.split(",")   
    
    for i in range(len(answers)-1):
      ans=answers[i]
      if ans[0] == int(guesses[0]) and ans[1]==int(guesses[1]) and ans[2]==str(guesses[2]):
        answers.remove(ans)
        i==len(answers)+1
        print("this is working")
        break
      else:
        print("sorry this is not a word")
        break

This is an example of the case I am talking about. As can be seen the available answers get smaller, until a wrong guess is entered but after a right guess following it still says it is not a word.

[(2, 12, 'up', 'reduce'), (11, 0, 'left', 'cherimolla'), (7, 12, 'up', 'leopardbane'), (9, 12, 'upleft', 'bionomical')]

Player Stephan's name: make a guess:2,12,up

this is working

[(11, 0, 'left', 'cherimolla'), (7, 12, 'up', 'leopardbane'), (9, 12, 'upleft', 'bionomical')]

Player Stephan's name: make a guess:11,11,left

sorry this is not a word

[(11, 0, 'left', 'cherimolla'), (7, 12, 'up', 'leopardbane'), (9, 12, 'upleft', 'bionomical')]

Player Stephan's name: make a guess:11,0,left

this is working

[(7, 12, 'up', 'leopardbane'), (9, 12, 'upleft', 'bionomical')]

Player Stephan's name: make a guess:7,12,up

this is working

[(9, 12, 'upleft', 'bionomical')]

Player Stephan's name: make a guess:11,11,left

[(9, 12, 'upleft', 'bionomical')]

Player Stephan's name: make a guess:11,11,left

[(9, 12, 'upleft', 'bionomical')]

Player Stephan's name: make a guess:9,12,upleft

[(9, 12, 'upleft', 'bionomical')]

Aucun commentaire:

Enregistrer un commentaire