AI algorithms with alpha beta stratagy 1

tpvvsreenivasarao 43 views 26 slides May 29, 2024
Slide 1
Slide 1 of 26
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26

About This Presentation

very good ppt


Slide Content

1RCS702/Unit-2
Subject Name:-Artificial Intelligence
Subject Code:-RCS702
Unit No.:-2
Lecture No.:-6
Topic Name :-Alpha-Beta Algorithm
Er. Hiresh Kumar Gupta
Department of CSE

Content
1.Alpha-Beta Pruning
2.Condition for alpha-beta pruning
3.Pseudo-code for Alpha-beta Pruning
4.Working of Alpha-Beta Pruning
5.Example
6.Important Questions
RCS702/Unit-2 2

Alpha-Beta Pruning
•Alpha-betapruningisamodifiedversionoftheminimaxalgorithm.It
isanoptimizationtechniquefortheminimaxalgorithm.
•Aswehaveseenintheminimaxsearchalgorithmthatthenumberof
gamestatesithastoexamineareexponentialindepthofthetree.Since
wecannoteliminatetheexponent,butwecancutittohalf.Hencethere
isatechniquebywhichwithoutcheckingeachnodeofthegametree
wecancomputethecorrectminimaxdecision,andthistechniqueis
calledpruning.ThisinvolvestwothresholdparameterAlphaandbeta
forfutureexpansion,soitiscalledalpha-betapruning.Itisalso
calledasAlpha-BetaAlgorithm.
•Alpha-betapruningcanbeappliedatanydepthofatree,and
sometimesitnotonlyprunethetreeleavesbutalsoentiresub-tree.
3RCS702/Unit-2

•Thetwo-parametercanbedefinedas:
–Alpha:Thebest(highest-value)choicewehavefoundsofarat
anypointalongthepathofMaximizer.Theinitialvalueofalpha
is-∞.
–Beta:Thebest(lowest-value)choicewehavefoundsofaratany
pointalongthepathofMinimizer.Theinitialvalueofbeta
is+∞.
•TheAlpha-betapruningtoastandardminimaxalgorithm
returnsthesamemoveasthestandardalgorithmdoes,butit
removesallthenodeswhicharenotreallyaffectingthe
finaldecisionbutmakingalgorithmslow.Hencebypruning
thesenodes,itmakesthealgorithmfast.
4RCS702/Unit-2

Condition for Alpha-beta pruning
•Themainconditionwhichrequiredforalpha-betapruning
is:
α>=β
•TheMaxplayerwillonlyupdatethevalueofalpha.
•TheMinplayerwillonlyupdatethevalueofbeta.
•Whilebacktrackingthetree,thenodevalueswillbepassed
touppernodesinsteadofvaluesofalphaandbeta.
•Wewillonlypassthealpha,betavaluestothechildnodes.
5RCS702/Unit-2

Pseudo-code for Alpha-beta Pruning
functionminimax(node,depth,alpha,beta,maximizingPlayer)is
ifdepth==0ornodeisaterminalnodethen
returnstaticevaluationofnode
ifMaximizingPlayerthen//forMaximizerPlayer
maxEva=-infinity
foreachchildofnodedo
eva=minimax(child,depth-1,alpha,beta,False)
maxEva=max(maxEva,eva)
alpha=max(alpha,maxEva)
ifbeta<=alpha
6RCS702/Unit-2

break
returnmaxEva
else //forMinimizerplayer
minEva=+infinity
foreachchildofnodedo
eva=minimax(child,depth-1,alpha,beta,true)
minEva=min(minEva,eva)
beta=min(beta,eva)
ifbeta<=alpha
break
returnminEva
7RCS702/Unit-2

Working of Alpha-Beta Pruning
Let'stakeanexampleoftwo-playersearchtreeto
understandtheworkingofAlpha-betapruning:
•Step1:Atthefirststepthe,Maxplayerwillstart
firstmovefromnodeAwhereα=-∞andβ=+∞,
thesevalueofalphaandbetapasseddowntonode
Bwhereagainα=-∞andβ=+∞,andNodeB
passesthesamevaluetoitschildD.
8RCS702/Unit-2

9RCS702/Unit-2

