It is the almighty 2048 game..

http://gabrielecirulli.github.io/2048/

and we have to do a simpler version in pascal language.

This is the code i've made till now..

program game2048;

uses crt;

const max = 4;

type matriz = array [1..max,1..max] of integer;

var tabla:matriz;

key:char;

procedure random2 (var k:matriz);

var n1,n2:integer;

begin

repeat

randomize;

n1:=random(3)+1;

n2:=random(3)+1

until k[n1,n2]=0;

k[n1,n2]:=2;

end;

procedure cargaMatriz (var s:matriz);

var i,j:integer;

begin

for i:=1 to max do

begin

for j:=1 to max do

begin

s[i,j]:=0;

end;

end;

random2(s);

random2(s);

end;

function check0 (s:matriz):boolean;

var i,j,c:integer;

begin

c:=0;

for i:=1 to max do

begin

for j:= 1 to max do

begin

if s[i,j]=0 then

c:=c+1;

end;

end;

if c=0 then

check0:=false

else

check0:=true;

end;

procedure printM (var s:matriz);

var i,j:integer;

begin

textbackground(lightgray);

textcolor(black);

clrScr;

for i:= 1 to max do

begin

for j:= 1 to max do

begin

if (check0(s)) then

write(s[i,j],' ')

else

write('c*est fini');

end;

writeln;

end;

end;

procedure movr(var s:matriz);

var i,j,k,aux:integer;

begin

for i:= 1 to max do

for j:= max downto 1 do

for K:= j downto 1 do

begin

if ((s[i,j]=0) and (s[i,k]<>0)) then

begin

aux:=s[i,j];

s[i,j]:=s[i,k];

s[i,k]:=aux;

end;

end;

end;

procedure merger(var s:matriz);

var i,j: integer;

begin

for i:=1 to max do

for j:= 2 to max do

if (s[i,j]=s[i,j-1]) then

begin

s[i,j-1]:=s[i,j-1]+s[i,j];

s[i,j]:=0;

end;

end;

procedure movl(var s:matriz);

var i,j,k,aux:integer;

begin

clrScr;

for i:= 1 to max do

for j:= 1 to max do

for K:= j to max do

begin

if ((s[i,j]=0) and (s[i,k]<>0)) then

begin

aux:=s[i,j];

s[i,j]:=s[i,k];

s[i,k]:=aux;

end;

end;

end;

procedure mergel(var s:matriz);

var i,j: integer;

begin

for i:=1 to max do

for j:= 1 to max-1 do

if (s[i,j]=s[i,j+1]) then

begin

s[i,j]:=s[i,j]+s[i,j+1];

s[i,j+1]:=0;

end;

end;

procedure movu(var s:matriz);

var i,j,k,aux:integer;

begin

clrScr;

for i:= 1 to max do

for j:= 1 to max do

for K:= i to max do

begin

if ((s[i,j]=0) and (s[k,j]<>0)) then

begin

aux:=s[i,j];

s[i,j]:=s[k,j];

s[k,j]:=aux;

end;

end;

end;

procedure mergeu(var s:matriz);

var i,j:integer;

begin

for j:= 1 to max do

for i:=1 to max-1 do

if (s[i,j]=s[i+1,j]) then

begin

s[i,j]:=s[i+1,j]+s[i,j];

s[i+1,j]:=0;

end;

end;

procedure movd(var s:matriz);

var i,j,k,aux:integer;

begin

clrScr;

for i:= max downto 1 do

for j:= 1 to max do

for K:= i downto 1 do

begin

if ((s[i,j]=0) and (s[k,j]<>0)) then

begin

aux:=s[i,j];

s[i,j]:=s[k,j];

s[k,j]:=aux;

end;

end;

end;

procedure merged(var s:matriz);

var i,j:integer;

begin

for j:= 1 to max do

for i:= max downto 2 do

if (s[i,j]=s[i-1,j]) then

begin

s[i,j]:=s[i-1,j]+s[i,j];

s[i-1,j]:=0;

end;

end;

begin

cargamatriz(tabla);

printM(tabla);

writeln('Bienvenido, presione Arriba/aBajo/Izquierda/Derecha o Esc');

repeat

key:=readkey;

begin

case key of

'I','i' : begin

mergel(tabla);

movl(tabla);

random2(tabla);

printm(tabla);

end;

'A','a' : begin

mergeu(tabla);

movu(tabla);

random2(tabla);

printm(tabla);

end;

'D','d' : begin

merger(tabla);

movr(tabla);

random2(tabla);

printm(tabla);

end;

'B','b' : begin

merged(tabla);

movd(tabla);

random2(tabla);

printm(tabla);

end;

end;

end;

until key=#27;

readkey;

end.

one of the thing i don't understand is why the 'random2' procedure doesn't seem to work in the general program, even though it works well when i call it from the procedure 'cargarMatriz'.. and also when i execute it the program it work fine for a while, but after a certain point just it stops displaying.. before ending the game..

