![]()
이게 떴는데 괜찮은지 모르겠네
아 그리고 이렇게 코딩했는데 코딩을 못해서 AI한테 말했는데 이렇게 나오더라고 AI가 잘 했음?
import sys
from PyQt5.QtWidgets import QMainWindow, QApplication, QWidget, QGridLayout, QPushButton
class Board(QWidget):
def __init__(self, size):
super().__init__()
# 바둑판 그리기
grid = QGridLayout()
for i in range(size):
for j in range(size):
button = QPushButton(self)
button.clicked.connect(lambda _, row=i, col=j: self.on_click(row, col))
grid.addWidget(button, i, j)
self.setLayout(grid)
def on_click(self, row, col):
print(f"돌 놓기: ({row}, {col})")
# TODO: 돌 놓기 기능 구현
class MainWindow(QMainWindow):
def __init__(self, size):
super().__init__()
self.setWindowTitle("바둑 공원")
board = Board(size)
self.setCentralWidget(board)
if __name__ == "__main__":
app = QApplication(sys.argv)
size = 19
window = MainWindow(size)
sys.exit(app.exec_())
class GoBoard:
def __init__(self, size=19):
self.size = size
self.board = [[0] * size for _ in range(size)]
self.current_player = 1
def get_winner(self):
# TODO: 승리자 검사
return None
def play(self, row, col):
if self.board[row][col] != 0:
return False
self.board[row][col] = self.current_player
# TODO: 돌 놓기 이후 처리 (좌표 출력, 승리자 검사 등)
self.current_player = 3 - self.current_player
return True
class GoGame:
def __init__(self, size=19):
self.board = GoBoard(size)
def start(self):
while True:
# TODO: 플레이어에게 입력 받기 (좌표 입력 등)
row, col = 0, 0 # 임시 코드
if not self.board.play(row, col):
print("잘못된 수입니다.")
continue
winner = self.board.get_winner()
if winner is not None:
print(f"{winner} 승리!")
break
class GoBoard:
def __init__(self, size=19):
self.size = size
self.board = [[0] * size for _ in range(size)]
self.current_player = 1
def get_winner(self):
for r in range(self.size):
for c in range(self.size):
if self.board[r][c] == 0:
continue
color = self.board[r][c]
if (r <= self.size - 5 and self.board[r+1][c] == color
and self.board[r+2][c] == color and self.board[r+3][c] == color and self.board[r+4][c] == color):
return color
if (c <= self.size - 5 and self.board[r][c+1] == color
and self.board[r][c+2] == color and self.board[r][c+3] == color and self.board[r][c+4] == color):
return color
if (r <= self.size - 5 and c <= self.size - 5 and self.board[r+1][c+1] == color
and self.board[r+2][c+2] == color and self.board[r+3][c+3] == color and self.board[r+4][c+4] == color):
return color
if (r >= 4 and c <= self.size - 5 and self.board[r-1][c+1] == color
and self.board[r-2][c+2] == color and self.board[r-3][c+3] == color and self.board[r-4][c+4] == color):
return color
return None
class GoGame:
def __init__(self, size=19):
self.board = GoBoard(size)
def start(self):
while True:
# TODO: 플레이어에게 입력 받기 (좌표 입력 등)
row, col = 0, 0 # 임시 코드
if not self.board.play(row, col):
print("잘못된 수입니다.")
continue
winner = self.board.get_winner()
if winner is not None:
if winner == self.board.current_player:
print("승리!")
else:
print("패배!")
break