made AIs aware what colour they were playing
This commit is contained in:
parent
d6aa977a15
commit
dc6631f79c
@ -2,6 +2,7 @@
|
|||||||
#include "controller/controller.hpp"
|
#include "controller/controller.hpp"
|
||||||
#include "controller/human_vs_ai.hpp"
|
#include "controller/human_vs_ai.hpp"
|
||||||
#include "controller/manual.hpp"
|
#include "controller/manual.hpp"
|
||||||
|
#include "model/perft/perft.hpp"
|
||||||
#include "view/gui.hpp"
|
#include "view/gui.hpp"
|
||||||
#include "view/noop.hpp"
|
#include "view/noop.hpp"
|
||||||
#include "view/view.hpp"
|
#include "view/view.hpp"
|
||||||
@ -14,8 +15,8 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
Board b = Board::setup_fen_position(pos);
|
Board b = Board::setup_fen_position(pos);
|
||||||
|
|
||||||
ai::v0_random p1(std::chrono::milliseconds(500));
|
ai::v0_random p1(true, std::chrono::milliseconds(500));
|
||||||
ai::v0_random p2(std::chrono::milliseconds(500));
|
ai::v0_random p2(false, std::chrono::milliseconds(500));
|
||||||
|
|
||||||
GUI gui;
|
GUI gui;
|
||||||
AIvsAIController manual(b, gui, p1, p2);
|
AIvsAIController manual(b, gui, p1, p2);
|
||||||
@ -25,10 +26,5 @@ int main(int argc, char* argv[]) {
|
|||||||
controller.start();
|
controller.start();
|
||||||
|
|
||||||
// perft();
|
// perft();
|
||||||
// ai::v1_simple ai;
|
|
||||||
//
|
|
||||||
// Board b = Board::setup_fen_position(pos);
|
|
||||||
// Move move = ai.search(b, true);
|
|
||||||
// std::cout << move << std::endl;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -8,36 +8,39 @@
|
|||||||
namespace ai {
|
namespace ai {
|
||||||
class AI {
|
class AI {
|
||||||
protected:
|
protected:
|
||||||
|
bool am_white;
|
||||||
std::chrono::milliseconds thinking_time;
|
std::chrono::milliseconds thinking_time;
|
||||||
virtual Move _search(const Board&, bool = false) = 0;
|
virtual Move _search(const Board&) = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AI(std::chrono::milliseconds tt): thinking_time(tt) {}
|
AI(bool am_white, std::chrono::milliseconds tt)
|
||||||
|
: am_white(am_white),
|
||||||
|
thinking_time(tt) {}
|
||||||
|
|
||||||
std::atomic<bool> stop_computation = false;
|
std::atomic<bool> stop_computation = false;
|
||||||
|
|
||||||
Move search(const Board& b, bool am_white = false);
|
Move search(const Board& b);
|
||||||
|
|
||||||
virtual int eval(const Board&) = 0;
|
virtual int eval(const Board&) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct v0_random : public AI {
|
struct v0_random : public AI {
|
||||||
v0_random(std::chrono::milliseconds tt): AI(tt) {}
|
v0_random(bool w, std::chrono::milliseconds tt): AI(w, tt) {}
|
||||||
|
|
||||||
Move _search(const Board&, bool) override;
|
Move _search(const Board&) override;
|
||||||
|
|
||||||
int eval(const Board&) override {
|
int eval(const Board&) override {
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
class v1_simple : public AI {
|
class v1_simple : public AI { // looks two moves ahead
|
||||||
int _search(const Board&, int);
|
int _search(const Board&, int);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
v1_simple(std::chrono::milliseconds tt): AI(tt) {}
|
v1_simple(bool w, std::chrono::milliseconds tt): AI(w, tt) {}
|
||||||
|
|
||||||
Move _search(const Board&, bool) override;
|
Move _search(const Board&) override;
|
||||||
int eval(const Board&) override;
|
int eval(const Board&) override;
|
||||||
};
|
};
|
||||||
} // namespace ai
|
} // namespace ai
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
Move ai::v0_random::_search(const Board& b, bool) {
|
Move ai::v0_random::_search(const Board& b) {
|
||||||
std::vector<Move> moves = b.all_legal_moves();
|
std::vector<Move> moves = b.all_legal_moves();
|
||||||
|
|
||||||
return moves[rand() % moves.size()];
|
return moves[rand() % moves.size()];
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
static int INFINITY = std::numeric_limits<int>::max();
|
static int INFINITY = std::numeric_limits<int>::max();
|
||||||
|
|
||||||
Move ai::v1_simple::_search(const Board& b, bool am_white) {
|
Move ai::v1_simple::_search(const Board& b) {
|
||||||
ThreadPool pool(std::thread::hardware_concurrency());
|
ThreadPool pool(std::thread::hardware_concurrency());
|
||||||
|
|
||||||
std::vector<Move> moves = b.all_legal_moves();
|
std::vector<Move> moves = b.all_legal_moves();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user