made small opti
This commit is contained in:
parent
a80fc9482d
commit
1b14ed693d
@ -29,7 +29,7 @@ obj/%.o:
|
||||
$(CXX) $(CXXFLAGS) -o $@ -c $<
|
||||
|
||||
main: $(OBJFILES)
|
||||
$(CXX) $(LDFLAGS) $(OBJFILES) $(LOADLIBES) $(LDLIBS) -o main -lsfml-graphics -lsfml-window -lsfml-system
|
||||
$(CXX) $(CXXFLAGS) $(OBJFILES) $(LOADLIBES) $(LDLIBS) -o main -lsfml-graphics -lsfml-window -lsfml-system
|
||||
|
||||
clean:
|
||||
rm -rf obj/* $(DEPFILES) test_bin/
|
||||
|
@ -25,7 +25,7 @@ int main(int argc, char* argv[]) {
|
||||
ai::v1_simple p2(false, std::chrono::milliseconds(150000));
|
||||
// ai::v0_random p2(false, std::chrono::milliseconds(10000));
|
||||
|
||||
GUI gui;
|
||||
NoOpView gui;
|
||||
AIvsAIController manual(b, gui, p1, p2);
|
||||
// HumanVsAIController manual(b, gui, p2);
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include <map>
|
||||
|
||||
#define MULTITHREADED 0
|
||||
|
||||
static int INFINITY = std::numeric_limits<int>::max();
|
||||
|
||||
@ -11,9 +12,14 @@ int position_counter;
|
||||
|
||||
Move ai::v1_simple::_search(const Board& b) {
|
||||
position_counter = 0;
|
||||
std::vector<Move> moves = b.all_legal_moves();
|
||||
|
||||
Move best_move;
|
||||
int best_eval = -INFINITY;
|
||||
#if MULTITHREADED
|
||||
ThreadPool pool(std::thread::hardware_concurrency());
|
||||
|
||||
std::vector<Move> moves = b.all_legal_moves();
|
||||
std::cout << "Have to look at " << moves.size() << " moves" << std::endl;
|
||||
|
||||
std::map<Move, std::future<int>> futures;
|
||||
for (const Move& move : moves) {
|
||||
@ -23,8 +29,6 @@ Move ai::v1_simple::_search(const Board& b) {
|
||||
})});
|
||||
}
|
||||
|
||||
Move best_move;
|
||||
int best_eval = -INFINITY;
|
||||
int counter = 0;
|
||||
for (auto& [move, future] : futures) {
|
||||
int eval = future.get();
|
||||
@ -36,7 +40,19 @@ Move ai::v1_simple::_search(const Board& b) {
|
||||
best_move = move;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
for (const Move& move : moves) {
|
||||
Board tmp_board = b.make_move(move);
|
||||
std::cout << "Looking at " << move << std::endl;
|
||||
int eval = _search(tmp_board, 3);
|
||||
if (!am_white)
|
||||
eval *= -1;
|
||||
if (eval > best_eval) {
|
||||
best_eval = eval;
|
||||
best_move = move;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
std::cout << "Looked at " << position_counter << " positions" << std::endl;
|
||||
return best_move;
|
||||
}
|
||||
|
@ -48,19 +48,19 @@ struct Board {
|
||||
: is_checkmate_for(Black) || is_stalemate_for(Black);
|
||||
}
|
||||
|
||||
Piece piece_at(int8_t idx) const {
|
||||
inline Piece piece_at(int8_t idx) const {
|
||||
return (Piece) (squares[idx] & 0b00111);
|
||||
}
|
||||
|
||||
Piece piece_at(Coords xy) const {
|
||||
inline Piece piece_at(Coords xy) const {
|
||||
return piece_at(xy.to_index());
|
||||
}
|
||||
|
||||
Colour colour_at(int8_t idx) const {
|
||||
inline Colour colour_at(int8_t idx) const {
|
||||
return (Colour) (squares[idx] & 0b11000);
|
||||
}
|
||||
|
||||
Colour colour_at(Coords xy) const {
|
||||
inline Colour colour_at(Coords xy) const {
|
||||
return colour_at(xy.to_index());
|
||||
}
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user