You are on page 1of 6

Department of Computer Exp.

Semester VI
Subject Artificial Intelligence
Subject Professor In- Prof. Sachin Deshpande
charge
Assisting Teachers Prof. Sachin Deshpande
Laboratory

Student Name Pratik Rathod


Roll Number 19102A0056
Grade and Subject
Teacher’s Signature

Experiment Number 5

Experiment Title Implementation of Bot Clean Problem.


Resources / Hardware: Software: C Programming
Apparatus Required Computer System
Theory The goal of Artificial Intelligence is to create a rational agent. An agent
gets input from the environment through sensors and acts on the
environment with actuators. In this challenge, you will program a simple
bot to perform the correct actions based on environmental input.
Meet the bot MarkZoid. It's a cleaning bot whose sensor is a head
mounted camera and whose actuators are the wheels beneath it. It's used
to clean the floor.
The bot here is positioned at the top left corner of a 5*5 grid. Your task
is to move the bot to clean all the dirty cells.
Input Format
The first line contains two space separated integers which indicate the
current position of the bot. 
The board is indexed using Matrix Convention 
5 lines follow representing the grid. Each cell in the grid is represented
by any of the following 3 characters: 'b' (ascii value 98) indicates the
bot's current position, 'd' (ascii value 100) indicates a dirty cell and '-'
(ascii value 45) indicates a clean cell in the grid.
Note If the bot is on a dirty cell, the cell will still have 'd' on it.
Output Format
The output is the action that is taken by the bot in the current step, and it
can be either one of the movements in 4 directions or cleaning up the cell
in which it is currently located. The valid output strings are LEFT,
RIGHT, UP and DOWN or CLEAN. If the bot ever reaches a dirty cell,
output CLEAN to clean the dirty cell. Repeat this process until all the
cells on the grid are cleaned.

Program Code
Department of Computer Exp.5
#include<stdio.h>

#include<string.h>

void next_move(int posr, int posc, char board[5][5])

int i,j,c=0,l,r,u,d,cl=0;

l=r=u=d=0;

while(c<=25)
{

if(board[posr][posc]=='d')

{ printf("CLEAN\n"); cl=1; }

board[posr][posc]='v';

if(posc < 4 && !l && board[posr][posc+1] != 'v')

r=1;

else if(posr < 4 && !u && board[posr+1][posc] != 'v')

d=1;

else if(posc>0 && !r && board[posr][posc-1] != 'v')

l=1;

else if(!d && board[posr-1][posc] != 'v')

u=1;

// printf("\n(%d,%d) l=%d r=%d u=%d d=%d


",posr,posc,l,r,u,d);

if(l==1 )

{ if(!cl) printf("LEFT\n"); --posc; }

else if(r==1 )

{ if(!cl) printf("RIGHT\n"); ++posc; }


Department of Computer Exp.5
else if(u==1 )

{ if(!cl) printf("UP\n"); --posr; }

else if(d==1 )

{ if(!cl) printf("DOWN\n"); ++posr; }

++c;

if(posc==4 || board[posr][posc+1] == 'v') r=0;

if(posc==0 || board[posr][posc-1] == 'v') l=0;

if(posr==4 || board[posr+1][posc] == 'v') d=0;

if(posr==0 || board[posr-1][posc] == 'v') u=0;

cl=0;

int main(void) {

int pos[2], i;

char board[5][5], line[6];

scanf("%d", &pos[0]);

scanf("%d", &pos[1]);

for(i=0; i<5; i++) {

scanf("%s[^\\n]%*c", line);

strncpy(board[i], line, 5);

next_move(pos[0], pos[1], board);

return 0; }
Department of Computer Exp.5
Output

Conclusion In this experiment we learned the Bot clean problem in AI.


Department of Computer Exp.5
Department of Computer Exp.5

You might also like