You are on page 1of 26

Lp trnh game c tng basic

C TNG - PHIN BN U TIN (VERY SIMPLE CHINESE CHESS PROGRAM -


VSCCP 1.0)
Tc gi: PHM HNG NGUYN

I. Gii thiu

Tr chi C Tng (tn phin m Trung Quc XiangQi, tn ting Anh Chinese Chess) l mt
minh ho rt tt cho bi ton tm kim trn cy tr chi v p dng thut ton AlphaBeta trn cy
ny nh th no. y l mt tr chi th v v tng i ph bin Vit nam, chu cng nh
trn ton th gii. N to cm gic dng nh my tnh c th suy ngh v sc vi con ngi
(thc t cho n nay n vn ch tnh ton m thi). C Tng l loi c c phc tp v rt
nhiu mt tng ng vi c Vua.

Trong phn ny, chng ti s gii thiu vi bn nhng kin thc c bn nht v mt chng
trnh chi c phi nh th no. Cc chng trnh mu VSCCP (Very Simple Chinese Chess
Program - Chng trnh C Tng rt n gin) cng ht sc n gin v c y trong cc
ph lc.



II. Vit chng trnh chi c VSCCP 1.0
1. Biu din bn c v qun c

Bn c trong tr chi c Tng l mt bng ch nht bao gm 9 ng dc v 10 ng ngang.
Cc qun c chia lm hai bn ng ti cc giao im ca cc ng. Bn c v v tr khi u
cc qun c nh hnh 2.1. Cch n gin nht biu din mt bn c trong my tnh l ta dng
mt mng hai chiu, kch thc 9 x 10:
piece: array[1..10, 1..9] of byte

Mng trn hot ng tt nhng c ci bt tin l ta phi dng ti hai ch s truy cp vo mng
(v d v tr qun Pho gc trn bn tri (ct 2, dng 3) l piece[3, 2]). Mt ci tin nh l ta dng
mng mt chiu nh sau:
piece: array[1..90] of byte

Truy nhp n v tr qun Pho gc trn bn tri lc ny l piece[20].


Cc ca mng s cha nhng gi tr khc nhau cho bit l qun c g. Mi qun c s c
gn mt m s khc nhau nh bng di y. Cc ch trng (khng c qun c) s c in k
hiu trng (EMPTY):
















































Qun c K hiu Gi tr
Tt (Cht) PAWN 1
S BISHOP 2
Tng ELEPHANT 3
M KNIGHT 4
Pho CANNON 5
Xe ROOK 6
Tng KING 7
Trng EMPTY
0


Ngoi mc ch gn mi qun c mt m s phn bit, m ny cn gip ta c lng s b
tm quan trng ca qun c .

Nh vy, lc khi u, cc trong mng s c gn cc gi tr qun c nh khai bo const
(trong Pascal) nh di, trong BOARD_SIZE (kch thc bn c = 90) l mt hng s
c nh ngha trc :
PHP:
piece: array[1..BOARD_SIZE] of byte =
( 6, 4, 3, 2, 7, 2, 3, 4, 6,
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 5, 0, 0, 0, 0, 0, 5, 0,
1, 0, 1, 0, 1, 0, 1, 0, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 1, 0, 1, 0, 1, 0, 1,
0, 5, 0, 0, 0, 0, 0, 5, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
6, 4, 3, 2, 7, 2, 3, 4, 6);
n y, bn c cn cha c thng tin phn bit mt qun c l ca bn no. Ta c th ci
tin thay cho kiu byte ca mng piece l mt bn ghi nhm lu thm cc thng tin ny. Chng
ti xin gii thiu mt phng php n gin l dng thm mt mng na - mng color, lu
cc thng tin v bn. Hai bn c gn k hiu v m nh bng di. Nhng ch trng s dng
cng k hiu trng EMPTY.





















Bn K hiu Gi tr
en DARK 1
Trng LIGHT 2
Trng EMPTY
0


Ta li c thng tin v bn c khai bo khi u tng t:
PHP:
color: array[1..BOARD_SIZE] of byte =
(1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 0, 0, 0, 0, 0, 1, 0,
1, 0, 1, 0, 1, 0, 1, 0, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
2, 0, 2, 0, 2, 0, 2, 0, 2,
0, 2, 0, 0, 0, 0, 0, 2, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
2, 2, 2, 2, 2, 2, 2, 2, 2);
bit bn no ti lt i, ta dng mt bin ton cc side cha mt trong hai gi tr LIGHT v
DARK. Mt bin ton cc khc xside s c sn gi tr ngc vi side tin tnh ton (v d nu
side = LIGHT th xside = DARK). Khi ti phin i phng i, ta cn o ngc gi tr trong c
side v xside bng cc lnh nh sau (ch l LIGHT+DARK = 3):
side := xside; xside := 3 - xside;

Ngoi ra, ta cn khai bo bin computerside cng ch c mt trong hai gi tr LIGHT v DARK
nhm cho bit bn no l my. hin bn c, phng php n gin nht l hin ch text
(vn bn). Tuy cch ny trng xu v thng khng dng trong cc chng trnh c trn th
trng nhng n c cc u im ni tri sau:
Vn hin c bn c rt y , trc quan, d hiu, cho php theo di v thi
u bnh thng.
Rt n gin v tin cy. Bn s nhiu thi gian tm hiu v pht trin giao
din, dn sc cho vic quan trng hn - lm chng trnh chi hay hn. Giao
din ho ch cn thit lc hon chnh - lc bn "ng gi" chng trnh.
Vic hin thm cc thng tin kim tra, tm li rt d dng. R rng vic
dng hai th tc c sn ca Pascal l gotoxy v write th d, nhanh v m
bo hn cc hm ho.
D chuyn i h my v h iu hnh. C th bn s mun th chy trn
nhng my tnh c nn tng khc nh my mini, macintosh, h iu hnh
Windows 3.1, Win95, Win98, WinNT, System7, UNIX...
Bn c th t pht trin giao din ho v ci chut theo mnh.
Qun c c biu din bng mt ch ci vit hoa ng u tn ca n. Qun hai bn s c mu
khc nhau. Do qun Tng v Tng c cng ch ci u T nn trnh nhm ln ta dng ch
V (Voi) biu din qun Tng. Tuy qun Tt v Tng cng c cng ch ci u nhng ta
khng s nhm do Tt khng th nhp cung bn mnh c. N ch c th "tip chuyn" Tng
i phng, nhng lc ny hai bn li phn bit c nh mu (cc phng php khc l dng
ch ci u tn ting Anh: P-Tt, E-Tng, N-M, B-S, R-Xe, C-Pho, K-Tng; hoc theo qui
nh ca Lin on c Vit Nam: Tg-Tng, S-S, T-Tng, X-Xe, P-Pho, M-M, C-Cht).

