Question
I need java code for implementation vacuum cleaner by The Model-Based Agent I have 2 classes which are : package ai.vacuum; public interface EnvironmentInterface {
I need java code for implementation vacuum cleaner by "The Model-Based Agent"
I have 2 classes which are :
package ai.vacuum;
public interface EnvironmentInterface {
public int moveLeft();
public int moveRight();
public int moveUp();
public int moveDown();
public void suck(); // clean current cell
public boolean isDirty(); // is current cell dirty?
public int getScore(); // returns penalty score
}
and the environment class like this
package ai.vacuum;
import java.util.Scanner;
import java.util.ArrayList;
public class VacuumMain {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int rows,cols,dirt;
ArrayList rDirt = new ArrayList();
ArrayList cDirt = new ArrayList();
System.out.println("Enter the number of Rows: ");
rows = input.nextInt();
System.out.println("Enter the number of Columns: ");
cols = input.nextInt();
System.out.println("Enter the number of Dirty cells: ");
dirt = input.nextInt();
Environment env = new Environment(rows,cols,dirt);
//Scan for dirt
for(int i=0;i
if(i!=0 ){
env.moveDown();
}
for(int j=0;j
boolean x = env.isDirty();
if(x==true){
rDirt.add(env.getRow());
cDirt.add(env.getColumn());
}
if(j!=(cols-1)){
if(i==0 || i%2==0){
env.moveRight();
}
else{
env.moveLeft();
}
}
}
}
env.reset();
System.out.println(" Environment before cleaning:");
System.out.println(env.toString());
System.out.println(" Locations of Dirt:");
for(int i=0;i
System.out.println("("+rDirt.get(i)+","+cDirt.get(i)+")");
}
//Clean dirt
for(int i=0;i
if(!rDirt.isEmpty()){
for(int d=0;d
if(rDirt.get(d)==i){
int moves=cDirt.get(d)-env.getColumn();
if(moves==0){
env.suck();
System.out.println(" Clean:");
System.out.println(env.toString());
}
else if(moves>0){
for(int j=0;j
env.moveRight();
System.out.println(" Move Right:");
System.out.println(env.toString());
}
env.suck();
System.out.println(" Clean:");
System.out.println(env.toString());
}
else if(moves<0){
for(int j=0;j>moves;j--){
env.moveLeft();
System.out.println(" Move Left:");
System.out.println(env.toString());
}
env.suck();
System.out.println(" Clean:");
System.out.println(env.toString());
}
rDirt.remove(d);
cDirt.remove(d);
d--;
}
}
}
So, I need to create a Model-Based agent that follows the tiles until it reaches the goal tiles. At the start, the agent should just move forward until it hits a wall. Once it hits a wall, it should turn left and start following the tiles of the floor until it finds the goal. Create an agent MyModelBasedAgent.java.
To accomplish this, the agent will use some memory to store percepts obtained from its environment. In this case, the memory is simply whether or not the agent has hit a wall or not. This can be determined using the return of the moveRight() command the same as Task 3.
So, start by creating the memory bit. For example, you could use:
boolean hitWall;
Initialize this variable as false. Now to code up the agent, you should make it move forward until it hits a wall. Then, the agent should follow the tiles to its left using moveLeft() and moveDown() functions. This will take some thinking, but very little code is needed. The code should be able to reach the goal (Dirty cell) and be able to clean all dirt in the environment.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started