Đề thi Toán - Tin học trong nhà trường (Bài 41+42)
Chia sẻ bởi Thân Thị Thanh |
Ngày 18/10/2018 |
70
Chia sẻ tài liệu: Đề thi Toán - Tin học trong nhà trường (Bài 41+42) thuộc Sinh học 6
Nội dung tài liệu:
Bài 41/2000 - Cờ Othello
Program bai41; {Co Othello}
Uses Crt ;
Const Inp = `othello.Inp` ;
Out = `othello.out` ;
nmax = 50;
huongi:array[1..8] of integer = (-1,-1,-1,0,0,1,1,1);
huongj:array[1..8] of integer = (-1,0,1,-1,1,-1,0,1);
Type
Mang1 = Array [1..nmax] of string[3] ;
Mang2 = Array [1..8,1..8] of char ;
Var f: text;
a: mang2; l:mang1;
c: char; n, k, code:integer;
di:array[1..8,1..8] of boolean;
x0,y0:array[1..nmax] of integer;
{=================================================}
Procedure nhap;
Var i,j : Byte ;
Begin
Assign(f,inp) ;
Reset(f) ;
for i:=1 to 8 do
begin
for j:=1 to 8 do Read(f,a[i,j]) ;
Readln(f) ;
end;
Readln(f,c) ;
i:=0;
while not eof(f) do
begin
inc(i);
Readln(f,l[i]);
end;
n:=i;
End ;
{===============================================}
Procedure kiemtra(i,j:integer);
Var m:integer;
Begin
Case c of
`B`: If a[i,j] = `B` then
Begin
m:= 1;
repeat
if (a[i+huongi[m],j+huongj[m]] = `W`)
and(i+huongi[m]>0)and(j+huongj[m]>0)
and(i+2*huongi[m]>0)and(j+2*huongj[m]>0)
and(i+huongi[m]<9)and(j+huongj[m]<9)
and(i+2*huongi[m]<9)and(j+2*huongj[m]<9)
and(A [i+2*huongi[m],j+2*huongj[m]] = `-`)
then
di [i+2*huongi[m],j+2*huongj[m]] := True;
m:=m+1;
until m>8;
End;
`W`: If (a[i,j] = `W`) then
Begin
m:= 1;
repeat
if (a [i+huongi[m],j+huongj[m]] = `B`)
and(i+huongi[m]>0)and(j+huongj[m]>0)
and(i+2*huongi[m]>0)and(j+2*huongj[m]>0)
and(i+huongi[m]<9)and(j+huongj[m]<9)
and(i+2*huongi[m]<9)and(j+2*huongj[m]<9)
and(a[i+2*huongi[m],j+2*huongj[m]] = `-`)
then
di[i+2*huongi[m],j+2*huongj[m]] := True;
m:=m+1;
until m>8;
end;
End;{of Case}
End;
{================================================}
Procedure lietke;
Var
i,j,m: Integer;
t: Boolean;
Begin
t:= false;
for i:=1 to 8 do
for j:= 1 to 8 do
di[i,j]:=false;
for i:=1 to 8 do
for j:= 1 to 8 do kiemtra(i,j);
for i:= 1 to 8 do
for j:= 1 to 8 do
If di[i,j] then
Begin
t:= True;
Write (f,`(`,i,`,`,j,`)`);
End;
If t=false then Write (f, `No legal move.`);
Writeln(f);
End;
{======================================}
Procedure latco(x0,y0:integer);
Var m:integer;
Begin
Case c of
`B`: if a[x0,y0]
Program bai41; {Co Othello}
Uses Crt ;
Const Inp = `othello.Inp` ;
Out = `othello.out` ;
nmax = 50;
huongi:array[1..8] of integer = (-1,-1,-1,0,0,1,1,1);
huongj:array[1..8] of integer = (-1,0,1,-1,1,-1,0,1);
Type
Mang1 = Array [1..nmax] of string[3] ;
Mang2 = Array [1..8,1..8] of char ;
Var f: text;
a: mang2; l:mang1;
c: char; n, k, code:integer;
di:array[1..8,1..8] of boolean;
x0,y0:array[1..nmax] of integer;
{=================================================}
Procedure nhap;
Var i,j : Byte ;
Begin
Assign(f,inp) ;
Reset(f) ;
for i:=1 to 8 do
begin
for j:=1 to 8 do Read(f,a[i,j]) ;
Readln(f) ;
end;
Readln(f,c) ;
i:=0;
while not eof(f) do
begin
inc(i);
Readln(f,l[i]);
end;
n:=i;
End ;
{===============================================}
Procedure kiemtra(i,j:integer);
Var m:integer;
Begin
Case c of
`B`: If a[i,j] = `B` then
Begin
m:= 1;
repeat
if (a[i+huongi[m],j+huongj[m]] = `W`)
and(i+huongi[m]>0)and(j+huongj[m]>0)
and(i+2*huongi[m]>0)and(j+2*huongj[m]>0)
and(i+huongi[m]<9)and(j+huongj[m]<9)
and(i+2*huongi[m]<9)and(j+2*huongj[m]<9)
and(A [i+2*huongi[m],j+2*huongj[m]] = `-`)
then
di [i+2*huongi[m],j+2*huongj[m]] := True;
m:=m+1;
until m>8;
End;
`W`: If (a[i,j] = `W`) then
Begin
m:= 1;
repeat
if (a [i+huongi[m],j+huongj[m]] = `B`)
and(i+huongi[m]>0)and(j+huongj[m]>0)
and(i+2*huongi[m]>0)and(j+2*huongj[m]>0)
and(i+huongi[m]<9)and(j+huongj[m]<9)
and(i+2*huongi[m]<9)and(j+2*huongj[m]<9)
and(a[i+2*huongi[m],j+2*huongj[m]] = `-`)
then
di[i+2*huongi[m],j+2*huongj[m]] := True;
m:=m+1;
until m>8;
end;
End;{of Case}
End;
{================================================}
Procedure lietke;
Var
i,j,m: Integer;
t: Boolean;
Begin
t:= false;
for i:=1 to 8 do
for j:= 1 to 8 do
di[i,j]:=false;
for i:=1 to 8 do
for j:= 1 to 8 do kiemtra(i,j);
for i:= 1 to 8 do
for j:= 1 to 8 do
If di[i,j] then
Begin
t:= True;
Write (f,`(`,i,`,`,j,`)`);
End;
If t=false then Write (f, `No legal move.`);
Writeln(f);
End;
{======================================}
Procedure latco(x0,y0:integer);
Var m:integer;
Begin
Case c of
`B`: if a[x0,y0]
* Một số tài liệu cũ có thể bị lỗi font khi hiển thị do dùng bộ mã không phải Unikey ...
Người chia sẻ: Thân Thị Thanh
Dung lượng: |
Lượt tài: 0
Loại file:
Nguồn : Chưa rõ
(Tài liệu chưa được thẩm định)