Well, i'm a fresher so any hints on a more appropriate aproach will be helpfull..

]]>Thanks in advance.

]]>procedure TimerInt; interrupt;

begin

asm

pushf

call dword ptr [oldtimer]

cli

end;

if mutex = 0 then begin

mutex := 1;

asm

sti

end;

result := vpmPasTcpClose(conn);

asm

cli

end;

mutex := 0;

end;

end;

As you can see. some measures have been done against calling PC/TCP close reentrantly. If I comment out the PC/TCP call, everything works OK, so it seems to me that the problem is in calling PC/TCP. I failed to fix this:

1) It does not matter whether I intercept int $08 or int $1c - everything is the same.

2) Locking code segments using {$C FIXED PERMANENT} directive does not help.

3) Switching to a specially allocated new stack after calling the previous handler (and restoring the original stack pointer after PC/TCP call) does not help.

4) Using "call real mode procedure with an IRET frame" DPMI function instead of "simulate real mode interrupt" does not help.

5) Providing a real mode stack for the PC/TCP call (by allocating a real mode memory block and placing its address in the DPMI real mode registers structure) does not help.

In any case DOS hangs.

As I noted above, in real mode everything is OK (of course, in real mode I am using int $61 directly instead of DPMI). Calling the same close connection function in protected mode from the main code (not from the interrupt handler) does work.

What may I be doing wrong? Is there anything else that I don't take into account? Is it anything in PC/TCP that prevents calling it from an interrupt handler? If so, what to do?

`program test;

var

grid_esy:array [0..10,0..10] of integer; //might change togrid_esy:array [0..10,0..10] of integer;

grid_esy_adj:array [0..10,0..10] of integer;

grid_avg:array [1..15,1..15] of integer;

grid_hrd:array [1..20,1..20] of integer;

grid_esy_visual:array [0..10,0..10] of char;

index,counter,grid_esy_column,TypeOfGame,grid_esy_row:integer;

column,row,x,y,turn:integer;

comma:char;

label 1,2,3,4,6,7;

begin

randomize;

writeln('What type of game would you like');

writeln('1.) easy');

writeln('2.) average');

writeln('3.) Hard(ish)');

readln(TypeOfGame);

case TypeOfGame of

1: 1: begin

writeln('Use grid functions to pick your block.');

For grid_esy_row:=1 to 9 do // change values for harder difficulty

begin

For grid_esy_column:=1 to 9 do // change values for hared difficulty

begin

grid_esy[grid_esy_row,grid_esy_column]:=0;

write(grid_esy[grid_esy_row,grid_esy_column]);

end;

writeln;

end;

goto 2;

{----------------------------------grid set-------------------------------------------}

2: for index:=1 to 10 do // change values for harder difficulty

3: begin

row:=0;

column:=0;

row:=random(9)+1;

column:=random(9)+1;

if grid_esy[row,column] = 0

then begin

grid_esy[row,column]:=9; // change values for harder difficulty

writeln(row,column);

writeln(grid_esy[row,column]);

end

else begin

goto 3;

end;

end;

{----------------------------------mines set-------------------------------------------}

```
For row:=1 to 9 do // change values for harder difficulty
begin
For column:=1 to 9 do
begin
If grid_esy[row,column] <> 9
then
begin
If grid_esy[row - 1,column]= 9
then
begin
grid_esy_adj[row,column]:= 1 + grid_esy_adj[row,column];
end;
IF grid_esy[row + 1,column]= 9
then
begin
grid_esy_adj[row,column]:= 1 + grid_esy_adj[row,column];
end;
IF grid_esy[row - 1,column - 1]= 9
then
begin
grid_esy_adj[row,column]:= 1 + grid_esy_adj[row,column];
end;
IF grid_esy[ row + 1,column + 1]= 9
then
begin
grid_esy_adj[row,column]:= 1 + grid_esy_adj[row,column];
end;
IF grid_esy[row,column + 1]= 9
then
begin
grid_esy_adj[row,column]:= 1 + grid_esy_adj[row,column];
end;
IF grid_esy[row,column - 1]= 9
then
begin grid_esy_adj[row,column]:= 1 + grid_esy_adj[row,column];
end;
IF grid_esy[row - 1,column + 1]= 9
then
begin grid_esy_adj[row,column]:= 1 + grid_esy_adj[row,column];
end;
IF grid_esy[row + 1,column - 1]= 9
then
begin grid_esy_adj[row,column]:= 1 + grid_esy_adj[row,column];
end;
end
else
begin
grid_esy_adj[row,column]:=9
end;
end;//end of loop 2
end;//end of loop 1
```

{----------------------------------labeling-------------------------------------------}

counter:=0;

writeln;

```
For row:=1 to 9 do
begin
For column:=1 to 9 do
begin
grid_esy_visual[row,column] := char (254);
end;
writeln;
end;
```

6: For row:=1 to 9 do

begin

For column:=1 to 9 do

begin

write(grid_esy_visual[row,column]);

end;

writeln;

end;

```
Write('Use X and Y coordinates to pick Block you want to target: ');
read(x);
read(comma);
readln(y);
turn:=1 + turn;
If grid_esy_adj[x,y] = 9
then
begin
If turn = 1
then
begin
if grid_esy_adj[x,y] = 9
then
begin
```

7: row:=random(9)+1;

column:=random(9)+1;

grid_esy_adj[x,y]:=0;

for index:=1 to 1 do

begin

if grid_esy_adj[row,column] = 0

then begin

grid_esy_adj[row,column]:=9; // change values for harder difficult

end

else begin

goto 7;

end;

end;

end;

end

else

begin

goto 4;

end;

end

else

begin

If grid_esy_adj[x,y] = 0

then // Rows the Columns Y then X

begin

grid_esy_visual[x,y] := char(255);

repeat

until

goto 6;

end

else

begin

grid_esy_visual[x,y]:=char(grid_esy_adj[x,y] + 48);

goto 6;

end;

```
end;
```

4: writeln('That was a bomb sorry');

turn:=turn - 1;

writeln('You finshed ',turn:0,' turns without hitting a bomb');

{----------------------------------clearing/picking-------------------------------------------}

end;// end of case

```
2: begin
end
3: begin
end
end;
```

end.

`

]]>Make a program in Pascal that after has read a text with a list of nums., it will return the numb. of the nums that appear less than one times in the text.

