unified controller interface
This commit is contained in:
parent
a47130e5d0
commit
47cf8b3539
7
cpp/src/controller/controller.cpp
Normal file
7
cpp/src/controller/controller.cpp
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#include "controller.hpp"
|
||||||
|
|
||||||
|
#include "../view/view.hpp"
|
||||||
|
|
||||||
|
Controller::Controller(Board b, View& v): board(b), view(v) {
|
||||||
|
v.set_controller(this);
|
||||||
|
}
|
@ -7,8 +7,11 @@ class View;
|
|||||||
class Controller {
|
class Controller {
|
||||||
protected:
|
protected:
|
||||||
Board board;
|
Board board;
|
||||||
|
View& view;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Controller(Board, View);
|
Controller(Board, View&);
|
||||||
|
virtual void start() = 0;
|
||||||
virtual void on_tile_selected(int, int) = 0;
|
virtual void on_tile_selected(int, int) = 0;
|
||||||
};
|
};
|
||||||
|
@ -4,10 +4,7 @@
|
|||||||
|
|
||||||
HumanVsAIController::HumanVsAIController(Board b, View& v, ai::AI& ai)
|
HumanVsAIController::HumanVsAIController(Board b, View& v, ai::AI& ai)
|
||||||
: ManualController(b, v),
|
: ManualController(b, v),
|
||||||
ai(ai) {
|
ai(ai) {}
|
||||||
view.set_controller(this);
|
|
||||||
reset_selection();
|
|
||||||
}
|
|
||||||
|
|
||||||
void HumanVsAIController::on_tile_selected(int x, int y) {
|
void HumanVsAIController::on_tile_selected(int x, int y) {
|
||||||
Coords c{x, y};
|
Coords c{x, y};
|
||||||
|
@ -4,12 +4,14 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
ManualController::ManualController(Board b, View& view): view(view) {
|
ManualController::ManualController(Board b, View& v): Controller(b, v) {
|
||||||
board = b;
|
|
||||||
view.set_controller(this);
|
|
||||||
reset_selection();
|
reset_selection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ManualController::start() {
|
||||||
|
view.show();
|
||||||
|
}
|
||||||
|
|
||||||
void ManualController::on_tile_selected(int x, int y) {
|
void ManualController::on_tile_selected(int x, int y) {
|
||||||
Coords c{x, y};
|
Coords c{x, y};
|
||||||
Piece piece = board.piece_at(c);
|
Piece piece = board.piece_at(c);
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
class ManualController : public Controller {
|
class ManualController : public Controller {
|
||||||
protected:
|
protected:
|
||||||
View& view;
|
|
||||||
int8_t selected_index;
|
int8_t selected_index;
|
||||||
Piece selected_piece;
|
Piece selected_piece;
|
||||||
std::vector<int8_t> targets;
|
std::vector<int8_t> targets;
|
||||||
@ -19,4 +18,5 @@ class ManualController : public Controller {
|
|||||||
public:
|
public:
|
||||||
ManualController(Board, View&);
|
ManualController(Board, View&);
|
||||||
void on_tile_selected(int, int) override;
|
void on_tile_selected(int, int) override;
|
||||||
|
void start() override;
|
||||||
};
|
};
|
||||||
|
@ -18,11 +18,9 @@ int main(int argc, char* argv[]) {
|
|||||||
GUI gui;
|
GUI gui;
|
||||||
HumanVsAIController manual(b, gui, ai);
|
HumanVsAIController manual(b, gui, ai);
|
||||||
|
|
||||||
|
|
||||||
View& view = gui;
|
|
||||||
Controller& controller = manual;
|
Controller& controller = manual;
|
||||||
|
|
||||||
view.show();
|
controller.start();
|
||||||
|
|
||||||
// perft();
|
// perft();
|
||||||
// ai::v1_simple ai;
|
// ai::v1_simple ai;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user