Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp3
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[,] board=new int[10,10];
- n_queens(board, 4, 2);
- }
- public static void n_queens(int[,] board, int size, int solution_num)
- {
- int temp;
- int[] malkot = new int[size];
- for (int k = 0; k < size; k++)
- {
- malkot[k] = -1;
- }
- for (int i = 0; i < size; i++)
- {
- temp = PutMeMalkot(malkot, size, 0, 0, i);
- if (temp != -4)
- {
- malkot[i] = temp;
- }
- else
- {
- temp = ChnageAllThePastMalkot(malkot, i, size, i);
- if (temp == -6)
- {
- Console.WriteLine("אין פיתרון");
- }
- else
- {
- i = temp;
- }
- }
- }
- Console.WriteLine("asdasd");
- }
- public static int ChnageAllThePastMalkot(int[] malkot, int Row,int size,int witchRow)
- {
- if (malkot[Row]+1 < size-1)
- {
- if (malkot[Row - 1] + 1 > size)
- {
- malkot[Row - 1] = -1;
- return ChnageAllThePastMalkot(malkot, Row - 1, size, witchRow);
- }
- else
- {
- int temp = PutMeMalkot(malkot, size, 0, malkot[Row - 1] + 1, Row - 1);
- if (temp == -4)
- {
- malkot[Row - 1] = -1;
- return ChnageAllThePastMalkot(malkot, Row - 1, size, witchRow);
- }
- else
- {
- malkot[Row - 1] = temp;
- return Row - 1;
- }
- }
- }
- else
- {
- malkot[witchRow] = -6;
- return -6;
- }
- }
- public static int PutMeMalkot(int[] malkot, int size,int row,int place,int WhatRow)
- {
- if (place > size-1)
- {
- return -4;
- }
- if (row < size-1 && WhatRow != 0 && row != WhatRow)
- {
- if (malkot[row] != place
- && (malkot[row] + (1 * (WhatRow - row)) != place)
- && (malkot[row] - (1 * (WhatRow - row)) != place))
- {
- return PutMeMalkot(malkot, size, row + 1, place, WhatRow);
- }
- else
- {
- return PutMeMalkot(malkot, size, 0, place + 1, WhatRow);
- }
- }
- else
- {
- return place;
- }
- return -2;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement