Anda di halaman 1dari 5

//EXP NO-10 WUMPUS WORLD PROBLEM

import java.io.*;
import java.util.*;
class Wumpus
{
public static void main(String args[]) throws IOException
{
Scanner cin=new Scanner(System.in);
int a=0;
int b=0;
int path[][]=new int[20][2];
boolean visit[][]=new boolean[5][5];
int score=0;
for(int i=0;i<5;i++)
for(int j=0;j<5;j++)
visit[i][j]=false;
boolean Stench=false;
boolean breeze=false;
boolean bump=false;
boolean glitter=false;
boolean scream=false;
boolean arrow=true;
boolean gold=false;
String wump[][]=new String[5][5];
System.out.println("ENTER THE POSITION OF THE GOLD");
System.out.println("ROW NUMBER");
a=cin.nextInt();
System.out.println("COLUMN NUMBER");
b=cin.nextInt();
wump[a][b]="GOLD";
System.out.println("ENTER THE POSITION OF THE WUMPUS");
System.out.println("ROW NUMBER");
a=cin.nextInt();
System.out.println("COLUMN NUMBER");
b=cin.nextInt();
wump[a][b]="WUMPUS";
System.out.println("ENTER THE NUMBER OF THE PITS");
int n=cin.nextInt();
for(int i=0;i<n;i++)
{
System.out.println("ENTER THE POSITION OF THE PIT");
System.out.println("ROW NUMBER");
a=cin.nextInt();
System.out.println("COLUMN NUMBER");
b=cin.nextInt();
wump[a][b]="PIT";
}
System.out.println();
System.out.println();
System.out.println();
wump[1][1]="AGENT";
System.out.println("THE SCENARIO IS AS FOLLOWS ");
for(int i=4;i>=1;i--)
{
for(int j=1;j<5;j++)
{if(wump[i][j]==null)
System.out.print(" ");
else
System.out.print(wump[i][j]+ " ");}

System.out.println();
}
int count=0;
int i=1;
int j=1;
while(gold!=true)
{
visit[i][j]=true;
path[count][0]=i;
path[count++][1]=j;
Stench=checkstench(wump,i,j);
glitter=checkglitter(wump,i,j);
breeze=checkbreeze(wump,i,j);
bump=checkbump(wump,i,j);
System.out.println();
System.out.println("AGENT IS CURRENTLY AT "+i+ " "+j);
System.out.println("STENCH
GLITTER
BREEZE
BUMP");
System.out.println(Stench +"
"+glitter+"
"+breeze+"
"+bump);
if(wump[i+1][j]=="GOLD")
i++;
else if(glitter==true)
{System.out.println("AS HE PERCEIVES GLITTER HE HAS GOT THE GOLD");
gold=true;score+=1000;}
else if(breeze==true)
{System.out.println("AS AGENT PERCEIVES BREEZE HE COMES BACK");
j--;score-=1;
}
else if(Stench==true)
{int k=i+1;
System.out.println("AS STENCH IS PERCEIVED THE AGENT WILL SHOOT AN ARROW
");
score-=10;
System.out.println("SCORE IS : "+ score);
scream=checkscream(wump,k,j,arrow);
arrow=false;
System.out.println("ARROW USED");
System.out.println("SCREAM : "+scream);
if(scream==true)
{System.out.println("ARROW USED AND WUMPUS KILLED AT "+k+" "+ j);
i++;
score-=1;
}
else
{System.out.println("ARROW USED AND WUMPUS NOT KILLED AT "+k+" "+ j);
i++;score-=1;
}
}
else if(visit[i][j+1]==true)
{System.out.println("AGENT NOW GOES UP");
i++;score-=1;}
else
{ j++;
System.out.println("AGENT MOVES FORWARD");score-=1;}
System.out.println("SCORE IS : "+ score);
}
System.out.println();
System.out.println("THE PATH FOLLOWED IS");

for(int a1=0;a1<count;a1++)
System.out.println(path[a1][0] +" "+ path[a1][1]);
System.out.println("AS HE HAS STORED THE PATH IN HIS KNOWLEDGE BASE
");
System.out.println("HE COMES BACK TO THE START BACK FOLLOWING THE SA
ME PATH");
}
public static boolean checkbreeze(String x[][],int a,int b)
{
if(x[a][b+1]=="PIT" || x[a+1][b]=="PIT")
return true;
return false;
}
public static boolean checkscream(String x[][],int a,int b,boolean arrow
)
{
if(x[a][b]=="WUMPUS" && arrow==true)
return true;
return false;
}
public static boolean checkbump(String x[][],int a,int b)
{
if(x[a][b]=="PIT")
return true;
return false;
}
public static boolean checkglitter(String x[][],int a,int b)
{
if(x[a][b]=="GOLD")
return true;
return false;
}
public static boolean checkstench(String x[][],int a,int b)
{
if(x[a][b+1]=="WUMPUS" || x[a+1][b]=="WUMPUS")
return true;
return false;
}
}
/*OUTPUT
ENTER THE POSITION OF THE GOLD
ROW NUMBER
3
COLUMN NUMBER
2
ENTER THE POSITION OF THE WUMPUS
ROW NUMBER
3
COLUMN NUMBER
1
ENTER THE NUMBER OF THE PITS
2
ENTER THE POSITION OF THE PIT
ROW NUMBER
2
COLUMN NUMBER

3
ENTER THE POSITION OF THE PIT
ROW NUMBER
1
COLUMN NUMBER
3

THE SCENARIO IS AS FOLLOWS


WUMPUS GOLD
PIT
AGENT
PIT
AGENT IS CURRENTLY AT 1 1
STENCH
GLITTER
BREEZE
false
false
false
AGENT MOVES FORWARD
SCORE IS : -1
AGENT IS
STENCH
false
AS AGENT
SCORE IS

BUMP
false

CURRENTLY AT 1 2
GLITTER
BREEZE
BUMP
false
true
false
PERCEIVES BREEZE HE COMES BACK
: -2

AGENT IS CURRENTLY AT 1 1
STENCH
GLITTER
BREEZE
false
false
false
AGENT NOW GOES UP
SCORE IS : -3

BUMP
false

AGENT IS CURRENTLY AT 2 1
STENCH
GLITTER
BREEZE
BUMP
true
false
false
false
AS STENCH IS PERCEIVED THE AGENT WILL SHOOT AN ARROW
SCORE IS : -13
ARROW USED
SCREAM : true
ARROW USED AND WUMPUS KILLED AT 3 1
SCORE IS : -14
AGENT IS CURRENTLY AT 3 1
STENCH
GLITTER
BREEZE
false
false
false
AGENT MOVES FORWARD
SCORE IS : -15

BUMP
false

AGENT IS CURRENTLY AT 3 2
STENCH
GLITTER
BREEZE
BUMP
false
true
false
false
AS HE PERCEIVES GLITTER HE HAS GOT THE GOLD
SCORE IS : 985
THE PATH FOLLOWED IS
1 1
1 2
1 1
2 1

3
3
AS
HE
*/

1
2
HE HAS STORED THE PATH IN HIS KNOWLEDGE BASE
COMES BACK TO THE START BACK FOLLOWING THE SAME PATH