How to make artificial intellegence from this code (simple reflex agent)?

Discussion in 'Software' started by erdy_rezki, Sep 22, 2012.

  1. erdy_rezki

    erdy_rezki Private E-2

    Code:
    package pib;
    
    import java.util.Random;
    
    /**
     *
     * @author Developer
     */
    public class PIB {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            // TODO code application logic here
            int[][] arrayangka = new int[12][12];
            int baris,kolom,randomcounter=0;
            Random rand= new Random ();
            
            for(baris=0;baris<12;baris++)
            {
                for(kolom=0;kolom<12;kolom++)
                {
                    if ((baris==0) || (baris==11) || (kolom==0) || (kolom==11))
                        arrayangka[baris][kolom]=-1;
                }
            }
            
            while (randomcounter<20)
            {
                baris = rand.nextInt(11);
                kolom = rand.nextInt(11);
                
                if (arrayangka[baris][kolom] == 0)
                {
                    arrayangka[baris][kolom] = -1;
                    randomcounter=randomcounter+1;
                }
            }
            
            for(baris=0;baris<12;baris++)
            {
                for(kolom=0;kolom<12;kolom++)
                {
                    if (arrayangka[baris][kolom]==-1)
                    System.out.print(arrayangka[baris][kolom]);
                    else
                    System.out.print(" "+arrayangka[baris][kolom]);
                }
                System.out.println();
            }
            
        }
    }
    
     

    Attached Files:

  2. PC-XT

    PC-XT Master Sergeant

    Between the last two loops (while and for) you will need another that runs until the required ending condition is met. (You may also need a setup procedure before the loop to set up the beginning state of the reflex agent.) Each iteration of the loop will use if statements to look at the current state of the agent and its surroundings, and move or otherwise adjust the agent's state. In this case, it looks like you want to trace the path it takes, but I don't know what the rules are other than the goal is probably to get to the other corner. It looks like it starts top left corner, going right as far as it can, then down if it can. I assume if it can't go down, it will not go back on its path, but that means it won't get to its destination when it could only by backtracking. Maybe backtracking is a last resort. This is the kind of stuff you need to figure out, then put into the code as if statements.

    Note: some simple reflex agents have an internal state, while others don't. Either way, they rely on their environment to make simple if-then decisions. They don't really learn like some other agents do. I wouldn't need an internal state to implement the rules I gave above.
     
  3. erdy_rezki

    erdy_rezki Private E-2

    im not really understand about backtrack but thank you for the answer
     
  4. PC-XT

    PC-XT Master Sergeant

    backtracking = going back on its path

    An agent will often either look ahead if it sees danger is possible or backtrack after it finds some. Looking ahead is usually better to make as few moves as possible, while backtracking can sometimes be easier to implement. You just need to think ahead, and plan for anything you expect the agent to encounter. A simple agent knows the whole map, so there are many different ways to plan this out.

    As an example of the need for backtracking, say, if the agent I described in the last post has a map with this layout at the start:
    Code:
    #######
    #   #
    # # #
    # ###
    #
    It would go right into the spiral, then need to backtrack over the path it already made or it would be stuck there. If the tunnel trap was longer, it may need an internal state to remember which direction it last took to help decide which direction to backtrack. To not use an internal state, it could look ahead while backtracking or, to have the most efficient travel time, it could look ahead before going in there in the first place. It could also get stuck if the start or end was completely sealed off, but there's no way around that, other than to report failure.
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds