ChatGPT Atrocities — 2
I had earlier posted about ChatGPT doing some insane things in the software development domain.
Today, I wanted to see how robust its programming skills really are and asked ChatGPT to come up with a Python program for playing the tic-tac-toe game.
Here is the Python Code generated by ChatGPT.
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QGridLayout, QWidget
class TicTacToe(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.turn = "X"
self.grid = QGridLayout()
self.wid = QWidget()
self.wid.setLayout(self.grid)
self.setCentralWidget(self.wid)
self.buttons = {}
for i in range(3):
for j in range(3):
self.buttons[(i, j)] = QPushButton("")
self.buttons[(i, j)].clicked.connect(lambda: self.play(i, j))
self.grid.addWidget(self.buttons[(i, j)], i, j)
self.show()
def play(self, i, j):
if self.buttons[(i, j)].text() == "":
self.buttons[(i, j)].setText(self.turn)
if self.turn == "X":
self.turn = "O"
else:
self.turn = "X"
app = QApplication(sys.argv)
game = TicTacToe()
sys.exit(app.exec_())
Of course, the program runs on PyCharm without any syntax issues.
But does it work as expected? Nope!
The PyQt window comes up but nothing works when I click on the buttons. After the first X appears on the last button, irrespective of where I click in the window, nothing else happens.
This is because of how the button’s clicked.connect function is set. The lambda function is not being invoked properly. It has to be changed slightly like this.
for i in range(3):
for j in range(3):
btn = QPushButton("")
name = str(i) + "-" + str(j)
btn.setText("")
btn.clicked.connect(lambda state, x=name: self.play(x))
self.grid.addWidget(btn, i, j)
self.buttons[name] = btn
Ahem … obviously, ChatGPT won’t take away “all the software development jobs” YET.
But it will still have a significant impact because to come up with even this base framework, a beginner-level programmer could take 4 to 5 hours. An experienced programmer could debug this and fix it in an hour or two max.
So, while entry-level programming jobs are still at risk with ChatGPT, there is still some time before AI goes about completely cannibalizing all the programming jobs.