The text that will be read from the program should be like that.

In the first line there are two nums. seperated by a space, n and m. N is the number of nums that exist, like if the text contains the numbers 1,2,3,4, n is 4 (1..n).

M is how many lines follow.

Every line has a couple of nums, a,b, (1=<a=<n), (1=<b=<n) (a<>b)

a and b are separated by a space.

The file that the program will make will have written on it a num., that says how many nyms are appeared less than two tims in the text.

All the nums. are Integer.

0=<p=<n

i've made the following program, but it only reads the first line of the text. Anyone that can help me? The deadline is almost ended. Thanks in advance.

My code is the following.

Program thefinalp;

Uses SysUtils;

Var

f:Text;

m,d:Integer;

n:Char;

c:String[1];

a,e:array of integer;

LowArr:Integer;

HighArr:Integer;

ArrayLen:Integer;

i:Integer;

begin

Assign(f,'finalp.txt');

Reset(f);

repeat

Read (f,n);

Write(n);

until (n=' ');

Read(f,c);

Write(c);

while not SeekEoln(f) do

begin

read(f,d);

Write(d);

End;

Readln;

Writeln;

StrToIntDef(n,m);

setlength(a,m);

LowArr:=Low(a);

HighArr:=High(a);

ArrayLen:=Length(a);

setlength(e,m);

LowArr:=Low(e);

HighArr:=High(e);

ArrayLen:=Length(e);

for i:= LowArr to HighArr do

begin

repeat

Read (f,a[i]);

Write(a[i]);

until (n=' ');

Read(f,c);

Write(c);

while not SeekEoln(f) do

begin

read(f,e[i]);

Write(e[i]);

End;

Readln;

Writeln;

End;

Readln;

End.

I've made the code after that, the program is how to put into variables all the nums.

I'm a beginner so if anyone could give me an example, would help a lot.

domes.in domes.out

6 7 2

2 4

4 1

3 5

4 3

1 3

http://postimg.org/image/ep71zfqot/

The file represents stock as it is purchased. Therefore more products may be added to it of different/same sizes and barcodes. Each individual item creates a new record whether it be a new size or barcode for example if you have two products of the same barcode and size it stores them as two records. I need a procedure which sorts the records into ascending order of the barcodes and combines the sizes to one record and marks the others for deletion so that the file is like the one in the image below:

http://postimg.org/image/y8sk6dg1p/

-1 means its marked for deletion

i was told i need to do a nested while loop. However i was unable to get it to work

thank you, all help appreciated.

]]>I've run into a little problem while writing a terrain generator in PASCAL for a Minecraft-type sandbox game.

I am storing all block data in an array of records, each with a "noiseID" entry, which is the data generated by the "PerlinNoise" function, and decides what the block should be.

The PerlinNoise function, however, is not working. I followed the instructions on this site and transferred the code over to pascal:

http://freespace.virgin.net/hugo.elias/models/m_perlin.htm

However, the "smoothNoise" function is not working properly. Once called, the program exits with code 217. The output says "range check error", but I don't see how anything is out of range.

Here is the code (download Link):

http://www.sendspace.com/file/jd6xvq

]]>

First of all, I have to read the two big numbers from a file, they are written each on a row. So this would look like:

assign(f,'numere.txt');

reset(f);

string:='';

while not eoln do begin

read(a);

string:=string+'a';

end;

and same for the other number? ]]>