#include "queens.hh" #include #include #include #include using namespace queens; Configuration::Configuration(int m, int n, int number_of_pieces) { this->number_of_pieces = number_of_pieces; this->board = new Board; this->board->m = m; //x direction this->board->n = n; //y direction //get a random number generator: //the random device that will seed the generator std::random_device seeder; //then make a mersenne twister engine std::mt19937 engine(seeder()); //then the easy part... the distribution std::uniform_int_distribution m_rand(1, m); std::uniform_int_distribution n_rand(1, n); for (int i=0; ipieces.push_back(Queen(m_rand(engine), n_rand(engine))); } } std::vector Configuration::get_conflicts() { std::vector conflicts; for (int i = 0; inumber_of_pieces; i++) { // The piece we will check against the others: Piece* piece = &this->pieces[i]; // For every new i we need to check one fewer i for (int j = i+1; jpieces[j]; if (piece->x == enemy_piece->x or piece->y == enemy_piece->y or piece->x - enemy_piece->x == piece->y - enemy_piece->x) { Conflict conflict; conflict.piece_1 = i; conflict.piece_1_x = piece->x; conflict.piece_1_y = piece->y; conflict.piece_2 = j; conflict.piece_2_x = enemy_piece->x; conflict.piece_2_y = enemy_piece->y; conflicts.push_back(conflict); } } } return conflicts; } Piece::Piece(int x, int y) { this->x = x; this->y = y; }