Sunday, 21 April 2019

8 QUEENS program using the java



8 QUEENS program using the JAVA


What is 8 queens game  :

      Every one knows how to play the chess in that most power full, dangerous and second most tallest piece in the chess board.

      And know you have to keep the 8 queens in the chess board so that non of the queen can kill the other one. There is a probability that you can keep only 6, 7 and 8 of them maximum number of placing the queens is 8. 

And u can see the code bellow.    







Bellow photo will be the actual output and when you gave the in put between 1 to 64 it will convert in to the rows and columns of the the chess board and replace the number that you gave as "8" and powers of the queen (All the vertical, horizontal and the diagonal rows will be placed with the "1")   



Code starts from here


package com.company;

import sun.awt.geom.AreaOp;

import java.sql.SQLOutput;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
       // write your code here      /*       System.out.println("enter digit :");       Scanner scanner = new Scanner(System.in);       int A = scanner.nextInt();      System.out.println("digit :"+ A);
       */       int a = 0, b = 0;
       int[][] que = new int[8][8];

       //It will keep all zero's in chess board
       for (int i = 0; i < 8; i++)
       {
          for (int j = 0; j < 8; j++) {
             que[i][j] = 0;
             System.out.print("  " + que[i][j]);

          }
          System.out.println();
       }
for (int A=8;A>0;A--)
{
   System.out.println("Enter the digit between 1 to 64 to place the Queen");
   System.out.println("you have"+ A +"chances");
   Scanner scanner = new Scanner(System.in);
   int number = scanner.nextInt();
   number = number - 1;

   // 'a' indicates the columns   // 'b' indicates the rows   a = number / 8;
   b = number % 8;

   if (number < 64)
   {
      if (que[a][b] == 0)
      {
         que[a][b] = 8;                     // It will place the  "0" with the "8"         int k = 1;
         for (int j = 0; j < 8; j++)        // this if loop will place will block all the  collems         {
            if (que[a][j] == 0)
            {
               if (j > 8)
               {
                  j = j % 8;
                  que[a][j] = k;
               }
               else               {
                  que[a][j] = k;
               }

            }
         }

         for (int i = 0; i < 8; i++)   // this if loop will place will block all the  horizontal placess         {
            if (que[i][b] == 0)
            {
               if (i > 8)
               {
                  i = i % 8;
                  que[i][b] = k;
               }
               else               {
                  que[i][b] = k;
               }
            }
         }

         if (a > b && a != 7)
         {
            AgreaterBse(a, b, que, k);
            AgreaterBnw(a, b, que, k);

            if (a + b > 7)
            {
               AgreaterBsw(a, b, que, k);
               AgreaterBne(a, b, que, k);
            }

            if (a + b < 7)
            {
               AgreaterBsw(a, b, que, k);
               AgreaterBne(a, b, que, k);
            }
         }

         else if (a > b && a == 7)
         {
            AgreaterBnw(a, b, que, k);
            AgreaterBne(a, b, que, k);
         }

         else if (a == b)
         {
            if (a != 7 && a != 0)
            {
               AgreaterBse(a, b, que, k);
               AgreaterBnw(a, b, que, k);
               if (a + b > 7)
               {
                  AgreaterBsw(a, b, que, k);
                  AgreaterBne(a, b, que, k);
               }

               if (a + b < 7)
               {
                  AgreaterBsw(a, b, que, k);
                  AgreaterBne(a, b, que, k);
               }
            }

            else if (a == 7)
            {
               AgreaterBnw(a, b, que, k);
            }
            else if (a == 0)
            {
               AgreaterBse(a, b, que, k);
            }
         }
         else if (a < b)
         {
            if (a + b >= 7)
            {
               AgreaterBse(a, b, que, k);
               AgreaterBnw(a, b, que, k);
               AgreaterBsw(a, b, que, k);
               AgreaterBne(a, b, que, k);
            }

            if (a + b < 7)
            {
               AgreaterBse(a, b, que, k);
               AgreaterBnw(a, b, que, k);
               AgreaterBsw(a, b, que, k);
               AgreaterBne(a, b, que, k);
            }
         }
         else if (a > b && a == 7)
         {
            AgreaterBnw(a, b, que, k);
            AgreaterBne(a, b, que, k);
         }

      }

   }
      else ;
      {
         System.out.println("Enter the digit between 1 to 64 to place the Queen");
      }
      for (int i = 0; i < 8; i++)
      {
         for (int j = 0; j < 8; j++)
         {
            System.out.print("  " + que[i][j]);
         }
         System.out.println();
      }
   }
}


   public static void AgreaterBse(int a,int b, int [][] que, int k)
   {
      if (a>=b)
      {
         for (int i = a + 1; i <= 7; ++i)
         {
            for (int j = b + 1; j < b + 2; ++j)
            {
               que[i][j] = k;
            }
            ++b;
         }
      }
      else if(a<b)
      {
         for (int i = b+1; i <= 7; ++i)
         {
            for (int j = a+1; j < a + 2; ++j)
            {
               que[j][i] = k;
            }
            ++a;
         }
      }
   }
   public static void AgreaterBnw(int a,int b, int [][] que, int k)
   {
      if (a>=b)
      {
         for (int i = b - 1; i >= 0; i--) {
            for (int j = a - 1; j > a - 2; j--) {
               que[j][i] = k;
            }
            a--;
         }
      }
      else if (a<b)
      {
         for (int i = a - 1; i >= 0; i--)
         {
            for (int j = b - 1; j > b - 2; j--)
            {
               que[i][j] = k;
            }
            b--;
         }
      }
   }
   public static void AgreaterBne(int a,int b, int [][] que, int k) {
      if (a + b >= 7) {
         for (int i = b + 1; i <= 7; i++) {
            for (int j = a - 1; j > a - 2; j--) {
               que[j][i] = k;
            }
            a--;
         }
      } else {
         for (int i = a - 1; i >= 0; --i) {
            for (int j = b + 1; j < b + 2; ++j) {
               que[i][j] = k;
            }
            ++b;
         }
      }
   }



   public static void AgreaterBsw(int a,int b, int [][] que, int k)
   {
      if (a+b>=7)
      {
         for (int i = a + 1; i <= 7; ++i)
         {
            for (int j = b - 1; j > b - 2; --j)
            {
               que[i][j] = k;
            }
            --b;
         }
      }
      else      {
         for (int i = b - 1; i >= 0; --i)
         {
            for (int j = a + 1; j < a + 2; ++j)
            {
               que[j][i] = k;
            }
            ++a;

         }
      }
   }

}

