Vous êtes sur la page 1sur 4

Bo co bi tp ln Mn tr tu nhn to

Tn ti: Game C Caro

Ging vin hng dn: Hunh Th Thanh Thng

Sinh vin thc hin lp CS106.E11:


Phm nh Sng Phm Ngc nh 10520219 10520237

Bo co tin ln 2 1. M t bi ton.
Game caro l th loi game i khng gia 2 ngi chi(c th l my-ngi chi, ngi chi-ngi chi). C 2 qun c X v O mi ngi ln lt in qun c ca mnh ln sn chi l mt li cc vung vi kch thc xc nh (20x20). Ngi thng l ngi i c 5 qun c cng kiu trn mt ng thng theo hng ngang, hng dc, ng cho v khng b chn st nt c hai u. c im ca tr chi: C hai u th, mi u th ch c i mt nc khi ti lt. Cc u th u bit mi thng tin v tnh trng trn u. Trn u khng ko di v tn, phi din ra ha hoc mt bn thng v mt bn thua. Ta c th thy mi cch sp xp cc qun c X,O trn bn c sn chi 20x20 l mt trng thi. Tp hp cc trng tt c cc trng thi ny l khng gian trng thi ca tr chi ny. Trng thi bt u l trng thi m sn chi trng. Cc ton t (dn t trng thi ny sang trng thi khc) l cc nc i hp l (nh X hoc nh O ln bn c lm thay i th c). Trng thi kt thc l trng thi m c 5 qun c cng kiu trn mt ng thng theo hng ngang, hng dc, ng cho v khng b chn st nt hai u hoc bn c ht ch nh v cha c ngi thng.

2. Cu trc d liu:
S dng mng 2 chiu lu trng thi ca bn c. Cc trng thi ca bn c (hay cn gi l cc th c hay cc tnh hung c) trong qu trnh chi c th biu din thnh mt cy tm kim (c gi l cy tr chi hnh 1.1). Mi node trong cy biu hin mt th c, cc nhnh ni gia cc nt s cho bit t mt tnh hung bn c chuyn sang tnh hung khc thng qua ch mt nc i no (ton t chuyn trng thi) Nh vy bi ton tr thnh bi ton tm kim cc trng thi trong khng gian trng thi t c mc tiu l trang thi kt thc. Mi lt chi, ngi chi chn mt trong cc trng i mt nc do khng gian chn nc i t mt trng thi l hu hn

nhng khng gian tm kim nc i ti trng thi kt thc l ln.V d:

T mt th c, trung bnh c kh nng i c 16 nc i khc nhau( ta gi l h s nhnh con ti mi nt l b=16). Nh vy, sau mt tng ta s c 16 nt con, mi nt ny li c 16 nt con na. tng s nt con su th 2 l 16x16= b 2 vy c su d s c b d nt. Gi s su ca cy l 20 (h s nhnh 16 v su 20 thng l cc con s nh hn cc con s hay gp trong tr chi c caro), vy th phi c 1622 = 3.09x 1026 mt con s ln khng khip.

Hnh 1.1 Cy tr chi. Khng gian tm kim ny c th hin bi mt cy a phn gi l cy tm kim.

Hnh 1.2 Tm kim trn cy tr chi V y cy tr chi qu ln nn trong v d ch gii hn li bn c kch thc 3x3, ta s c mt phn ca cy nh sau:

Hnh 1.3 mt phn ca cy tr chi caro 9 .