Ta s hin bn c dng nh hnh 2.3. Ch cch nh k hiu cc v tr trong bn c bng ch
v s ging nh bn c Vua.

hin mt qun c, ta vit mt th tc DrawCell vi tham s l v tr bn c. Ngoi ra, n cn
mt tham s na cho bit s hin mu nn ca qun c vi mu bnh thng NORMAL (s c
nn en) hay mu khc SELECT (s c nn xanh sm) th hin qun c c chn (phc
v cho chn v i qun ca ngi chi).

procedure DrawCell(pos, mode: byte);

Nh vy, hin ton b bn c ta ch cn gi mt vng lp for l xong:

for i := 1 to BOARD_SIZE do DrawCell(i, NORMAL);




2. Sinh nc i

Mt trong nhng vic quan trng nht my tnh c th chi c c l phi ch cho n bit
mi nc i c th i c t mt th c. My s tnh ton chn nc i c li nht cho n.
Cc yu cu chnh i vi mt th tc sinh nc i l:
Chnh xc (rt quan trng). Mt nc i sai s lm hng mi tnh ton. ng
thi chng trnh c th b trng ti x thua lun. Do s lng nc i sinh
ra ln, lut i qun nhiu v phc tp nn vic kim tra tnh ng n tng
i kh.
y (rt quan trng). Sinh c mi nc i c th c t mt th c.
Nhanh. Do chc nng ny phi sinh c hng triu nc i mi khi my
n lt nn gim thi gian sinh nc i c ngha rt ln.
Sinh nc i l mt thut ton vt cn. My s tm mi nc i hp l c th c. My phi sinh
c t nhng nc i rt hay cho n nhng nc i rt ng ngn (nh y Tng vo v tr
khng ch ca i phng). Ta hnh dung ngay th tc sinh nc i Gen s c y nhng vng
lp for, cc cu lnh kim tra if v r nhnh case, trong cc php tnh kim tra gii hn chim
mt phn ng k. Th tc ny lun sinh nc cho bn ang ti lt chi cn c vo ni dung
ca bin side. y l mt trong nhng th tc phc tp v d sai nht.

Mt nc i c hai gi tr cn quan tm. l im xut pht (from) v im n (dest). Ta s
khai bo mt cu trc move nh sau dng nhng ni cn n d liu nc i.

type
move = record { nh ngha cu trc nc i }
from, dest: byte;
end;




Kim tra gii hn bn c
V d c mt qun Xe nm s 84 (trong mng piece). By gi ta s sinh th mt nc i sang
tri mt cho n. Nc i sang tri mt c chuyn thnh s 83 l mt v tr cng hng vi
xut pht nn c chp nhn. Mt nc i khc cn phi xem xt l sang tri ba - 81.
81 tuy c trong bn c nhng khc hng nn khng c chp nhn. Nh vy, mun bit ca
nc i sang tri c c php khng ta phi kim tra xem n c cng hng vi xut pht
khng. Vic kim tra thc hin bng cch chia cho 9 (kch thc ca mt dng) v ly phn
nguyn (trc li phi chuyn th t v gc l 0 bng cch tr i 1). Ta thy ((83-1) div 9)
= ((84-1) div 9) nn 83 c chp nhn; trong khi do ((81-1) div 9) <> ((84-1) div 9) nn
kt lun l nc i n 81 khng hp l (hnh 2.5).


Cc nc i va sinh ra s c a vo danh sch nc i nh gi th tc Gen_push. Th tc
ny c hai tham s l v tr xut pht ca qun c s i v ni n dest ca qun c .
Di y l on chng trnh dng sinh nhng nc i sang tri ca mt qun Xe, trong
x l v tr ca qun Xe ny .
PHP:
i := x - 1; { Nc sang tri u tin }
while ((i-1) div 9) = ((x-1) div 9) do
begin
if ( th i l trng) or ( th i c qun i phng) then
gen_push(v tr ca Xe, v tr ang xt);
if th i khng trng then
break; { Kt thc qu trnh sinh nc i sang tri }
i := i - 1; { Xt tip v tr bn tri }
end;
Vic sinh nhng nc i theo chiu khc cng tng t (v d sinh nc i theo chiu ng ta
ch cn cng hoc tr mt bi s ca 9) nhng iu kin kim tra s khc nhau. Nh vy, chng
trnh sinh nc i Gen c dng nh sau:

for Xt ln lt tng qun c bn hin ti do
case qunc of
Xe: begin
while Xt ln lt tt c cc t bn phi Xe cho n l tri bn c do
begin
if ( ang xt l trng) or ( ang xt cha qun i phng) then
gen_push(v tr ca Xe, v tr ang xt)
if ang xt khng trng then break;
end;

while Xt ln lt tt c cc t bn tri Xe cho n l phi bn c do
...
while Xt ln lt tt c cc t bn trn Xe cho n l trn bn c do
...
while Xt ln lt tt c cc t bn di Xe cho n l di bn c do
...
end; { Xong qun Xe }

Pho:
...

Phng php ny c nhc im l chng trnh phi vit phc tp, cng knh, kh tm li
nhng kh nhanh.

Trong chng trnh mu VSCCP, chng ti gii thiu mt k thut khc c tn gi l "hp th"
(mail box - do cc bng ca n c dng cc hp phn th). Mc ch chnh ca k thut ny l
nhm gim bt cc php kim tra vt gii hn bn c v lm n gin chng trnh. Mu cht
l thay cho bn c c kch thc bnh thng 9x10 = 90, ta dng mt bn c m rng, mi chiu
c thm 2 ng na (bn c mi c kch thc 13x14 = 182). Cc ng vi cc ng bao m
rng u c gi tr -1, tc l cc gi tr bo vt bin. Cc nc i trn bn c 9x10 c chuyn
tng ng sang bn c ny. Nu mt nc i c sinh ra li ri vo mt trong hai ng bao
th c ngha n ri ra ngoi bn c ri, phi b i v ngng sinh nc v pha . S d c n
hai ng bin (ch khng phi mt) do qun M v Tng c th nhy xa n hai (hnh 2.6).



Vic chuyn i to thc hin nh hai mng. Mng mailbox90 dng chuyn t to bn
c thng sang to bn c mi. Mng ng vi bn c mi - mailbox182 dng kim tra cc
nc i vt qu ng bin v d liu chuyn tr li to bnh thng.

