Está en la página 1de 3

#include <iostream>

#include <math.h>

#include <windows.h>

// Recursividad: caso base, acciones que debe tomar, llamada recursiva

using namespace std;

#define max 8

void inicializarTablero(int tablero[max]){

for(int x = 0; x < max ;x++){

tablero[x] = -1;

bool comprobar(int fila,int tablero[max]){

for ( int x = 0; x < fila ; x++){

if( (tablero[x] == tablero[fila]) || (abs(fila - x)) == abs(tablero[fila] - tablero[x]))

return false;

return true;

void mostrarTablero(int tablero[max]){

for(int x = 0; x < max; x++){

for(int y=0; y <max ; y++){

if(tablero[x] == y)

cout << " R ";


else

cout << " - ";

cout << endl;

Sleep(5);

void ubicarFicha(int fila, int &cantidad, int tablero[max]){

if( fila < max){

for(tablero[fila]=0; tablero[fila] < max ; tablero[fila]++){

if(comprobar(fila,tablero)){

ubicarFicha(fila+1,cantidad,tablero);

else{

cantidad++;

cout << endl << "Solucion N " << cantidad << endl;

mostrarTablero(tablero);

system("pause");

int main()

int tablero[max];

int fila = 0;

int cantidad = 0;
inicializarTablero(tablero);

ubicarFicha(fila,cantidad,tablero);

return 0;

También podría gustarte