예제 소스
테트리스 MoE 매크로 정책: 네 전문가로 착수 고르기 · 파일 31개
main_window.h
#pragma once
#include <QMainWindow>
#include "tetris_engine.h"
class QEvent;
class QKeyEvent;
class QLabel;
class QString;
class QShowEvent;
class QTcpServer;
class QTcpSocket;
class QTimer;
class TetrisWidget;
class MainWindow : public QMainWindow {
Q_OBJECT
public:
explicit MainWindow(QWidget* parent = nullptr, int rl_port = 0, int tick_ms = 650);
bool eventFilter(QObject* watched, QEvent* event) override;
protected:
void showEvent(QShowEvent* event) override;
void keyPressEvent(QKeyEvent* event) override;
private slots:
void on_tick();
void step_human(TetrisAction a);
void on_rl_new_connection();
void on_rl_ready_read();
void on_rl_disconnected();
private:
void update_hud();
void rl_send_state();
void rl_start(int port);
TetrisEngine engine_;
TetrisWidget* board_ = nullptr;
QLabel* hud_ = nullptr;
QTimer* tick_ = nullptr;
bool human_timer_enabled_ = true;
int tick_ms_ = 650;
// RL control (simple TCP, line-based)
QTcpServer* rl_server_ = nullptr;
QTcpSocket* rl_client_ = nullptr;
int rl_port_ = 0;
int pending_action_ = static_cast<int>(TetrisAction::Noop);
// TCP `human` / `agent`: 사람 직접 조작 vs 정책 액션만 적용
bool rl_human_mode_ = false;
QString rl_hud_extra_;
// 마지막 engine_.step()에 쓰인 액션(전이 식별용). 미스텝 전송은 -1
int last_step_action_ = -1;
quint64 rl_step_seq_ = 0;
};