V d, nu v tr qun Xe nm s 84 (trong mng piece) nh hnh 2.5, th khi i sang bn c
m rng s thnh v tr mailbox90[84] = 148. C ngha l n ng vi th 148 ca mng
mailbox182. By gi ta s sinh th mt nc i sang tri mt cho qun Xe ny. Vic sinh v
kim tra s c thc hin trong bn c m rng, nc i mi l s 148 - 1 = 147. Do
mailbox182[147] = 83 -1 nn nc i ny c chp nhn. S 83 cho bit kt qu sang tri mt
l v tr 83 trong bn c bnh thng. Tuy nhin, nc i sang tri ba , c s 148 - 3 = 145 v
mailbox182[145] = -1 cho bit l mt nc i khng hp l.

Chng trnh cng cn kim tra s nc i ti a theo mt hng ca qun c ang xt. Ch c
qun Pho v Xe c th i n 9 nc i, cn cc qun khc c nhiu nht l 1.

Vic i mt qun sang v tr mi thc cht l ta thay i to ca n bng cch cng vi
mt hng s (dng hoc m). trn ta thy qun Xe sang tri mt nc ta phi cng
v tr hin ti vi -1. sinh mt mi theo hng dc, ta phi cng vi +13 hoc -13 (ch ,
vic sinh nc v kim tra hp l u da vo mng mailbox182 nn gi tr 13 l kch thc mt
dng ca mng ny). sinh cc nc i cho ta phi cng tr vi mt hng s khc. Ta nn lu
cc hng s ny vo mng offset c 2 chiu. Mt chiu da vo loi qun c nn ch s c
nh t 1 n 7. Chiu cn li l s hng i ti a ca mt qun c.

Qun c c nhiu hng nht l qun M c ti 8 hng nn chiu ny c khai bo ch s t 1
n 8. Cc qun c c s hng t hn s c in 0 vo phn tha. Ch l nc i qun Tt
ca hai bn khc nhau hng tin. tit kim ta ch lu nc tin ca Tt en, cn nc tin
ca Tt trng ch n gin ly ngc du.

Kim tra v tr c php n
Vic chuyn to t bn c thng sang bn c m rng ch gip ta loi b c cc nc
vt qu bin. Ta cn phi kim tra mt s gii hn khc. V d nh Tng v S khng th i ra
ngoi cung, Tng ch c php 7 im c nh pha bn mnh, Tt ch c php tung
honh trn t i phng, cn pha bn mnh cng b gii hn ngt ngho mt s ... thc
hin nhng php kim tra ny, ta dng mt mng l legalmove ng vi tng trn bn c s
cung cp cc thng tin ny. kim tra mt qun c c c php khng, ta dng mt mt
n bt Maskpiece m tu theo tng qun s c gi tr khc nhau. Nu cn kim tra c bit
trng vi mt n ny c t l 1 th qun c c php n y.




V d, s 3 c gi tr legalmove[3] = 5 (chuyn thnh s nh phn l 00000101) cho bit cc
qun c c php i n l Tng, Xe, Pho, M.

Ngoi ra, ta cn phi kim tra nc b cn (i vi Tng v M) v x l cch n qun ca qun
Pho nh mt trng hp c bit. Nh vy, tng th sinh cc nc i cho mt qun c c dng
nh sau:
PHP:
p := piece[i]; { Sinh nc i cho qun c p v tr i }
for j := 1 to 8 do begin { S hng i ti a }
if offset[p,j] = 0 then break;
x:=mailbox90[i]; { Chuyn sang bn c m rng}
if p in [ROOK, CANNON] then n := 9 else n := 1;
for t:=1 to n do { S nc c th i theo mt hng}
begin
if (p=PAWN) and (side=LIGHT) then x := x - offset[p, j]
else x := x + offset[p, j]; { Nc i mi }
y := mailbox182[x]; { Chuyn v to bnh thng }
if side = DARK then t := y else t := 91-y;
if (y=-1) or { Ra ngoi l ? }
((legalmove[t] and maskpiece[p])=0) { c php v tr ny khng ? }
then break; { Thot nu nc i khng hp l }

{ Kim tra nc cn vi Tng, M v x l Pho y }
...
Mt vn na l lut hai Tng khng c i mt trc tip vi nhau. Vic kim tra c
thc hin nh hm kingface. Hm s tr li gi tr true nu nc va i gy h mt Tng. Hm
ny c th c t trong th tc sinh nc Gen. Tuy nhin n gin hn, ta t n trong th tc
gen_push, nu h mt Tng th tc ny s khng a nc i vo danh sch cc nc i.

3. nh gi mt th c

nh gi mt th c l mt trong nhng nhim v quyt nh chng trnh chi c ca bn c l
"cao th" hay khng. Cn c vo mt th c my s gn cho n mt im s (lng gi tnh)
nh gi tt - xu. Nh im ny my mi c th so snh cc th c vi nhau v bit chn
nc i tt nht. y l mt nhim v rt kh khn v phc tp do khng tn ti mt thut ton
tng qut v thng nht no tnh im c. im ca mt th c da trn rt nhiu yu t m
kh c th s ho ht c nh ph thuc vo s lng v gi tr cc qun c hin ti, ph thuc
vo tnh hm, tnh bin, th cng, th th ca tng qun c cng nh c cc din trn u. V d,
mt cp M giao chn, c th st cnh tin qun v ta lng phng th thng c gi hn hai M
ng ri. Nhng cng c lc hai M ng ri li tt hn hai M giao chn khi M ny li cn
M kia trong mt th trn no . Ta cng bit rng, "lc nc hai Xe nh b ph, gp thi mt
Tt cng thnh cng", th nhng s ho iu ny qua hm lng gi qu l mt iu kh qu sc.
Chng ta bt u vi vic cng nhn cc gi thuyt sau:
1. Ta c th biu din cht lng mt th c bng mt con s. V d, con s
c th l nh gi ca ta v xc sut chin thng, nhng i vi a s chng
trnh th con s khng c g c bit, n ch l con s m mc ch chnh l
so snh c vi nhau.
2. Chng ta nn o cht lng ca mt th c tng t nh php o ca i
phng (do , nu ta coi l t c mt th tt th i phng ca ta phi
thy l th xu i vi h v ngc li). iu ny tuy khng tht ng
lm, nhng n gip cho thut ton tm kim ca ta lm vic tt v trong thc
t cng kh gn vi s tht.
Trong chng ny chng ta ch ci t phng php n gin nhng c bn nht: lng gi da
trn c s gi tr ca tng qun c. Cch tnh ny s ly tng gi tr cc qun c hin c ca bn
mnh tr i tng gi tr cc qun c hin c ca i phng. Do , mt th c ny hn th c
kia ch n cn nhiu qun bn mnh hn, nhiu qun gi tr cao hn cng nh c bt c
nhiu qun v qun gi tr cao ca i phng hn khng.

