Mam do zrobienia grę w kółko i krzyżyk, większość mam skończoną, jednak potrzebuję oprócz losowego wstawiania znaku przez komputer na planszy, dodać mu inne algorytmy, np. blokowanie ruchu. Czy mógłby mi ktoś pomóc napisać ze dwa dodatkowe algorytmy? Poniżej część kodu (wydaje mi się, że wystarczy jeśli wrzucę strukturę komputera, w której trzeba to zmienić)
struct computer
{
public:
enum algorithm_type
{
ALGORITHM_0,
ALGORITHM_1
};
private:
std::string name;
char sign;
char (*board)[MAX_SIZE][MAX_SIZE];
algorithm_type choosen_algorithm;
void do_algorithm_0_move(int& return_x, int& return_y)
{
int x = 0;
int y = 0;
while (true)
{
x = rand() % MAX_SIZE;
y = rand() % MAX_SIZE;
if ((*board)[y][x] == EMPTY_SIGN)
{
(*board)[y][x] = sign;
return_x = x;
return_y = y;
std::cout << "Komputer wykonal ruch na x: " << x << ", y: " << y << std::endl;
break;
}
}
}
public:
computer(char(*b)[MAX_SIZE][MAX_SIZE] = nullptr, char s = ' ', const algorithm_type algo_type = algorithm_type::ALGORITHM_0)
{
name = "computer";
choosen_algorithm = algo_type;
sign = s;
board = b;
}
char get_sign() { return sign; }
void make_move(int& return_x, int& return_y)
{
switch (choosen_algorithm)
{
case algorithm_type::ALGORITHM_0:
{
do_algorithm_0_move(return_x, return_y);
break;
}
default:
{
std::cout << "Blad. Nie ma takiego algorytmu." << std::endl;
exit(0);
}
}
}
};