0% found this document useful (0 votes)
1 views3 pages

AI Assignment

The document discusses adversarial search, explaining its use in well-defined rule sets and multi-agent environments where agents aim to defeat each other. It also evaluates true/false statements regarding game theory concepts, particularly in zero-sum games, and presents a Python program for solving the N Queen Problem, detailing its logic and structure. The program checks for queen placements on a chessboard while ensuring no queens attack each other.

Uploaded by

abdulsamad.lgu
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views3 pages

AI Assignment

The document discusses adversarial search, explaining its use in well-defined rule sets and multi-agent environments where agents aim to defeat each other. It also evaluates true/false statements regarding game theory concepts, particularly in zero-sum games, and presents a Python program for solving the N Queen Problem, detailing its logic and structure. The program checks for queen placements on a chessboard while ensuring no queens attack each other.

Uploaded by

abdulsamad.lgu
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Lahore Garrison University

Department:

BSSE (5th semester) section-B

Submitted to:

[Link] Alvi

Submitted by:

Abdul Samad (Fa-2018/BSSE/069)


Q:2 When should one use adversarial search?

Ans: Adversarial search is used when well defined set of rules are given.
Multi-agent environment introduced.
Both agents wants to defeat another by optimal move.
Evolution becomes easy.

Q:3 Which of the following are true and which are false? Give brief
explanations.

a) In a fully observable, turn-taking, zero-sum game between two perfectly rational


players, it does not help the first player to know what strategy the second player is
using—That is, what move the second player will make, given the first player’s move.
Ans: TRUE, first player knows the optimal behavior of the second player in advance.

b) In a partially observable, turn-taking, zero-sum game between two perfectly rational


Players, it does not help the first player to know what move the second player will
Make, given the first player’s move.
Ans: FALSE, knowledge about moves of opponent always help.

c) A perfectly rational backgammon agent never loses.


Ans: FALSE, Backgammon agent is a Stochastic Game.
Q:4 Write python program for N Queen Problem and explain how it works.
#Number of queens
print ("Enter The Number Of
Queens") N = int(input())

#chessboard
#NxN matrix with all
elements 0 board = [[0]*N for
_ in range(N)]

def is_attack(i, j):


#checking if there is a queen in row or
column for k in range(0,N):
if board[i][k]==1 or board[k][j]==1:
return True
#checking
diagonals for k in
range(0,N):
for l in range(0,N):
if (k+l==i+j) or (k-l==i-j):
if board[k][l]==1:
return
True return False

def N_queen(n):
#if n is 0, solution
found if n==0:
return True
for i in range(0,N):
for j in range(0,N):
'''checking if we can place a queen here or not
queen will not be placed if the place is being
attacked or already occupied'''
if (not(is_attack(i,j))) and (board[i][j]!=1):
board[i][j]
=1
#recursion
#wether we can put the next queen with this arrangment or
not if N_queen(n-1)==True:
return
True
board[i][j]
=0

return False

N_queen(N)
for i in
board:
print (i)

You might also like