Cch lm ny b qua mt nhng ngh thut, chin lc chi c (m l nhng im
nh gi mt ngi l gii c hay khng). Cc qun c c trin khai khng theo mt chin
lc chung no ht (v nh). N cn to cm gic nh c "v", ngha l ch nhm nhm s h
ca i phng l "n" ngay m khng cn bit n hu qu (iu ny khng hn ng, l do s
trnh by di). Tuy nhin phng php tnh im ny c nhng u im sau:
L cch tnh im c bn nht, ng vai tr ch o trong im ca mt th
c. N l c s ca a s hm nh gi. Ta cng c th nhn thy trong phn
ln thi gian din ra trn u, hai bn u tm cch tiu dit qun ca nhau.
Cc phng n, chin lc thng ch c tnh nh nhng im cng thm
vo v ng gp mt t l nh trong tng s im ca mt th c. Vic ch
nhm "v" qun ca i phng nhng sau khi suy ngh su nhiu nc
cng tr thnh "cao c" ri y. Ni cho cng, mc ch chnh ca chng
ta cng l "v" bng c qun c gi tr cao nht - Tng i phng.
L cch tnh n gin nht v nhanh nht. Do tnh nhanh, ta c th tng thm
su tm kim. Vic tng thm su li gip my c ci nhn xa hn, "cao
c" hn v nhiu khi khc phc c nhc im ca cch tnh n gin.
im cc qun c c nh gi theo kinh nghim v cho bit s tng quan gia cc qun c.
Sau y l im tng qun m mi ngi thng chp nhn:





































Qun c K hiu im
Tt PAWN 1 (2 nu qua sng)
S BISHOP 2
Tng ELEPHANT 2
M KNIGHT 4
Pho CANNON 4.5
Xe ROOK
9


Bn cng c th theo bt k thang im no khc tu theo hiu bit v s thch ca mnh. V d
nh trong lng c Vit nam thng cho im cc qun hi khc (xem bi c di): Tt - 1 (2
nu qua sng), S - 2, Tng - 2.5, M - 4.5, Pho - 5, Xe - 10.

Trong chng trnh c ca chng ta, im c th ca tng qun c l cc s nguyn 10, 20, 20,
40, 45 v 90. Ta dng mt mng piecevalue lu im tng qun c. Cho im nh vy khng
nhng vn gi nguyn c tng quan v trnh dng s thc (tnh chm) m ta cn c mt
khong cch hp l gia cc im sau ny d dng thm nhng im b xung "thng" hoc
"pht", tc l nhng im cn c vo nhng yu t khc (v d cng l Pho nhng lc ch c
40 im do v tr "b", lc khc li c th n 85 do v tr Pho trng v ang e do Pho
lng).

Trong bn c, qun Tng l qun quan trng nht, d mt mi qun hoc t c th c no i
na u khng c mt Tng v n dn n thua c. Do , Tng thng c cho mt
im rt cao, cch bit nhiu ln so vi cc qun khc, m bo im tng ca cc qun cn li
cng mi loi "thng", "thm" u khng bng c Tng. Trong chng trnh, ta cho n
1000 im.

Hm lng gi tht n gin nh sau (ch l ta cha tng im cho Tt qua sng):
PHP:
function Eval: integer;
const piecevalue:array[1..7]of integer=(10,20,20,40,45,90,1000);
var i, s: integer;
begin
s := 0;
for i:=1 to BOARD_SIZE do begin
if color[i] = side then s := s + piecevalue[piece[i]]
else if color[i] = xside then s := s - piecevalue[piece[i]];
end;
Eval := s;
end;
Vn ci tin hm lng gi s c bn ring trong mt chng phn sau.

Tham kho kin thc c Tng

GI TR CA CC QUN C
Khi nim gi tr ca cc qun c khng phi l mi i vi nhng ngi chi c t cc th k
trc. T lu, lng c c cu nhn nh sc mnh ca cc qun ch lc l "Xe 10, Pho 7,
M 3" hoc nh gi Xe l qun ch lc mnh nht bng cu "Nht Xa st vn" hay nh gi
mt Tt qua h, sc mnh bng na con Xe (nht Tt h, bn Xa chi lc). Th nhng s nh
gi nhn nh ny v sc mnh ca cc qun khng chnh xc v cng khng y . Do khi
nim gi tr ca cc qun cn c xc nh r v hon chnh hn. Thng thng, theo thi gian
mt vn c c chia thnh ba giai on: khai cuc, trung cuc v tn cuc. Trong ba giai on
ny th trung cuc chim nhiu thi gian nht v c ngha n thng thua nhiu nht. Do
cc nh gi qun c thng l cho giai on ny.
Chng ta bit mi loi qun c hay mi binh chng c c im, tnh nng v tc dng khc
nhau nn sc mnh ca chng cng khc nhau, gi tr ca chng cng khng ging nhau. Ngay
bn thn mi qun c cng khng phi lc no sc mnh cng gi nguyn nh c. Khi ng v
tr tt n pht huy tnh nng tc dng ti a khc hn vi khi n ng v tr xu, khng th
pht huy tnh nng tc dng c, hay ch pht huy mc rt hn ch. Vy iu trc tin
chng ta phi thy mi qun c c hai gi tr: gi tr vn c v gi tr bin ng. Gi tr vn c
thng c gi l gi tr c bn (gi tr tnh), cn gi tr bin ng c gi l gi tr tng
i.

Cc nh nghin cu l lun v c trao i thng nht vi nhau bng gi tr c bn ca cc
qun nh sau:
Nu ly Tt cha qua sng lm chun xc nh gi tr th n l qun km nng lc nht trn
bn c. Khi cha qua sng n ch kim sot hay khng ch mi mt im trc mt n nn tm
cho n c gi tr bng 1. Khi Tt qua sng, n khng ch n 2 hay 3 im trc mt v bn
cnh (Tt bin ch khng ch c 2). By gi n mang gi tr tng i, phi thy n mnh hn
lc cha qua sng nn gi tr lc ny ca n phi bng 2.

i vi S, Tng l loi binh chng phng ng, c nhim v chnh l bo v an ton cho Tng,
i lc chng cng tr gip cc qun khc tn cng. Trong giai on trung cuc, Tt i
phng qua sng i c mt S hoc mt Tng. Do ngi ta nh gi S hoc Tng c
gi tr bng mt Tt qua sng, tc l bng 2. Nhng v so snh nng lc gia Tng v S th
thy Tng c phn c lc hn nn nh gi tr S l 2 th Tng phi l 2.5 mi cng bng.

