|
|
|
|
|
by joshka
1286 days ago
|
|
The code I got for "write a small python program to play tic tac toe" was complete (though I had to write "continue" to get all the output. It made a playable game, that was close to the output that it suggested would occur, but it did have a few mistakes - it missed 2 win conditions (rows and one of the diagonals), and the output didn't quite align fully (i.e. "" instead of " " being printed and no lines for board edges, it also doubled up the diagonal checks oddly. # Check if there is a winner, and if so, print a message indicating who won
if board[0][0] == board[1][1] == board[2][2] and board[0][0] != "":
print(f"Player {board[0][0]} wins")
elif board[0][2] == board[1][1] == board[2][0] and board[0][2] != "":
print(f"Player {board[0][2]} wins")
else:
# If there is no winner, the game is a draw
print("It's a draw!")
It took me a while to find the right prompt to fix this as it seems to confuse the code checking for game over, which checks for a winner as one of the conditions, for the code that checks for the winner at the end of the game.One of my prompts led to the output being made the program be refactored into a function run in a loop rather than a one shot game. and then I tried: >the play_game function prints the wrong output when there is a winner in the columns or rows and got the desired fix. I like the stateful nature of this. |
|
I noticed a bug, informed ChatGPT and it fixed it correctly, which is cool and all.
But I'm really interested in the next thing: I didn't save the code and so reran the same prompt a few days later. Now it was correct the first time. Did it learn the bug? It also lost the Exception handling it had in the first version, though. And it changed it's naming scheme for member variables from `m_foo` to `foo_`.