•Step2:AtNodeD,thevalueofαwillbe
calculatedasitsturnforMax.Thevalueofαis
comparedwithfirstly2andthen3,andthemax
(2,3)=3willbethevalueofαatnodeDand
nodevaluewillalso3.
•Step3:NowalgorithmbacktracktonodeB,
wherethevalueofβwillchangeasthisisaturn
ofMin,Nowβ=+∞,willcomparewiththe
availablesubsequentnodesvalue,i.e.min(∞,3)
=3,henceatnodeBnowα=-∞,andβ=3.
10RCS702/Unit-2

11RCS702/Unit-2

•Inthenextstep,algorithmtraversethenextsuccessor
ofNodeBwhichisnodeE,andthevaluesofα=-∞,
andβ=3willalsobepassed.
•Step4:AtnodeE,Maxwilltakeitsturn,andthevalue
ofalphawillchange.Thecurrentvalueofalphawillbe
comparedwith5,somax(-∞,5)=5,henceatnodeE
α=5andβ=3,whereα>=β,sotherightsuccessorofE
willbepruned,andalgorithmwillnottraverseit,and
thevalueatnodeEwillbe5.
12RCS702/Unit-2

13RCS702/Unit-2

•Step5:Atnextstep,algorithmagainbacktrackthetree,
fromnodeBtonodeA.AtnodeA,thevalueofalphawill
bechangedthemaximumavailablevalueis3asmax(-∞,
3)=3,andβ=+∞,thesetwovaluesnowpassestoright
successorofAwhichisNodeC.
•AtnodeC,α=3andβ=+∞,andthesamevalueswillbe
passedontonodeF.
•Step6:AtnodeF,againthevalueofαwillbecompared
withleftchildwhichis0,andmax(3,0)=3,andthen
comparedwithrightchildwhichis1,andmax(3,1)=3still
αremains3,butthenodevalueofFwillbecome1.
14RCS702/Unit-2

15RCS702/Unit-2

•Step7:NodeFreturnsthenodevalue1to
nodeC,atCα=3andβ=+∞,herethevalueof
betawillbechanged,itwillcomparewith1so
min(∞,1)=1.NowatC,α=3andβ=1,and
againitsatisfiestheconditionα>=β,sothe
nextchildofCwhichisGwillbepruned,and
thealgorithmwillnotcomputetheentiresub-
treeG.
16RCS702/Unit-2

17RCS702/Unit-2

•Step8:Cnowreturnsthevalueof1toAhere
thebestvalueforAismax(3,1)=3.
Followingisthefinalgametreewhichisthe
showingthenodeswhicharecomputedand
nodeswhichhasnevercomputed.Hencethe
optimalvalueforthemaximizeris3forthis
example.
18RCS702/Unit-2

19RCS702/Unit-2

Move Ordering in Alpha-Beta pruning
Theeffectivenessofalpha-betapruningishighlydependenton
theorderinwhicheachnodeisexamined.Moveorderisan
importantaspectofalpha-betapruning.Itcanbeoftwotypes:
•Worstordering:Insomecases,alpha-betapruningalgorithm
doesnotpruneanyoftheleavesofthetree,andworksexactly
asminimaxalgorithm.Inthiscase,italsoconsumesmoretime
becauseofalpha-betafactors,suchamoveofpruningiscalled
worstordering.Inthiscase,thebestmoveoccursontheright
sideofthetree.Thetimecomplexityforsuchanorderis
O(b
m
).
20RCS702/Unit-2

•Idealordering:Theidealorderingforalpha-
betapruningoccurswhenlotsofpruning
happensinthetree,andbestmovesoccurat
theleftsideofthetree.WeapplyDFShenceit
firstsearchleftofthetreeandgodeeptwiceas
minimaxalgorithminthesameamountof
time.ComplexityinidealorderingisO(b
m/2
).
21RCS702/Unit-2

Example
RCS702/Unit-2 22

Important Questions
Solved following question by alpha-beta pruning
method-
1. 2.
RCS702/Unit-2 23

3.
RCS702/Unit-2 24

References
Text Book:
Stuart Russell, Peter Norvig, “Artificial Intelligence –A Modern Approach”,
Pearson Education
Reference Book:
Elaine Rich and Kevin Knight, “Artificial Intelligence”, McGraw-Hill
Other:
https://www.javatpoint.com/ai-alpha-beta-pruning
https://www.mygreatlearning.com/blog/alpha-beta-pruning-in-ai/
https://www.geeksforgeeks.org/minimax-algorithm-in-game-theory-set-4-alpha-beta-pruning/
25RCS702/Unit-2

Thank You
26RCS702/Unit-2
Tags