Qun M trn bn c c kh nng khng ch ti a 8 im. Mi bc nhy ca n vt c hai
tuyn ng ngang hay dc. So ra th M cng mnh y nhng tc chin tm c ly ngn m
thi. Nu so vi hai Tt qua sng cp k nhau th nng lc ca M khng hn bao nhiu, do
nh gi tr c bn ca M 4.5 l va. Nn nh hai Tt cp k nhau khi qua sng phi c gi
tr hn 4.

Pho l binh chng tc chin tm xa rt c hiu qu. Trn ng dc, Pho khng ch ti a ch
8 im nhng n cn khng ch c c ng ngang. Mt khc Pho l qun c tnh c ng
cao, n c th i mt bc vt n 9 tuyn ng. Nhng c li gn, nhiu khi Pho bt lc,
khng lm g c khng ch i phng. Do so vi M th phi thy mi qun c mt s
trng ring, sc mnh ca chng coi nh tng ng nhau. Th nhng trong giai on trung
cuc qun s ca hai bn tng i cn nhiu, M i li d b cn tr, cn Pho th nhanh nhn
hn, d pht huy nng lc hn nn gi tr c bn ca Pho phi hn M mt cht v bng 5.

i vi Xe th r rng l mt binh chng c ng mnh nht, n khng ch ngang, dc ti a
n 17 im. Nu em Xe i ly mt Pho v mt M ca i phng th thy c phn thit thi
mt cht, cn i vi hai Pho th c th coi l cn bng. Do gi tr c bn ca Xe l 10.

Cn Tng, bn thn n khng c sc mnh g nhiu d i khi n cng lm c nhim v tr
gip cho cc qun phe n tn cng c kt qu. Th nhng gi tr c bn ca n th v cng to
ln, khng mt qun no so snh c. Tt c cc qun u c th i, c th hi sinh nhng
ring qun Tng khng th nh i m cng khng th hi sinh, v mt Tng l thua c. Do
cng khng nn nh gi tr c bn ca Tng v nh cng chng c ngha g.
(Su tm)


4. X l mt nc i "th"
Trong qu trnh tnh ton tm nc i tt nht cho mnh, my thng phi i "th" mt nc ri
li tnh tip. Sau n s phc hi li nc i ny. Do qu trnh th - phc hi din ra rt nhanh
v khng hin ra mn hnh nn my c th th hng chc triu ln mi khi n lt. Vic i th
c thc hin nh gi hm Makemove. Vic khi phc nc i ny nh gi th tc
UnMakemove. Nh vy, chng trnh thng xuyn thc hin cc cu lnh dng nh sau:
PHP:
while tt c cc nc i c th c t mt th c do begin
Makemove(mt_nc_i); { i th mt nc }
best := Tnh im ca nc i th ;
UnMakemove; { phc hi nc i ny}
Lu nc i c im cao nht;
end;
tnh c im ca nc i va thc hin, nhiu khi my li phi th i tip mt s nc na.
C nh vy cc hm Makemove v UnMakemove c th c gi lng nhau rt su.

Khi i th, hm Makemove phi lu li cc thng tin cn thit cho vic khi phc li sau ny.
Cch n gin nht - lu li c bn c, khng dng c do cc thng tin phi lu qu nhiu.
Thc cht, ta ch cn lu cc thng tin bao gm: im xut pht ca qun c, im n v loi
qun c m n bt c (nu c). lu cc thng tin ny, hm s dng mt mng hist_dat cc
bn ghi cha thng tin v con tr hdp c t chc nh mt ngn xp, ngha l nc i sau
cng s c phc hi trc nht.

Khi my i "th" cho mt bn mt nc, th nc sau s n lt i phng. Do hm ny
cng phi thay i gi tr cc bin ton cc v bn i v i th side v xside (vic thay i ny
l rt cn thit hm Gen sinh nc i cho ng bn ti lt). N cng tng bin ply ( su)
thm 1 do dn su thm mt bc trn cy tm kim.

Hm khi phc nc i th UnMakemove c nhim v l lm mi th ngc li vi hm
Makemove.
Mt vn ny sinh y l nu mt qun Tng b bt th c cn phi i "th" na khng. Nu
mt mt Tng, vn c s kt thc ngay lp tc, do khng cn phi i th tip v nhnh cy
tr chi b ct ti y d vn cha t n su tm kim ti a. Cn nu my i th tip,
my s coi Tng nh mt qun bnh thng (d c gi tr rt cao) v c th i qun c - n
sn sng mt Tng min l ngay sau n li c Tng i phng (hnh 2.8). Ta buc
phi ct nhnh nhng ni Tng b mt (hnh 2.9).




x l nhng trng hp ny, ta cn chuyn Makemove thnh mt hm boolean, tr li gi tr
true nu nc i th ny li n c Tng i phng. Nu n c, hin nhin im s rt cao
(c 1000 im) v khng cn phi tnh im cho nhng nhnh con na. Phn chng trnh i
th c dng nh sau:


PHP:
while tt c cc nc i c th c t mt th c do begin
if Makemove(mt_nc_i) then { i th mt nc. Hm tr v gi tr true
nu n c Tng i phng }
best := 1000 - ply { im ca nc c nu n c Tng i phng}
else best := Tnh im ca nc i th;
UnMakemove; { phc hi nc i ny}
Lu nc i c im cao nht
end;
Trong cc cu lnh trn c mt ch hi kh hiu: ti sao ta li cho nc n Tng l 1000 - ply
m khng phi ng 1000? Bin ply l bin ch su tm kim. Nu khng c bin ny v trong
trng hp Tng (bn my tnh) sp b bt d i bt c nc no th mi nhnh cy u tr v
im -1000. Do my s chn nhnh u tin i. Nc i ny c th khng hay do chp
nhn thua qu sm nh minh ho trn hnh 2.10. My nn chn nc thua lu nht hi vng
i phng i "nhm" (cn nc cn tt) v ng tinh thn chin u hn.

5. Tm kim AlphaBeta

Ta thy chng trnh mu ca th tc AlphaBeta trong chng 1. Hm AlphaBeta ca
VSCCP v c bn l ging nh vy, ch b i cc tham s pos (th c hin ti - y l gi tr
ca hai mng piece v color) mt s hm do bin i trc tip vo cc mng ton cc piece
v color (nh cc hm Makemove v UnMakemove m ta cp n trn) nn chng chnh
l th c ang xt.
PHP:
function AlphaBeta(alpha, beta: integer; depth: byte): integer;
var i, best, value: integer;
begin
if depth = 0 then AlphaBeta := Eval
else begin
Gen; best := -INFINITY;
i := gen_begin[ply]; { Khi u lp tt c cc nc }
while (i < gen_end[ply]) and (best < beta) do begin
if best > alpha then alpha := best;

