Tuesday, October 2, 2018

EIGHT PUZZLE PROGRAM IN JAVA.

 





8 PUZZLE PROGRAM.
The Eight-Puzzle program basically a 3x3 matrices.in that Three row was given and Three column.
The Task was is to Rearrange the row and column in a series wise..so as you can see in the start state the matrix Puzzle number was given Randomly.so The Task of goal state is to Rearrange in the sequence of 1,2,3,4.....9..for that purpose you can see a sample code of 8 Puzzle written in java.


CODE:-

class Node
{
    Node children[]=null;
    Node parent=null;
    int puzzle[][]=null;
    
    Node(int p[][],Node pa)
    {
        puzzle=p;
        parent=pa;
    }
    
    public void print()
    {
        System.out.println("**********");
        for (int i=0;i<puzzle.length;i++)
        {
            for (int j=0;j<puzzle.length;j++)
            {
                System.out.print(puzzle[i][j]);
                
            }
            System.out.println("");
        }
        System.out.println("**********");
    }
    
    public void printChildren()
    {
        for (int i=0;i<4;i++)
    {
        if(children[i]!=null)
        {
            (children[i]).print();
        }
    }
    }
    
    public void expand()
    {
        children=new Node[4];
        children[0]=expandDown();
        children[1]=expandUp();
        children[2]=expandLeft();
        children[3]=expandRight();
    }
    
    public Node expandDown()
    {
        Node n=new Node(puzzle.clone(),this);
        int zeroXY[]=n.getZero();
        if(zeroXY[1]-1>0 && zeroXY[1]-1<puzzle.length)
        {
            int temp=n.puzzle[zeroXY[0]][zeroXY[1]];
            n.puzzle[zeroXY[0]][zeroXY[1]]=n.puzzle[zeroXY[0]][zeroXY[1]-1];
            n.puzzle[zeroXY[0]][zeroXY[1]-1]=temp;
            n.print();
            return n;
        }
        else
        {
            return null;
        }
        
        
    }
    
    public Node expandUp()
    {
        Node n=new Node(puzzle.clone(),this);
        int zeroXY[]=n.getZero();      
        if(zeroXY[1]+1>0 && zeroXY[1]+1<puzzle.length)
        {
            int temp=n.puzzle[zeroXY[0]][zeroXY[1]];
            n.puzzle[zeroXY[0]][zeroXY[1]]=n.puzzle[zeroXY[0]][zeroXY[1]+1];
            n.puzzle[zeroXY[0]][zeroXY[1]+1]=temp;
            n.print();
            return n;
        }
        else
        {
            return null;
        }
        
        
    }
    
    public Node expandRight()
    {
        Node n=new Node(puzzle.clone(),this);
        int zeroXY[]=n.getZero();
        if(zeroXY[0]+1>0 && zeroXY[0]+1<puzzle.length)
        {
            int temp=n.puzzle[zeroXY[0]][zeroXY[1]];
            n.puzzle[zeroXY[0]][zeroXY[1]]=n.puzzle[zeroXY[0]+1][zeroXY[1]];
            n.puzzle[zeroXY[0]+1][zeroXY[1]]=temp;
            n.print();
            return n;
        }
        else
        {
            return null;
        }
        
    }
    
    public Node expandLeft()
    {
        Node n=new Node(puzzle.clone(),this);
        int zeroXY []=n.getZero();
        if(zeroXY[0]-1>0 && zeroXY[0]-1<puzzle.length)
        {
            int temp=n.puzzle[zeroXY[0]][zeroXY[1]];
            n.puzzle[zeroXY[0]][zeroXY[1]]=n.puzzle[zeroXY[0]-1][zeroXY[1]];
            n.puzzle[zeroXY[0]-1][zeroXY[1]]=temp;
            n.print();
            return n;
        }
        else
        {
            return null;
        }
        
    }
    
    
    
    int[] getZero()
    {
        int[] n=new int[2];
        for (int i=0;i<puzzle.length;i++)
        {
            for (int j=0;j<puzzle.length;j++)
            {
                if(puzzle[i][j]==0)
                {
                    n[0]=i;
                    n[1]=j;
                    //System.out.println(n[0]+","+n[1]);
                    return n;
                }
            }          
        }
        return null;
    }
}
class Puzzle8
{
    final static int GOAL [][]={{1,2,3},{4,5,6},{7,8,0}};  
    public static void main(String args[])
    {
        int board[][]={{1,2,3},{4,5,6},{7,8,0}};   
    Node Start=new Node(board,null);
    Start.expand();
    Start.printChildren(); 
    }
}

Wednesday, September 12, 2018

WHAT IS INTELLIGENT AGENTS IN ARTIFICAL INTELLIGENCE ??

                                  FIGURE:-INTELLIGENT AGENT IN AI.

 INTELLIGENT AGENT is something that perceives its environment through "Sensors"(INPUT) and acts upon the environment through "Actuators"(OUTPUT).
The Basic Ability of Intelligent Agent are to Exist to be Self-Governed,Responsive,Goal-directed,etc.
Ability of Remain Autonomous(self-directed).
  • RESPONSIVE
  • GOAL-ORIENTED
EXAMPLE:-TAKE A SMALL EXAMPLE OF HUMAN AGENT.
(1)HUMAN AGENT:-
It Has Five Sense:-Eyes,Ears,Nose,Skin,Tongue.This Senses Sense the Environment are called "SENSOR".
"ACTUATORS"are organs or tools using which the Agent acts  upon the Environment.
In Case of Human Agents we have Hands,Legs,as Actuators.

Q.WHAT IS AGENT???
ANS:-AGENT IS A COMBINATION OF ARCHITECTURE PLUS PROGRAM
AGENT=ARCHITECTURE+PROGRAM.

 After understanding What is Agent??and What is Human agent?.
let's try to Figure out Sensor and Actuators for a Robotics agents.

 The Robotics Agent has Camera,Infrared Sensors,Scanner,etc.used as a "Sensor".While Various Types of  Motors,Screen,Printing,Devices, etc.used as a "Actuators".
 

 


 

INTRODUCTION TO ARTIFICAL INTELLIGENCE.




 INTRODUCTION:-

  • JOHN McCarthy who has coined the word of "Artifical Intelligence in 1956.
  • He Define the word of artifical intelligence as "THE SCINCE AND ENGINEERING OF MAKING AN INTELLIGENT MACHINE".
  • Artifical Intelligence is basically relevant  to any Task where the Machine need to take some Decision or Choose the next action based on on Current state of the System 
  

Q..What  is Artifical Intelligence???

ARTIFICAL INTELLIGENCE something like a machine learning....that can work and behaves like a human....

  • Artifical Intelligence is a branch of computer science ..the aim of the AI is used to create intelligent machine.
  • This generally involves borrowing characteristics from human intelligence, and applying them as algorithms in a computer friendly way. 
  • Robotics is also a major field related to AI.
  • Artificial intelligence can be viewed from a variety of perspectives . 
  1.  From the perspective of intelligence  artificial intelligence is making machines "intelligent" -- acting as we would expect people to act.
  2.   From a business perspective AI is a set of very powerful tools, and methodologies for using those tools to solve business problems. 
    3. From a programming perspective, AI includes the study of symbolic programming, problem solving, and search.  
  • Artificial Intelligence is a new electronic machine that stores large amount of information and process it at very high 
  • GUYS THIS WAYS ONLY THE INTRODUCTION ABOUT ARTIFICAL INTELLIGENCE...IN MY NEXT SESSION I WILL GIVE YOU A BRIEF INFORMATION ON ARTIFICAL INTELLIGENCE TOPIC WISE...