def runIters(procNum): ITERATIONS = 100 guessesToWin = [] losses = 0 for i in range(ITERATIONS): guesser = Guesser() guesser.weightingTuple = weightTuple responder = Responder( getCellTuple(n2l(random.randint(1, 18)), random.randint(1, 18))) # print(f"Iteration {i}: {formatCell(responder.cell)}") turns = 0 gameOver = False while not gameOver: guess = guesser.getGuess() # print(f"Turn {turns} of iteration {i}: {formatCell(guess[0])}") if guess[1]: if responder.checkSolve(guess[0]): guessesToWin.append(turns) break else: losses += 1 break guesser.feedback(guess[0], responder.check(guess[0])) turns += 1 return (guessesToWin, losses, ITERATIONS)
print(f"Iteration {i}: {responder.cell}") turns = 0 gameOver = False while not gameOver: guess = guesser.getGuess() # print(f"Turn {turns} of iteration {i}: {guess}") if guess[1]: if responder.checkSolve(guess[0]): guessesToWin.append(turns) break else: losses += 1 break guesser.feedback(guess[0], responder.check(guess[0])) turns += 1 print(f"Mean turns to win: {sum(guessesToWin) / len(guessesToWin)}") print(f"{losses/ITERATIONS * 100}% loss rate ({losses} losses)") # if len(guessesToWin) > 0: # print("Rendering plot...") # plt.hist(guessesToWin) # plt.ylabel('Occurences') # plt.xlabel('Turns to Win'); # meanTurnsToWin = sum(guessesToWin) / len(guessesToWin) # plt.title('Mean Turns to Win: ' + str(meanTurnsToWin)); # plt.savefig('histo.png')
import random import sys from responder import Responder from helpers import getCellTuple, n2l, formatCell if len(sys.argv) == 3: cell = getCellTuple(sys.argv[1].upper(), int(sys.argv[2])) else: cell = getCellTuple(n2l(random.randint(1, 18)), random.randint(1, 18)) responder = Responder(cell) print(formatCell(responder.cell)) while True: guess = input('Input guess (prefix with s if solving): ').upper() if guess[0] == 'S': guessCell = getCellTuple(guess[1:2].upper(), int(guess[2:])) if responder.checkSolve(guessCell): print('You win!') else: print('You lose!') print('Correct answer: ' + formatCell(responder.cell)) break guessCell = getCellTuple(guess[0:1].upper(), int(guess[1:])) if responder.check(guessCell): print(formatCell(guessCell) + ': Yes') else: print(formatCell(guessCell) + ': No')