if MakeMove(gen_dat[i].m) then value := 1000-ply
else value := -AlphaBeta(-beta, -alpha, depth-1);
UnMakemove;

if value > best then begin
best := value;
if ply = 0 then newmove := gen_dat[i].m;
end;
inc (i);
end; { while }
AlphaBeta := best;
end;
end;
Nc i tt nht (im cao nht) su 0 (ply = 0) c lu vo mt bin ton cc newmove.
My s chn i theo nc ny.

Th tc gi hm AlphaBeta ch c cc lnh n gin nh di. N gi hm ny vi cc gi tr
khi u thch hp bt u tm kim.
PHP:
(***** THINK - MY TNH TNH NC I *****)
procedure ComputerThink; { Tm nc i tt nht cho my }
begin
AlphaBeta (-INFINITY, INFINITY, MAX_PLY);
end;
6. X l iu khin ca ngi chi

Ngi chi dng bn phm iu khin cc qun bn mnh khi n lt: dng cc phm mi
tn iu khin con tr mn hnh chy n qun c thch hp, bm phm Space hoc Enter ch
mnh s i qun ny, chuyn con tr n ch mi v vn bm phm Space hoc Enter ch l
ch n. Ngi chi c th ngng chi gia chng bng cch bm phm ESC. Hm x l iu
khin ca ngi chi GetHumanMove phi lm nhim v x l cc phm iu khin v tr v
nc i c chn trong bin ton cc newmove. Hm cng x l hai bin ton cc x, y l to
ca con tr mn hnh.

Mt chng trnh chi c tt cn phi gip ngi chi khng i sai lut. Cc nc i khng
hp l (d c hay v tnh) u cn c pht hin v ngn cm. Cch lm th c nhiu, y
chng ti gii thiu phng php n gin nht s dng hm sn c: hm Gen. u tin, ta gi
n sinh ra tt c nhng nc i c th c t th c hin ti vi bn i l ngi - chnh l
cc nc i hp l. Mi khi ngi chi chn mt nc, my s kim tra xem n c trong danh
sch cc nc i hp l khng. Nu c, my s chp nhn nc i v thot khi hm
GetHumanMove. Nu khng n s i ngi chi phi chn li.
PHP:
function GetHumanMove: boolean;
const x: byte = 5; y: byte = 5;
var ch: char; selecting, from, t, i: integer;
begin
Gen; { Dng kim tra nc i hp l ca ngi chi }
GetHumanMove := false; selecting := 0;

while true do begin
MoveTo(x, y);
ch := ReadKey;
case ch of
#13, ' ': begin { nh du/chn mt nc i }
t := x + (y-1)*SIZE_X;
if selecting=0 then begin { Ngi chi nh du }
if color[t]=side then begin
selecting:=1; from := t; DrawCell(t,SELECT);
end;
end
else begin { Ngi chi ch ra nc i n }
if t <> from then DrawCell(from, NORMAL);
if color[t]=side then begin
from := t; DrawCell(t, SELECT);
end
else begin
newmove.from := from; newmove.dest := t;

{ Kim tra xem nc i va chn c trong danh sch cc nc i h
p l khng. Nu c s thot khi hm ny n lt my }
for i := gen_begin[ply] to gen_end[ply]-1 do
if (gen_dat[i].m.from = from) and
(gen_dat[i].m.dest = t)then
exit;
{ Nu nc khng hp l, hin li qun xut pht, ngi
chi chn nc i khc }
DrawCell(from, SELECT);
end;
end;
end;
#27: { X l cc phm khc y }
...
7. Cp nht mt nc i
Sau khi "suy ngh" xong, n lc my hoc ngi phi thc hin mt nc i thc s.
Chng trnh phi cp nht tt c cc thng tin cn thit lin quan n nc i v hin hnh
nhng thay i. Vic ny c thc hin nh gi hm UpdateNewMove. N c kh nhiu ch
ging nh hm Makemove nhng n gin hn. Tham s quan trng nht m n quan tm l
nc i c ngi hoc my chn i (t trong bin ton cc newmove). Hm cng ng thi
s kim tra tnh trng thng c ca bn va i (n c Tng i phng) v tr v gi tr true
nu c mt bn thng. Vng lp chnh s cn c vo gi tr chn l ny ngng chi.

8. Vng lp chnh x l tr chi
Sau khi c cc hm v th tc cn thit, n lc ta lin kt chng li thnh mt tr chi hp
dn. Trong phn thn chng trnh chnh, ta s bt gp vng lp repeat. Vng lp ny s lp mi
cho n khi ngi chi bm phm ESC hoc mt bn thng c. Tu theo bn ti lt n s gi
hm x l thch hp cho ngi hoc my. Sau khi nhn kt qu n lo cp nht cc s liu cn
thit, chuyn i phng thnh ngi n lt chi.
PHP:
repeat
if side=computerside then ComputerThink
else if GetHumanMove then break;{ Thot nu ESC c bm}
side := xside; xside := 3 - xside; { i bn ti lt chi }
until UpdateNewMove;
9. Hin thng tin
n y, chng trnh sn sng sc vi bn ri y. Nhng c th bn mun bit thm
mt vi s liu nh: thi gian mi ln my ngh, h s phn nhnh ca cy tr chi, s th c n
phi tnh gi tr, kh nng xt th c trung bnh ca my l bao nhiu cng nh nhiu s liu
khc. Vic quan st cc s liu ny cn gip ta bit cc ci tin, sa i v sau c thc s hot
ng tt khng.

Cch ly s liu rt n gin, ta khai bo thm mt s bin ton cc, thm mt s lnh v cui
cng in chng ra mn hnh ch thch hp. Mt s thng tin rt kh ly chnh xc, ta s tm
bng lng vi nhng s liu gn ng vy.

bit mi ln ngh, my lng gi bao nhiu th c - mt thng tin v cng quan trng, ta
khai bo mt bin ton cc evalcount v mi khi hm Eval c gi ta li tng gi tr ca n
thm mt.

Ta cng cn bit my ngh trong bao lu bng cch khai bo cc bin tnh thi gian. Thi
gian c o cn c vo s xung ng h v tr tuyt i $40:$6c trong b nh. T y ta tnh
c thi gian tnh bng giy nh chia cho 18.23 - s xung trong mi giy. Khi bit c thi
gian tiu tn c th c tnh tc lng gi ca my bng cch chia tng s nt lng gi
cho thi gian tiu tn. Tt nhin thi gian tiu tn ny ngoi thi gian tiu cho hm lng gi
cn phi chi cho nhiu th khc nh chy cc lnh ca hm Gen, hm AlphaBeta... nn cch lm
ny ch cho bit con s c lng m thi.