Wednesday, 17 April 2019



8 QUEENS program using the C#

                     In this page you can see how to make the 8 queens program in the c# language.

What is 8 queens game  :

      Every one knows how to play the chess in that most power full, dangerous and second most tallest piece in the chess board.

      And know you have to keep the 8 queens in the chess board so that non of the queen can kill the other one. There is a probability that you can keep only 6, 7 and 8 of them maximum number of placing the queens is 8. 

And u can see the code bellow.    







Bellow photo will be the actual output and when you gave the in put between 1 to 64 it will convert in to the rows and columns of the the chess board and replace the number that you gave as "8" and powers of the queen (All the vertical, horizontal and the diagonal rows will be placed with the "1")   



Code starts from here

using System;

namespace ConsoleApp17
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = 0, b = 0;
            int[,] que = new int[8, 8];
         


            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    que[i, j] = 0;
                    Console.Write(" " + que[i, j]);
                }

                Console.WriteLine();

            }
           
            //for (int k1 = 8; k1 > 0; k1--)
                for (int k1 = 8; k1 > 0 ; k1--)
            {
                int k = 1;
               

                Console.WriteLine("Select a value between 1 to 64 to plase the qween ");
                Console.WriteLine("number of chancess left is : "+k1   );

                int n = Int32.Parse(Console.ReadLine());
                n = n - 1;
             

                if (n <= 64)
                {
                    b = n % 8;  // It will produce reminder and this will be the columns
                    a = n / 8;    // It will gives the rows for the chess board
                    Console.WriteLine(a);
                    Console.WriteLine(b);
                    int w = a;
                    int x = b;
                    int d = a;
                    int e = b;
                    int f = a;
                    int g = b;
                    int r = a;
                    int s = b;
                    int r1 = 1;
                    int s1 = b;
                    if (que[a, b] == 0)
                    {

                        que[a, b] = 8;                     // It will place the  "0" with the "8"


                        for (int j = 0; j < 8; j++)        // this if loop will place will block all the  columns
                        {
                            if (que[a, j] == 0)
                            {



                                if (j > 8)
                                {
                                    j = j % 8;
                                    //k = r1;
                                    que[a, j] = k;
                                }
                                else
                                {
                                    que[a, j] = k;
                                }

                            }
                        }




                        for (int i = 0; i < 8; i++)   // this if loop will place will block all the  horizontal placess
                        {
                            if (que[i, b] == 0)
                            {


                                if (i > 8)
                                {
                                    i = i % 8;
                                    que[i, b] = k;
                                }
                                else
                                {

                                    que[i, b] = k;
                                }

                            }
                        }
                       


                        // This part of the code will block all the diagonal placess in the the chess board
                       
                        if (a>b)
                        {
                         
                            if (a!=7)
                            {
                                for (int z = 0; z < 2; z++)
                                {

                                    if (z == 0)
                                    {

                                       for (int i = w + 1; i <= 7; ++i)
                                        {
                                            for (int j = x + 1; j < x + 2; ++j)
                                            {
                                                que[i, j] = k;
                                            }
                                            ++x;

                                        }

                                        for (int i = e - 1; i >= 0; i--)
                                        {
                                            for (int j = d - 1; j > d - 2; j--)
                                            {
                                                que[j, i] = k;
                                            }
                                            d--;

                                        }
                                       
                                        if (a + b > 7)
                                        {
                                         

                                            for (int i = g + 1; i <= 7; ++i)
                                            {

                                                for (int j = f - 1; j > f - 2; --j)
                                                {
                                                    que[j, i] = k;
                                                }
                                                --f;

                                            }

                                            for (int i = r + 1; i <= 7; ++i)
                                            {
                                                for (int j = s - 1; j > s - 2; --j)
                                                {
                                                    que[i, j] = k;
                                                }
                                                --s;

                                            }
                                        }

                                        if (a + b <= 7)
                                        {


                                            for (int i = f - 1; i >= 0; --i)
                                            {

                                                for (int j = g + 1; j < g + 2; ++j)
                                                {
                                                    que[i, j] = k;
                                                }
                                                ++g;

                                            }

                                            for (int i = s - 1; i >= 0; --i)
                                            {
                                                for (int j = r + 1; j < r + 2; ++j)
                                                {
                                                    que[j, i] = k;
                                                }
                                                ++r;

                                            }
                                        }
                                    }
                                   
                                   
                                }
                            }

                            else
                            {
                                for (int i = e - 1; i >= 0; i--)
                                {
                                    for (int j = d - 1; j > d - 2; j--)
                                    {
                                        que[j, i] = k;
                                    }
                                    d--;

                                }

                               
                                for (int i = s + 1; i <= 7; ++i)
                                {
                                        for (int j = r - 1; j > r - 2; --j)
                                        {
                                            que[j, i] = k;
                                        }
                                        --r;

                                }
                               
                            }

                        }
                       
                         if (a < b)
                        {
                         
                            if (b != 7)
                            {
                                for (int z = 0; z < 2; z++)
                                {

                                 
                                    if (z == 0)
                                    {
                                       
                                         for (int i = x+1; i <= 7; ++i)
                                         {
                                             for (int j = w+1; j < w + 2; ++j)
                                             {
                                                 que[j, i] = k;
                                             //   Console.WriteLine(que[i, j] = k);

                                            }
                                            ++w;

                                         }
                                     }

                                    if (z == 0)
                                    {
                                        if (a+b <= 7)
                                        {
                                            for (int i = f - 1; i >= 0; --i)
                                            {
                                                for (int j = g + 1; j < g + 2; ++j)
                                                {
                                                    que[i, j] = k;
                                                }
                                                ++g;

                                            }

                                            for (int i = s - 1; i >= 0; --i)
                                            {
                                                for (int j = r + 1; j < r + 2; ++j)
                                                {
                                                    que[j, i] = k;
                                                }
                                                ++r;

                                            }
                                        }

                                       else if(a+b>7)
                                        {
                                            for (int i = f + 1; i <= 7; ++i)
                                            {
                                                for (int j = g - 1; j > g - 2; --j)
                                                {
                                                    que[i, j] = k;
                                                }
                                                --g;

                                            }
                                            for (int i = s + 1; i <= 7; ++i)
                                            {
                                                for (int j = r - 1; j > r - 2; --j)
                                                {
                                                    que[j, i] = k;
                                                }
                                                --r;

                                            }
                                        }

                                     
                                    }


                                    else
                                    {
                                       




                                        for (int i = d - 1; i >= 0; i--)
                                        {
                                            for (int j = e - 1; j > e - 2; j--)
                                            {
                                                que[i, j] = k;
                                            }
                                            e--;
                                        }
                                       

                                     

                                    }
                                }
                            }

                            else
                            {
                               
                                for (int i = f + 1; i <= 7; ++i)
                                {
                                    for (int j = g - 1; j > g - 2; --j)
                                    {
                                        que[i, j] = k;
                                    }
                                    --g;

                                }

                                for (int i = d - 1; i >= 0; i--)
                                {
                                    for (int j = e - 1; j > e - 2; j--)
                                    {
                                        que[i, j] = k;
                                    }
                                    e--;
                                }


                            }
                           
                        }
                       
                       
                        else if (a == b)
                        {
                         
                            if (a != 7)
                            {
                                for (int z = 0; z < 2; z++)
                                {
                                 
                                    if (z == 0)
                                    {

                                         for (int i = w+1; i <= 7; ++i)
                                        {
                                            for (int j = x+1; j < x + 2; ++j)
                                            {
                                                que[i, j] = k;
                                            }
                                            ++x;
                                           
                                        }

                                        for (int i = d - 1; i >= 0; i--)
                                        {
                                            for (int j = e - 1; j > e - 2; j--)
                                            {
                                                que[i, j] = k;
                                            }
                                            e--;

                                        }

                                        if (a+b<=6)
                                        {
                                            for (int i = f - 1; i >= 0; --i)
                                            {
                                                for (int j = g + 1; j < g + 2; ++j)
                                                {
                                                    que[i, j] = k;
                                                }
                                                ++g;

                                            }

                                            for (int i = s - 1; i >= 0; --i)
                                            {
                                                for (int j = r + 1; j < r + 2; ++j)
                                                {
                                                    que[j, i] = k;
                                                }
                                                ++r;

                                            }
                                        }

                                        if (a+b>=8)
                                        {
                                            for (int i = f + 1; i <= 7; ++i)
                                            {
                                                for (int j = g - 1; j > g - 2; --j)
                                                {
                                                    que[i, j] = k;
                                                }
                                                --g;

                                            }
                                            for (int i = s + 1; i <= 7; ++i)
                                            {
                                                for (int j = r - 1; j > r - 2; --j)
                                                {
                                                    que[j, i] = k;
                                                }
                                                --r;

                                            }
                                        }
                                    }

                                 
                                }
                            }

                            else
                            {
                                for (int i = a - 1; i >= 0; --i)
                                {
                                    for (int j = b - 1; j > b - 2; --j)
                                    {
                                        que[i, j] = k;
                                    }
                                    --b;

                                }
                            }
                           
                        }

                        for (int i = 0; i < 8; i++)
                        {
                            for (int j = 0; j < 8; j++)
                            {
                                Console.Write(" " + que[i, j]);
                            }

                            Console.WriteLine();
                        }



                    }

                    else
                    {
                        Console.WriteLine("quween cannot be plased hear");
                        que[a, b] = que[a, b] - 8;
                        k1 = k1 - 1;
                    }

                 


                }


                else
                {
                    Console.WriteLine("Please enter the digits between 1 to 64");
                }

            }
        }
    }
}

Friday, 10 March 2017

PROJECT WORLD

PROJECTS FOR STUDENTS

  • voice recognition robot 
            This project consist of two weals that operated by a voice control device. 
            To know how it work go to the link given below
             
            video-1  
                         https://www.youtube.com/watch?v=yXNq37mC0nU
         
             video-2
                         https://www.youtube.com/watch?v=aUkLd2MncHg&t=312s

  • Motion sensor using PIR sensor
          This project consist of PIR sensor and a arduino to sens the motion
          To know how it work go to the link given below
             
            video-1  
                        https://www.youtube.com/watch?v=6Fdrr_1guok  


  • Gesture controlled car

          This project consist of gesture controller sensor on which accelerometer is built on it
          and it controller the movement of car
          To know how it work go to the link given below
       
          video-1
  • Zigbee based wireless electronic notice board
          In this project we use bluetooth and zigbee to give instructions to wireless electronic notice                 board
          To know how it work go to the link given below
          
         video-1
                     https://www.youtube.com/watch?v=dw0ngjUYRXc
  • Cell phone detector
          In this project we will detect when a call coming from from other phone or when call is making           from the phone near the circuit

         video-1
                       https://www.youtube.com/watch?v=xW-hXU7MWnM
  •