Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int[] schachbrett = new int[8];
- int counter = 1;
- bool damenSicher() {
- for (int x=0; x<7; x++) {
- if (schachbrett[x] != 0) {
- for(int y=x+1; y<=7; y++) {
- if (schachbrett[y] != 0) {
- if (schachbrett[x]==schachbrett[y])
- return false;
- if (Math.Abs(x-y)==Math.Abs(schachbrett[x]-schachbrett[y]))
- return false;
- }
- }
- }
- }
- return true;
- }
- int dame(int position) {
- int x = 1;
- while(x <= 8) {
- schachbrett[position]=x;
- if(damenSicher()) {
- if(position) {
- if(damenSicher())
- return 1;
- }
- else {
- Console.Write("Loesungs-Nr " + (counter++) );
- for(int i=0; i<8; i++)
- Console.Write("(" + i+1 + "," + schachbrett[i] + ")" );
- Console.WriteLine();
- }
- }
- x++;
- }
- schachbrett[position] = 0;
- return 0;
- }
- void Main() {
- dame(schachbrett,7);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement