سلام
اینم حسن ختام پروژه های پاسکال.
موفق باشید.
program magic_matrix ;
uses crt;
const con3t = 20 ;
var i,tul:integer;
odd:boolean;
a:array[1..con3t , 1..con3t] of integer;
{--------- www.ukcs86.zet.ir -----------}
procedure clear_matrix;
var i,j :integer;
begin
for i:=1to con3t do
for j:=1 to con3t do
a[i,j]:=0;
end; { of procedure clear_matrix }
{--------- www.ukcs86.zet.ir -----------}
procedure show_magix_matrix (tul:integer);
var p,w:integer;
begin
for p:=1 to tul do
begin
for w := 1 to tul do
write(a[p,w]:5);
writeln;
end;
end; { of procedure show_magix_matrix }
{--------- www.ukcs86.zet.ir -----------}
procedure do_magic(tul:integer) ;
var x,y:integer;
begin{of procedure do_magic}
x:=1; y:=(tul div 2 )+1; a[x,y]:=1;
for i:=2 to (tul*tul) do
begin
x:=x-1; y:=y-1;
if x=0 then x:=tul;
if y=0 then y:=tul;
if a[x,y]=0 then a[x,y]:=i
else
begin
x:=x+2; y:=y+1;
if x>tul then x:=x-tul;
if y>tul then y:=y-tul;
a[x,y]:=i;
end;{else}
end;{of for1}
end;{of procedure do_magic}
{--------- www.ukcs86.zet.ir -----------}
begin
clear_matrix;
clrscr;
write('pleaze enter an odd number : ');
readln(tul);
if (tul mod 2) =0 then
begin
odd := false;
writeln('sorry you sould enter a odd number');
end
else
odd:=true;
if odd then
do_magic(tul);
show_magix_matrix(tul);
readln;
end.{-------- source by sajjadG -----------}
------------------------------------------------------------------------------------------------
program eight_gueens;
{uses crt;}
const max=8; {this is number max queen } { max = 8 ---> 8 vazir }
type sahovincia = array [1..max,1..max] of boolean ;
var i,j:integer ;
sah : sahovincia;
t:boolean;
{------------------------- function queen - ok ----------------------}
function queen_ok(i,j:integer):boolean;
var
x :integer;
t :boolean;
begin
t:=false;
for x:=1 to max do
t:= t or sah[i,x] or sah[x,j]; {ha}
{in shart khali budane khanehaye ofoghi va amudi
ra chek mikonad }
for x:=1 to max do
begin {this 2 line is for cheks row(satr) and column(soton) and ...(orib ya kaj) }
if (i+j-x>=1) and(i+j-x<=max) then
t:= ( t or sah[x,i+j-x] );{agar sah dorost nabud t false meghdare t ke false ast ra migirad}
if (x-(i-j)>=1) and (x-(i-j)<=max)then
t:= ( t or sah [x,x-(i-j)] );
end;
queen_ok:=not t ;
end;
{---------- my check function -----------}
function check(i,k:integer):boolean;
var x:integer;
begin
x:=0;
check:=true;
if not ((k=1) and (i=k) )then
begin
if (k>1) then
for x:=k downto 2 do
begin
if sah[i-1,k-1] then
check:=false;
if sah[i+1,k-1] then
check:=false;
end;
if k<max then
for x:=k to max do
begin
if sah[i-1,k+1] then
check:=false;
if sah[i+1,k+1] then
check:=false;
end;
for x:=1 to max do
begin
if sah[x,k] then
check:=false;
if sah[i,x] then
check:=false;
end;
if k=i then
check:=false;
end;
end;{of procedure}
{----------------------- function place queen ---------------------- }
function place_queen(i:integer):boolean;
var
k :integer ;
t :boolean ;
begin
if i > max then
place_queen :=true
else
begin
k:=1 ;{baraye while}
t:=false ;
{---------raveshe khodesh-----------}
while (k<=max) and not t do
begin
if queen_ok(i,k) then
begin
sah[i,k]:= true ;
t:= place_queen(i+1); {back tracking}
if not t then
sah[i,k]:=false ;
end; {of if}
k:=k+1;
end;{of while}
(* for k:=1 to max do
begin
if queen_ok(i,k) then
begin
sah[i,k]:= true ;
t:= place_queen(i+1); {back tracking}
if not t then
sah[i,k]:=false ;
end; {of if}
end;
*)
place_queen:=t; {meghdar dahi be tabe}
end;{of else begin}
end;
{-------clear matrix-------------}
procedure clear_matrix;
var i:integer;
begin
for i:= 1 to max do
for j:=1 to max do
sah[i,j]:=false; { input false in all cell array }
end;{of proc clear_matrix}
{----------show queen place-------------}
procedure show_queens ;
var i: integer;
begin
for i:=1 to max do
begin
for j:=1 to max do
if sah[i,j] then
writeln ('[ ',i,',',j,' ]');
write;
end;
end;{of proc show_queen}
{----------write_matrix--------------}
procedure write_matrix ;
var i:integer;
begin
for i:=1 to max do
begin
for j:=1 to max do
if sah[i,j]= false then
write ('0':4)
else
write ('':4);
writeln;
end;
end;{of proc write_matrix}
{------------------- main program --------------------}
begin
(* textcolor(4); { for color font }
textbackground(1); { for color back ground } *)
{clrscr ; { for clear screen in run program }
clear_matrix;
t:=place_queen(1);
writeln ;
show_queens;
write_matrix;
readln;
end.
-----------------------------------------------------------------------------------------
program snake_game_with_comments_by_sajjadG; (* email address: sajjadgerami2003@yahoo.com *)
{www.ukcs86.zet.ir}
uses crt,graph;
const passo=19;
var coor:array[1..800,1..2]of integer; { for snake length}
n:array[1..13]of char; { for logo procedure}
cont,driver,mode,i,j,x,y,xc,yc,totale,ultx,ulty,point,primato,vel : integer;
direzione,key : char ;
oldscore,score,s : string;
c_error,barkhord_ba_khod,mangia : boolean;
procedure kadr;
begin
rectangle(8,8,(passo*30)-8,(passo*24)-8);
outtextxy(580,80,'Score:')
end;
{------------------------------}
procedure segment(x,y:integer);
var dd:integer;
begin
randomize;
dd:=random(15);
setcolor(dd);{range dore snake}
rectangle(x-9,y-9,x+9,y+9); {9 size morabahaye snake ast}
setfillstyle(12,white);
bar(x-8,y-8,x+8,y+8);
setcolor(white);
end;
{------------------------------}
procedure clear_s(x,y:integer);
begin
setfillstyle(1,black);
bar(x-9,y-9,x+9,y+9);
setfillstyle(1,white)
end;
{------------------------------}
procedure gerdi(x,y:integer);
begin
x:=x*passo;
y:=y*passo;
circle(x,y,8);
setfillstyle(1,blue);{taghire rage snake hengame barkhord}
end;
{------------------------------}
procedure end_sound;
var i:integer;
begin
for i:=1 to 30000 do
sound(100);
nosound;
end;
{------------------------------}
procedure score_sound;
var i:integer;
begin
for i:=1 to 5000 do
sound(1100);
nosound;
end;
{------------------------------}
function punti(x:integer):string;
var
s:string[10];
begin
str(x,s);{ in tabe integer(x) ra be string(s) tabdil mikonad}
punti:=s;
end;
{---------------base procedure-----------------}
procedure base_procedure;
begin
kadr;
point:=0;
oldscore:=punti(point);
score:=oldscore;
x:=passo*15;
y:=passo*23;
direzione:='6';
key:='6';
totale:=8;
barkhord_ba_khod:=false;
mangia:=false;
coor[1,1]:=x;
coor[1,2]:=y;
c_error:=false;
for i:=2 to totale do
begin
coor[i,1]:=coor[i-1,1]-passo;
coor[i,2]:=y
end;
xc:=15; yc:=12; {x va y e dayere-circle}
gerdi(xc,yc); {dayereye hadaf} {tavajoh konid ke gerdi ghable halghast}
repeat
setcolor(black); { baraye chape score }
outtextxy(580,100,oldscore);
setcolor(white);
outtextxy(580,100,score);
for i:=1 to totale do
segment(coor[i,1],coor[i,2]);
delay(170);
clear_s(coor[totale,1],coor[totale,2]);
{clear_s baraye pak kardane rade snake}
delay(70);
if (x=xc*passo) and (y=yc*passo) then { sharte barkhorde snake}
mangia:=true; {ba dayereye hadaf }
if mangia then
begin
point:=point+9; { adding score}
score:=punti(point); {negahdarie score jadid}
oldscore:=punti(point-9);{negahdarie score ghadimi}
totale:=totale+1; {add shodan segmenthaye mar}
coor[totale,1]:=ultx;
coor[totale,2]:=ulty;
score_sound;
repeat
c_error:=false;
xc:=random(29)+1;{ mokhtasate x gerdie jadid}
yc:=random(23)+1; { mokhtasate y gerdie jadid}
for i:=1 to totale do
if (coor[i,1]=xc*passo)and(coor[i,2]=yc*passo)then
{ in shart chek mikonad ke aya gerdi roye mar ast ya na}
c_error:=true;
until not c_error;
gerdi(xc,yc);
mangia:=false; {mangia sharte barkhord ast}
end;
if keypressed then key:=readkey;
case key of
'8':if direzione<>'2' then direzione:='8';
'2':if direzione<>'8' then direzione:='2';
'6':if direzione<>'4' then direzione:='6';
'4':if direzione<>'6' then direzione:='4'
end;
case direzione of
'8': y:=y-passo;
'2': y:=y+passo;
'6': x:=x+passo;
'4': x:=x-passo
end;
ultx:=coor[totale,1];
ulty:=coor[totale,2];
for i:=totale downto 2 do
begin {enteghale segmenthaye ghabli be jolo i}
coor[i,1]:=coor[i-1,1];
coor[i,2]:=coor[i-1,2];
end;
coor[1,1]:=x; {mokhtasate sare snake}
coor[1,2]:=y;
for i:=2 to totale do { sharte barkhord ba khodesh}
if (coor[i,1]=x) and (coor[i,2]=y) then
barkhord_ba_khod:=true
until (x-passo<0)or(y-passo<0)or(x+passo=passo*31)or(y+passo=passo*25)or barkhord_ba_khod;
end_sound;
end;
{-----------main program--------------}
begin (*main program.*)
initgraph (driver,mode,'c:\progra~1\tp\bgi');
setbkcolor(9);
repeat
cleardevice;{manade clear screen dar unit crt mibashad}
base_procedure;
cleardevice;
outtextxy(280,240,'Score : ');
outtextxy(350,240,punti(point));
readln;
outtextxy(265,270,'New game?(Y/N)');
key:=readkey
until (key='n') or (key='N');
closegraph;
end.{www.ukcs86.zet.ir}
----------------------------------------------------------------------------------------------
program snake_game_with_comments_by_sajjadG; (* email address: sajjadgerami2003@yahoo.com *)
{www.ukcs86.zet.ir}
uses crt,graph;
const passo=19;
var coor:array[1..800,1..2]of integer; { for snake length}
n:array[1..13]of char; { for logo procedure}
cont,driver,mode,i,j,x,y,xc,yc,totale,ultx,ulty,point,primato,vel : integer;
direzione,key : char ;
oldscore,score,s : string;
c_error,barkhord_ba_khod,mangia : boolean;
procedure kadr;
begin
rectangle(8,8,(passo*30)-8,(passo*24)-8);
outtextxy(580,80,'Score:')
end;
{------------------------------}
procedure segment(x,y:integer);
var dd:integer;
begin
randomize;
dd:=random(15);
setcolor(dd);{range dore snake}
rectangle(x-9,y-9,x+9,y+9); {9 size morabahaye snake ast}
setfillstyle(12,white);
bar(x-8,y-8,x+8,y+8);
setcolor(white);
end;
{------------------------------}
procedure clear_s(x,y:integer);
begin
setfillstyle(1,black);
bar(x-9,y-9,x+9,y+9);
setfillstyle(1,white)
end;
{------------------------------}
procedure gerdi(x,y:integer);
begin
x:=x*passo;
y:=y*passo;
circle(x,y,8);
setfillstyle(1,blue);{taghire rage snake hengame barkhord}
end;
{------------------------------}
procedure end_sound;
var i:integer;
begin
for i:=1 to 30000 do
sound(100);
nosound;
end;
{------------------------------}
procedure score_sound;
var i:integer;
begin
for i:=1 to 5000 do
sound(1100);
nosound;
end;
{------------------------------}
function punti(x:integer):string;
var
s:string[10];
begin
str(x,s);{ in tabe integer(x) ra be string(s) tabdil mikonad}
punti:=s;
end;
{---------------base procedure-----------------}
procedure base_procedure;
begin
kadr;
point:=0;
oldscore:=punti(point);
score:=oldscore;
x:=passo*15;
y:=passo*23;
direzione:='6';
key:='6';
totale:=8;
barkhord_ba_khod:=false;
mangia:=false;
coor[1,1]:=x;
coor[1,2]:=y;
c_error:=false;
for i:=2 to totale do
begin
coor[i,1]:=coor[i-1,1]-passo;
coor[i,2]:=y
end;
xc:=15; yc:=12; {x va y e dayere-circle}
gerdi(xc,yc); {dayereye hadaf} {tavajoh konid ke gerdi ghable halghast}
repeat
setcolor(black); { baraye chape score }
outtextxy(580,100,oldscore);
setcolor(white);
outtextxy(580,100,score);
for i:=1 to totale do
segment(coor[i,1],coor[i,2]);
delay(170);
clear_s(coor[totale,1],coor[totale,2]);
{clear_s baraye pak kardane rade snake}
delay(70);
if (x=xc*passo) and (y=yc*passo) then { sharte barkhorde snake}
mangia:=true; {ba dayereye hadaf }
if mangia then
begin
point:=point+9; { adding score}
score:=punti(point); {negahdarie score jadid}
oldscore:=punti(point-9);{negahdarie score ghadimi}
totale:=totale+1; {add shodan segmenthaye mar}
coor[totale,1]:=ultx;
coor[totale,2]:=ulty;
score_sound;
repeat
c_error:=false;
xc:=random(29)+1;{ mokhtasate x gerdie jadid}
yc:=random(23)+1; { mokhtasate y gerdie jadid}
for i:=1 to totale do
if (coor[i,1]=xc*passo)and(coor[i,2]=yc*passo)then
{ in shart chek mikonad ke aya gerdi roye mar ast ya na}
c_error:=true;
until not c_error;
gerdi(xc,yc);
mangia:=false; {mangia sharte barkhord ast}
end;
if keypressed then key:=readkey;
case key of
'8':if direzione<>'2' then direzione:='8';
'2':if direzione<>'8' then direzione:='2';
'6':if direzione<>'4' then direzione:='6';
'4':if direzione<>'6' then direzione:='4'
end;
case direzione of
'8': y:=y-passo;
'2': y:=y+passo;
'6': x:=x+passo;
'4': x:=x-passo
end;
ultx:=coor[totale,1];
ulty:=coor[totale,2];
for i:=totale downto 2 do
begin {enteghale segmenthaye ghabli be jolo i}
coor[i,1]:=coor[i-1,1];
coor[i,2]:=coor[i-1,2];
end;
coor[1,1]:=x; {mokhtasate sare snake}
coor[1,2]:=y;
for i:=2 to totale do { sharte barkhord ba khodesh}
if (coor[i,1]=x) and (coor[i,2]=y) then
barkhord_ba_khod:=true
until (x-passo<0)or(y-passo<0)or(x+passo=passo*31)or(y+passo=passo*25)or barkhord_ba_khod;
end_sound;
end;
{-----------main program--------------}
begin (*main program.*)
initgraph (driver,mode,'c:\progra~1\tp\bgi');
setbkcolor(9);
repeat
cleardevice;{manade clear screen dar unit crt mibashad}
base_procedure;
cleardevice;
outtextxy(280,240,'Score : ');
outtextxy(350,240,punti(point));
readln;
outtextxy(265,270,'New game?(Y/N)');
key:=readkey
until (key='n') or (key='N');
closegraph;
end.{www.ukcs86.zet.ir}
------------------------------------------------------------------------------------------
program matrix ;
{uses crt;}
const max = 8 ;
type
a = array[1..max , 1..max] of boolean ;
var
t:integer;
c_array:a;
b: array[1..max] of integer;
s:string;
city1,city2:integer;
n,z:integer;
{---------show matrix------------}
procedure show_m (n:integer);
var j,i,k,c:integer;
begin
for i:=1 to n do
for j:=1 to n do
if (i<>j) and (i<j) then
writeln('[' , i , ',' ,j, ']=' , c_array[i,j]);
end;
{---------true point------------}
procedure true_p(n:integer) ;
var i,j:integer;
begin
for i:=1 to n do
for j :=1 to n do
begin
if i=j then
c_array[i,j]:=false;
end;
end;{of true_p procedure}
{-----------clear matrix----------------}
procedure clear_m ;
var i,j :integer;
begin
for i:=1 to max do
for j:=1 to max do
c_array[i,j]:=false;
end;
{---------------------------------}
procedure show_matrix(n:integer);
var i,j :integer;
begin
for i:= 1 to n do
begin
for j:= 1 to n do
write(c_array[i,j]:10);
writeln;
end;
end;
{------------way-----------------}
procedure way (n:integer);
var c,i,k,j:integer;
begin
i:=1;
repeat
k:=1;
for c:=i to n-1 do
begin
write('Is there any way between city',i,' and city',i+k,' (y/n):');
repeat
readln(s);{??? ba read kar nemikonad ???}
until (s='y') or (s='n') ;
if s='y' then
begin
c_array[i,i+k] := true;
c_array[i+k,i] := true;
end;
k:=k+1;
end;
i:=i+1
until i > n ;
end;
{------------------------------------}
function not_in(w:integer):boolean;
var i : integer;
begin
not_in:=true;
for i:= 1 to n do
if b[i]=w then
not_in:=false;
end;
{------------------------------------}
function way_ok(i,j:integer):boolean;
begin
if c_array[i,j] then
way_ok:=true
else
way_ok:=false;
end;
{------------------f------------------}
PROCEDURE f (y,t:integer);
var ii,jj:integer;
begin
if y = city2 then
begin
for ii :=1 to t do
if b[ii]<>0 then
write(b[ii],',');
writeln;
end
else
begin
for jj:=1 to n do
if not_in(jj) then
begin
if way_ok(y,jj) then
{ t:=t+1;}
b[t+1]:=jj;
f(jj,t+1);
end;
end;
b[t]:=0;
end;
{-----------------------------------}
procedure get_cities ;
var i,j:integer;
begin
clear_m;
write('how many city we have : ');
readln(n);
{ true_p(n);}
way(n);
{ show_m(n); }
end;
{--------------proc1--------------------}
function proc1 (n:integer):boolean;
{ var zz:integer;}
begin
for z:=1 to n do
if z<>city1 then
begin
if z=city2 then proc1:=true
else
begin {else}
if proc1(n+1) then
write(city2);
end; {else}
end;
end;
(*--------------------------------------------------------*)
begin {of main body}
{ clrscr;}
get_cities;
write('enter 2 city : ');
readln(city1,city2);
b[1]:=city1;
t:=1;
f(city1,1);
{ show_matrix(n); }
readln;
end. {of main body}
(*------------------------------------*)
---------------------------------------------------------------------------------------------
نوشته شده توسط گرامی در 28 تير 1387 ساعت 00:39