c c h s phn nhnh chnh xc ta phi thng k qua mt s d liu ln. Ch rng, s
nhnh con c sinh ra mi ln gi hm Gen c o bng hiu gen_end[ply]-gen_begin[ply].
Do h s phn nhnh c o bng cch ly tng cc nhnh con ny ri chia cho s ln gi
hm Gen (o bng bin gencount). Cng chi lu, cc d liu o c cng ln, kt qu s cng
chnh xc.

Ngoi ra, bn c th cn mun hin ch gii nc va i ca my d theo di v xem xt
im t c. Hy ch cch tnh cc con s ny (ch s 65 l m ca ch ci A, 9 l s ct
ca mt dng bn c).
Sau y l nhng ch cn b xung bn c c cc thng tin cn thit. Nhng ch thm, sa
t nay v sau u c nh du bng mt mi tn trng cho d tm.
PHP:
const
...
{ Cc bin dng o h s phn nhnh }
brandtotal: longint = 0; gencount: longint = 0;
...
Var
evalcount: longint;
systicks: longint absolute $40:$6C; { Bin o thi gian }
...
procedure Gen;
...
brandtotal := brandtotal + gen_end[ply] - gen_begin[ply];
inc(gencount);
end;

function Eval: integer;
var i, s: integer;
begin
inc(evalcount);
...

procedure ComputerThink; { Tm nc i v hin thng tin }
var best: integer; tickstart, tickend: longint;
begin
evalcount := 0; tickstart := systicks;

best := AlphaBeta(-INFINITY, INFINITY, MAX_PLY);

{ Phc v hin cc thng tin theo di }
tickend := systicks; textcolor(7);
gotoxy(50, 4); write('Do sau : ', MAX_PLY);
gotoxy(50, 5); write('So nut luong gia: ', evalcount, ' ');
gotoxy(50, 6); write('He so phan nhanh: ',
brandtotal/gencount:3:2, ' ');
gotoxy(50, 7); write('Thoi gian (giay): ',
(tickend-tickstart)/18.23:0:2, ' ');
gotoxy(50, 8); write('Toc do xet nut : ',
evalcount*18.23/(tickend-tickstart+1):0:0, ' ');
gotoxy(50, 9); write('Diem dat duoc : ', best, ' ');
gotoxy(50,11); write('May tinh di : ',
chr(((newmove.from-1) mod SIZE_X)+65),
SIZE_X -(newmove.from-1) div SIZE_X,
chr(((newmove.dest-1) mod SIZE_X)+65),
SIZE_X-(newmove.dest-1)div SIZE_X,' ');
end;
10. Chy th

By gi bn hy dch v chy th chng trnh trn (ton b ngun trong Ph lc A). Cn thn
nh, ta cha ci chc nng cho php hon i. Nu i nhm bn khng th i li. Chng trnh
my tnh li khng "nhm ln" v vi su ngm nh 4 (tc l ngh trc ti 4 nc i) n c
kh nng nh bi nhng ngi chi c trnh trung bnh v chi u. Bn hy chu kh suy
ngh k mt cht, cn thn mt cht th c th thng c.

Hnh 2.11 l thng tin in ra mn hnh sau khi my i nc u tin. Chng trnh c chy trn
my tnh Pentium 166MHZ ci h iu hnh Windows 98 v tm kim n su bng 4. Cc s
liu cho ta bit cy tr chi c h s phn nhnh khong 41. Nu ly trn l 40 th ta c bd = 404
= 2560000 (tc l s nt l ca cy tr chi c khong trn hai triu ri nt). chnh l s nt
ta phi xt nu dng phng php tm kim Minimax. Vi tc trung bnh xt c 55985 nt
mi giy th thi gian xt ht bng phng php ny s mt khong 2560000/55985 46 giy.
y, ta ang dng phng php tm kim AlphaBeta, s nt phi xt ch cn 150480, ngha l
t hn 17 ln v tng thi gian phi b ra ch 2.63 giy thay cho 46 giy. Nc i M vo gc
khng c hay lm - nhng khng sao, y mi ch l phin bn u tin v su tm kim
cn hn ch.



Nu bn cha h thc hin mt ci tin no m ch nhp nguyn vn chng trnh mu t Ph
lc A v dch chy th cc gi tr v su, s nt lng gi, h s phn nhnh, im t c,
my tnh i (tr nhng thng s lin quan n thi gian do tu thuc loi my bn c) phi y ht
nh hnh 2.11. Nu c iu g khc c ngha l c sai st trong khi nhp chng trnh ngun,
bn cn thn trng kim tra chng trnh.

Tu theo sc mnh my tnh (v c kh nng ch i), bn hy th tng su tm kim bng
cch sa khai bo hng s MAX_PLY t 4 ln 5 hoc 6. ng ham tng nhiu. Do bng n t
hp, nu tng nhiu bn s khng ch ni u. Cng tng su, bn s thy chng trnh chi
cng bt h hnh v cng kh thng y.

Bn hy th kim nghim vi su 5 xem sao. Cc con s u tng khng khip. Trn my
tnh ca ti, thi gian xt nc u tin tng t 2.63 ti 88 giy (tng 33 ln). S nt phi
lng gi l 5574794 nt (tng 37 ln).

Nu my tnh ca bn l loi tt, hy th tip vi su 6. Trn my tnh ca ti, thi gian my
"ngh" nc u tin mt ti 1031 giy (hn 17 pht, gn gp 12 ln). Cn s nt phi lng
gi l 62929742 (gp 11 ln). Bn c th thy cc con s cng tng rt nhiu nhng d sao ch
tng c 11 ln. H s phn nhnh c thng k qua s lng nhiu hn tt xung cn 40.15.
Nc c chn i hi khc l B7C7 (c l l nc tt hn). Cn su 7 ti ch dm th mt
ln v thi gian tiu tn cho ln ngh nc u tin mt n... 3.7 gi (trong khi qui nh tng
cng tt c cc nc ca mt u th ch c trong 1 gi khi thi u).

Nu ta cho rng tng mt su thi gian tnh ton ch di thm trung bnh 10 ln th ch cn n
su 11, cc my tnh c Pentium 166 MHZ s mt n... 4 nm ngh nc i u tin (cn
n su 14 th mt... 4223 nm).

