AL
INTELLIG
ENCE
Mrs. Jhilik
Bhattacharya
Name: Sumeet Lalla
Roll No: 101203104
Group: COE9
1.
Tower of Hanoi
NTRIALS = 100
player_win = board.check_win()
if winner == player:
match_score = MCMATCH
other_score = -1 * MCOTHER
else:
match_score = -1 * MCMATCH
other_score = MCOTHER
scores[row][col] += match_score
else:
scores[row][col] += other_score
ret_move = moves[random.randrange(len(moves))]
return ret_move
"""
scores = [[0 for dummy_x in range(board.get_dim())] for dummy_y in range(board.get_dim())]
for _ in range(trials):
trial_board = board.clone()
mc_trial(trial_board, player)
mc_update_scores(scores, trial_board, player)
3.
#include<stdio.h>
#include<conio.h>
struct node
{
int x, y;
struct node *next;
}*root, *left, *right;
void DFS()
{
struct node *temp;
temp = left;
printf(DFS Result\nStart State :: (%d , %d)\n, root->x, root->y);
printf(Possible DFS Result 1\n);
while(1)
{
printf((%d , %d)\n, temp->x, temp->y);
if(temp->next == NULL)
break;
temp = temp->next;
}
temp = right;
printf(Possible DFS Result 2\n);
while(1)
{
printf((%d , %d)\n, temp->x, temp->y);
if(temp->next == NULL)
break;
temp = temp->next;
}
}
int isNodePresent(struct node *nextState, int maxJug1, int maxJug2, int reqJug1, int reqJug2)
{
struct node *temp;
if((nextState->x == reqJug1) && (nextState->y == reqJug2))
return(0);
if((nextState->x == maxJug1) && (nextState->y == maxJug2))
return(1);
if((nextState->x == 0) && (nextState->y == 0))
return(1);
temp = left;
while(1)
{
if((temp->x == nextState->x) && (temp->y == nextState->y))
return(1);
else if(temp->next == NULL)
break;
else
temp = temp->next;
}
temp = right;
while(1)
{
if((temp->x == nextState->x) && (temp->y == nextState->y))
return(1);
else if(temp->next == NULL)
break;
temp = temp->next;
}
return(0);
}
struct node* genNewState(struct node *crntState, int maxJug1, int maxJug2, int reqJug1, int
reqJug2)
{
int d;
struct node *nextState;
nextState->x = maxJug1;
nextState->y = crntState->y;
if(isNodePresent(nextState, maxJug1, maxJug2, reqJug1, reqJug2) != 1)
return(nextState);
nextState->x = crntState->x;
nextState->y = maxJug2;
if(isNodePresent(nextState, maxJug1, maxJug2, reqJug1, reqJug2) != 1)
return(nextState);
nextState->x = 0;
nextState->y = crntState->y;
if(isNodePresent(nextState, maxJug1, maxJug2, reqJug1, reqJug2) != 1)
return(nextState);
nextState->y = 0;
nextState->x = crntState->x;
if(isNodePresent(nextState, maxJug1, maxJug2, reqJug1, reqJug2) != 1)
return(nextState);
nextState->x = crntState->x d;
nextState->y = crntState->y + d;
}
if(isNodePresent(nextState, maxJug1, maxJug2, reqJug1, reqJug2) != 1)
return(nextState);
}
void main()
{
int maxJug1, maxJug2, reqJug1, reqJug2;
clrscr();
printf(Enter the maximum capacity of jug1
::
);
::
);
scanf(%d, &maxJug1);
printf(Enter the maximum capacity of jug2
scanf(%d, &maxJug2);
printf(Enter the required water in jug1
::
);
::
);
scanf(%d, &reqJug1);
printf(Enter the required water in jug2
scanf(%d, &reqJug2);
generateTree(maxJug1, maxJug2, reqJug1, reqJug2);
DFS();
BFS(reqJug1, reqJug2);
getch();
}
Test Cases: 4 3 0 2
3420