예제 소스
오목 Next.js 웹과 VLM 착수 API 연결하기 · 파일 59개
mainwindow.h
#pragma once
#include "boardmodel.h"
#include <QElapsedTimer>
#include <QMainWindow>
#include <QPointer>
class BoardWidget;
class QCheckBox;
class QLabel;
class QComboBox;
class QLineEdit;
class QPushButton;
class QSpinBox;
class QThread;
class QTimer;
namespace TcpVlmClient {
class Worker;
}
class MainWindow final : public QMainWindow {
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow() override;
void selectGameMode(GameMode mode);
private slots:
void onIntersectionClicked(int row, int col);
void onNewGameClicked();
void onModeChanged(int index);
void onBoardSizeChanged(int index);
void onHumanSideChanged(int index);
void doOneAiMove();
void onPingServerClicked();
void onCancelVlmClicked();
void onVlmMoveReady(bool success, int row, int col, QString errorMessage);
void onVlmPingReady(bool success, QString errorMessage);
void onVlmConnectionStateChanged(bool connected, QString endpoint);
void onVlmTickProgress();
private:
void pushBoardToView();
void updateStatus();
void restartMatch();
void maybeScheduleAi();
bool aiShouldAnswerThisTurn() const;
QVector<QVector<Cell>> shallowCopyCells() const;
/** 마지막 수 위치 마커를 갱신. 게임 종료 상태이면 깜빡임 정지. */
void markLastMove(int row, int col);
/** 둔 수를 학습용 기보로 서버에 비동기 로깅. 모든 모드에서 호출 가능 (실패는 무시). */
void logMoveToServer(int row, int col, Cell stone, int actorKind);
void setVlmUiVisible(bool visible);
void startVlmTcpRequest(); ///< 비동기 시작
void finishVlmCleanup(); ///< 응답/취소 후 UI 복원
void playLocalFallbackForVlm(); ///< VLM 실패 시 로컬 휴리스틱이 VLM 자리를 대체
Cell vlmSideForCurrentMode() const; ///< 현재 모드에서 VLM 이 잡는 색
bool isVlmTurn() const; ///< 현재 차례가 VLM 차례인지
BoardModel m_board;
BoardWidget *m_boardWidget = nullptr;
QLabel *m_statusLabel = nullptr;
QComboBox *m_modeCombo = nullptr;
QComboBox *m_sizeCombo = nullptr;
QLabel *m_humanSideLabel = nullptr;
QComboBox *m_humanSideCombo = nullptr;
QCheckBox *m_autoRestartCheck = nullptr;
QWidget *m_vlmConfigRow = nullptr;
QLineEdit *m_vlmHostEdit = nullptr;
QLineEdit *m_vlmPortEdit = nullptr;
QSpinBox *m_vlmTimeoutSpin = nullptr;
QPushButton *m_vlmConnectBtn = nullptr;
QPushButton *m_vlmCancelBtn = nullptr;
QLabel *m_vlmConnLabel = nullptr;
QThread *m_vlmThread = nullptr;
QPointer<TcpVlmClient::Worker> m_vlmWorker;
QTimer *m_vlmProgressTimer = nullptr;
QElapsedTimer m_vlmProgressClock;
bool m_vlmInFlight = false;
quint64 m_vlmRequestSession = 0;
quint64 m_sessionId = 0;
int m_moveSeq = 0; ///< 현재 게임 안에서 둔 수 순번 (1부터). restartMatch 에서 0으로.
bool m_autoRestartScheduled = false; ///< 한 게임 종료당 자동 재시작 1회 예약 보장.
};