I have to design a relatively simple game-type programm on pascal
It has to generate a way, which the player will have to guess. They way can only go horizontaly or verticaly. Im usign 10x10 array for this. The problems start, when im making the way for player and checking if randomly roled next piece is possible. Im checking if adjescent pieces of next piece are already road. There should only be one piece there, the way hes comming from, and no any other for it not to merge. There the programm stucks in loop;
heres the code

program KD;
Uses crt;
Var
	mass:array[1..10,1..10] of integer;
	mass2: array[1..10,1..10] of integer;
	Sx, Sy, TSx, TSy, CSx, CSy, mov, itcheck, itcase, IT,P:integer;
	
Label start;
Label nextfield;
Label endgen;
Label nextmove;
Label endgame;

function nextmoveitcheck(ITSx, ITSy: integer):integer;
	Begin
		itcase:=0;
		begin
		if (itsx=1) or (itsx=10) then
			itcase:=(itcase+1);
		if (itsy=1) or (itsy=10) then
			itcase:=(itcase+1);
		end;
		Begin
		Itcheck:=0;
		if (itsx+1<>11) then
			Begin
			CSx:=(itsx+1);
			CSy:=(itsy);
			if (mass[CSx][CSy]=1) then
				itcheck:=(itcheck+1);
			end;
		if (itsx-1<>0) then
			Begin
			CSx:=(itsx-1);
			CSy:=(itsy);
			if (mass[CSx][CSy]=1) then
				itcheck:=(itcheck+1);
			end;
		if (itsy+1<>11) then
			Begin
			CSx:=itsx;
			CSy:=(itsy+1);
			if (mass[CSx][CSy]=1) then
				itcheck:=(itcheck+1);
			end;
		if (itsy-1<>0) then
			Begin
			CSx:=itsx;
			CSy:=(itsy-1);
			if (mass[CSx][CSy]=1) then
				itcheck:=(itcheck+1);
			end;
		end;
		begin
		case itcase of
		0:
			begin
			if (itcheck=4) then
				nextmoveitcheck:=1;
			if (itcheck>1) then
				nextmoveitcheck:=2;
			if (itcheck=1) then
				nextmoveitcheck:=3;
			end;
		1:
			begin
			if (itcheck=3) then
				nextmoveitcheck:=1;
			if (itcheck=2) then
				nextmoveitcheck:=2;
			if (itcheck=1) then
				nextmoveitcheck:=3;
			end;
		2:
			begin
			if (itcheck=2) then
				nextmoveitcheck:=1;
			if (itcheck=1) then
				nextmoveitcheck:=3;
			end;
		end;
		end;
	writeln(itcheck);
	end;


Begin
	begin
		for Sx:=1 to 10 do
			for Sy:=1 to 10 do
			Begin
				mass[Sx][Sy]:=0;
				mass2[Sx][Sy]:=0;
			end;
	end;
	Mass[1][1]:=1;
	mass2[1][1]:=1;
	mass[10][10]:=1;
	mass2[10][10]:=1;
	Start:
		Begin
		Clrscr;
		randomize;
		Sx:=1;
		Sy:=1;
		nextfield:
			Begin
			mov:=random(4);
			Case mov of
			0:
				Begin
					TSx:=(Sx+1);
					TSy:=Sy;
				end;
			1:
				Begin
					TSx:=(Sx-1);
					TSy:=Sy;
				end;
			2:
				begin
					TSx:=Sx;
					TSy:=(Sy+1);
				end;
			3:
				Begin
					TSx:=Sx;
					TSy:=(Sy-1);
				end;
			end;
			end;
		If (TSx=0) or (TSx=11) or (TSy=0) or (TSy=11) then
		goto nextfield;
		if (TSx=10) and (TSy=10) then
		goto endgen;
		IT:=(nextmoveitcheck(Tsx, Tsy));
		case it of
		1:
			Begin
			goto start
			end;
		2:
			Begin
			goto nextfield
			end;
		3:
			Begin
			Sx:=TSx;
			Sy:=TSy;
			mass[Sx][Sy]:=1;
			writeln('Field generation succesfull');
			goto nextfield;
			end;
		end;
	endgen:
        writeln('Field has been generated, press any key to start!');
        readln;
	end;

	Begin
	Sx:=1;
	Sy:=1;
	nextmove:
	Clrscr;
	writeln;
		for TSx:=1 to 10 do
			Begin
			writeln;
			for TSy:=1 to 10 do
				Begin
				If (TSx=Sx) and (TSy=Sy) then
				write ('S':2);
				If ((TSy=Sy+1) or (Tsy=sy-1)) and ((TSx=Sx+1) or (Tsx=Sx-1)) then
				write ('P':2)
				else
				write (mass2[TSx][TSy]:2);
				end;
			end;
		end;
	Begin
		writeln;
		writeln('Your current possition is ' ,Sx, ' and ' ,Sy);
		Writeln('please input two numbers betwen 1 to 10');
		Readln(CSx);
		Readln(Csy);
		If (CSy=23) then
			Begin
			Begin
			For TSx:=1 to 10 do
				Begin
				writeln;
				For TSy:=1 to 10 do
					Begin
					write(mass[TSx][TSy]:2);
					end;
				end;
			end;
			readln;
			end;
		if (CSy=0) or (Csy=11) or (Csx=0) or (Csx=11) then
			Begin
			writeln('impossible move, press any key to try again');
			readln;
			goto nextmove;
			end;
		If (Csy<>Sy+1) or (Csy<>Sy-1) then
			Begin
			writeln('impossible move, press any key to try again');
			readln;
			goto nextmove;
			end;
		If (CSx<>Sx+1) or (CSx<>Sx-1) then
			Begin
			writeln('impossible move, press any key to try again');
			readln;
			goto nextmove;
			end;
		if (CSy=10) and (CSx=10) then
			goto endgame;
		If (mass[Csx][Csy]=1) then
			Begin
			writeln('You move on, press any key to continue');
			Mass2[Sx][Sy]:=1;
			Sx:=Csx;
			Sy:=csy;
			readln;
			goto nextmove;
			end;
		if (mass[CSx][CSy]=0) then
			Begin
			writeln('Incorect move, try again! (Press any key to continue)');
			readln;
			goto nextmove;
			end;
	end;
	endgame:
	Begin
	writeln('You have won the game! congratz!');
	writeln('Press 1 to quit, press any key to play again!');
	readln(P);
	if P<>1 then
	goto start;
	end;
	
end.

I found the error myself, I forgot to clear the Array before each usage, so evidently it filled up.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.