Ta hy th c m nu c c chic my tnh mnh v chuyn dng (cho c) nh Deep Blue
th tnh c n u. Loi my ln u tin thng c Kasparov (nm 1997) c kh nng xt
c trung bnh 200 triu (i khi ln n 400 triu) nc i mi giy. Vi su 7 (m my
tnh ca ti phi ch trong 3.7 ting ng h) s c my chiu c trong khong... 3 giy. Nu
c ngh mt nc trong 3 pht (thi gian c php trung bnh cho mt nc) th su c
th n c s khong t 8 n 10 (nu khng c ci tin c bit).

n y ta cng c th thy, cc chng trnh c thuc loi tt nht chy trn cc my tnh thng
thng (loi PC v khng gn cc mch chuyn dng) cng ch tm kim c y n su
t 5 n 8 m thi (vi gii hn thi gian thi u bnh thng). D vy cc c gng ci tin b ra
cng phi rt nhiu v rt lu mi t c n cc su nh vy (bn s c nghin cu mt
vi ci tin nhm nng su trong thi gian chi hp l).

Ch l thng bo v tc xt nc c th rt khc nhau khi thay i su cc i do hm
lng gi dng y qu n gin, t trng thi gian khng ln so vi cc hm khc v thi
gian o li bao gm tt c mi th nn cc con s b nh hng nhiu. Tuy nhin, nu vi cng
su th tc hin tng i n nh.

Ton b m ngun chng trnh c Tng VSCCP phin bn 1.0 cho trong phn Ph lc A.

Tng kt chng 2

Chng ny i su vo cch vit mt chng trnh c Tng n gin. Nhng im quan trng
trong chng l cc khai bo cc loi d liu khc nhau, cch biu din mt bn c, cc th tc
v hm c bn. Ch l cc cu trc d liu v cc khai bo trong chng trnh mu rt n
gin nhng cng rt hiu qu. Th tc Gen l lng nhng, phc tp v d sai nht.

Thut ton AlphaBeta tuy ging nh cp n trong chng 1 nhng n chng ny bn
cn phi hiu n tht s. Bn cng cn nm vng cch ly s liu cng nh hiu cc s liu ny
tip tc theo di cc ci tin chng trnh trong cc chng sau.

GI PHT TRIN

1. Thay cho mng mt chiu biu din bn c, bn hy th dng mng hai
chiu (dng piece*1..10, 1..9+ of byte). T mnh khm ph cc u, nhc im
ca cch lm ny.
2. Mt byte l qu lu thng tin v qun c v bn chi. Ni cch khc,
mng color khng tht cn thit. Bn hy sa li chng trnh sao cho vn
gia nguyn khai bo ca mng piece, nhng li b c mng color.
3. Ti sao bn li phi chuyn sang bn c m rng kch thc 1314 (v ri
li phi chuyn v bn c thng 910) lm mi nhim v kim tra vic
vt qu bin cho nc c ang c sinh? Bn c th dng trc tip bn c
m rng ny chi c khng (dng trc tip bn c 13x14)?
4. Bn hy t sa chng trnh cho php c hai bn u l my (hoc u l
ngi) chi. Ngha l cho my c th t u.
5. Th my u c hai bn vi su ging v khc nhau (v d nh 3-3, 3-4,
4-4, 3-5 hoc 4-5) v thay i lt i trc ca cc bn. Bn no thng?
6. Bn hy t ci tin hm lng gi theo mnh. V d hy th cho im cc
qun c tu .
7. Hy thi u nhiu vi my. Chc chn trong qu trnh chi my s i nhiu
nc kh l lng (trn quan im ca ngi chi bnh thng). Hy ghi li
nhng nc i v hy th l gii v sao my li i nh vy. Kho st k v
hy th ci tin hm lng gi nu my phm sai lm nhiu.
8. Bn hy ci thm mt chc nng na cho ngi chi: chc nng "hon",
ngha l b nc va i (hoc mt lot nc va i) v cho ngi chi i li
nc khc. Ch : hy tn dng ti a nhng th tc c sn nh
UnMakemove.
9. Bn hy ci chc nng "gi " (hay "mch nc") cho ngi chi bit nn i
nc no bng cch ch ra cc nc i chng c tt nht. Bn nn tn dng
nhng kt qu c sn trong ln my ngh trc m khng cn phi tnh li.
10. Hy cho php ngi chi ghi li vn c ang chi d v lc khc c th np
vo chi tip.
11. Cho php ngi chi c by c th. By xong mi thi u.
12. Hy t ci tin giao din: dng ho, ci thm chut, thm menu, phm g
tt... Hy tham kho cc chng trnh c c trn th trng lm cho tt.
13. Bnh lun: Theo di mt trn u bt k, mi khi mt u th i mt nc th
c gng gii thch l do chn nc . V d gii thch nc i dn ti th
c hay (nh im cao), s n c qun no ca i phng hoc trnh
c mt qun, hoc dn ti thng hoc trnh thua sau bao nhiu nc...
14. Ghi nc i: Ta lm quen vi cch ghi nc i n gin trn. V d nh
A1A6 ngha l qun c v tr A1 s chuyn n v tr A6. Cch ny x l tht
n gin. Tuy vy, y khng phi l cch ghi nc i thng dng trong
"lng c". Nu bn a bn ghi mt vn c nh th cho mt ngi chi c
bnh thng th h khng hiu. Ta cn ghi mt vn c theo cc qui nh ghi
chp bin bn vn u (do Lin on c Vit nam a ra). Cc qui nh ny
nh sau:

Bn c c tnh theo ct (hnh 2.12). Bn no tnh theo ct bn .


K hiu qun c: Tg - Tng; S - S; T - Tng; X - Xe; P - Pho; M - M; B -
Tt (Binh).
phn bit cc qun cng loi ng trc, sau hay gia th dng cc ch
vit tt: t - trc, s - sau, g - gia.
K hiu i qun:
+Tn (tin): (.) du chm. Ch l nc tn ca Xe, Pho, Tt c ghi hi khc vi M, Tng.
V d: X2.6 c ngha Xe ct 2 tin 6 . Cn M 2.3 c ngha l qun M ang ct 2 tin sang
ct 3).
+Thoi (lui): (/) gch cho. Ngc vi tn. V d M7/8 ngha l M ct 7 thoi lui sang ct 8.
+Bnh (sang ngang): (-) du ngang (P2-5 ngha l Pho 2 sang ngang n ct 5).

V d: Cc nc i dn n th c nh hnh 2.12 (th ny c tn di dng l: Pho u Xe tun
h i bnh phong M c in) c ghi nh sau:
1. P2-5 M8.7
2. M2.3 C3.1
3. X1-2 X9-8
4. X2.4 M2.3


Tc gi: Phm Hng Nguyn