NKXXGBPMUBFVEBTQAWPKWTQBAGXGLAZFTSJVYISLPCFNEB3W32NAC
unit SysRandom;
interface
procedure Randomize;
implementation
{$ifdef UNIX}
procedure Randomize;
const
RandomDeviceName = '/dev/urandom';
var
RandomNumber: Cardinal;
RandomReader: File of Cardinal;
begin
Assign(RandomReader, RandomDeviceName);
{$push}
{turn off runtime error gen}
{$IOChecks off}
Reset(RandomReader);
if IOResult() = 0 then
begin
WriteLn('opened');
Read(RandomReader, RandomNumber);
if IOResult() = 0 then
begin
System.RandSeed := RandomNumber;
Close(RandomReader);
end
else System.Randomize;
end
{$pop}
else
begin
System.Randomize;
end;
end;
{$else}
procedure Randomize;
begin
System.Randomize;
end;
{$endif}
end.
TCell = (Empty, Bomb);
TField = record
Cells: array of TCell;
Rows: Integer;
Cols: Integer;
end;
TCell = (Empty, Bomb);
TField = record
Cells: array of TCell;
Open: array of Boolean;
Rows: Integer;
Cols: Integer;
end;
function FieldGet(Field: TField; Row, Col: Integer): TCell;
begin
FieldGet := Field.Cells[Row * Field.Cols + Col];
end;
Field.Cells[Row * Field.Cols + Col] := Cell;
Field.Cells[Row * Field.Cols + Col] := Cell;
end;
procedure FieldResize(var Field: TField; Rows, Cols: Integer);
begin
SetLength(Field.Cells, Rows * Cols);
SetLength(Field.Open, Rows * Cols);
Field.Rows := Rows;
Field.Cols := Cols;
WriteLn('hello world')
Row := Random(Field.Rows);
Col := Random(Field.Cols);
FieldRandomCell := FieldGet(Field, Row, Col);
end;
procedure FieldRandomize(var Field: TField; BombsPercentage: Integer);
var
Index, BombsCount: Integer;
Row, Col: Integer;
begin
for Index := 0 to Field.Rows * Field.Cols do
begin
Field.Cells[Index] := Empty;
Field.Open[Index] := False;
end;
if BombsPercentage > 100 then BombsPercentage := 100;
BombsCount := (Field.Rows * Field.Cols * BombsPercentage + 99) div 100;
for Index := 1 to BombsCount do
begin
while FieldRandomCell(Field, Row, Col) = Bomb do ;
FieldSet(Field, Row, Col, Bomb);
end;
end;
function FieldCountNeighbors(Field: TField; Row, Col: Integer): Integer;
var
DRow, DCol: Integer;
Cell: TCell;
begin
FieldCountNeighbors := 0;
for DRow := -1 to 1 do
for DCol := -1 to 1 do
if (DRow <> 0) or(DCol <> 0) then
begin
if FieldGetChecked(Field, Row + DRow, Col + DCol, Cell) then
if Cell = Bomb then
Inc(FieldCountNeighbors);
end;
end;
procedure FieldWrite(Field: TField);
var
Row, Col, Neighbors: Integer;
begin
for Row := 0 to Field.Rows - 1 do
begin
for Col := 0 to Field.Cols - 1 do
begin
Write(' ');
if FieldIsOpen(Field, Row, Col) then
case FieldGet(Field, Row, Col) of
Bomb: Write('*');
Empty: begin
Neighbors := FieldCountNeighbors(Field, Row, Col);
if Neighbors > 0 then Write(Neighbors) else Write(' ');
end;
end
else Write('#');
Write(' ');
end;
WriteLn;
end;
end;
var
MainField: TField;
begin
Randomize;
FieldResize(MainField, 10, 10);
FieldRandomize(MainField, 20);
FieldSet(MainField, 0, 0, Bomb);
FieldSet(MainField, 0, 1, Bomb);
FieldWrite(MainField);
current_page=1
FILE_NAME_0=203;Pascal;0;EUTF-8;1;1;0;%2Fhome%2Fkyle%2FDocuments%2Fmine%2Fmine.pas;0;4
FILE_NAME_1=29;None;0;EUTF-8;1;1;0;%2Fhome%2Fkyle%2FDocuments%2Fmine%2F.ignore;0;4
current_page=0
FILE_NAME_0=26;None;0;EUTF-8;1;1;0;%2Fhome%2Fkyle%2FDocuments%2Fmine%2F.ignore;0;4
FILE_NAME_1=221;None;0;EUTF-8;1;1;0;%2Fhome%2Fkyle%2FDocuments%2Fmine%2F.editorconfig;0;4
FILE_NAME_2=173;Pascal;0;EUTF-8;0;1;0;%2Fhome%2Fkyle%2FDocuments%2Fmine%2Fsysrandom.pas;0;2
FILE_NAME_3=0;Pascal;0;EUTF-8;0;1;0;%2Fhome%2Fkyle%2FDocuments%2Fmine%2Fmine.pas;0;2
FILE_NAME_4=26;Make;0;EUTF-8;1;1;0;%2Fhome%2Fkyle%2FDocuments%2Fmine%2Fmakefile;0;8
.PHONY: all
all:
fpc mine.pas
root = true
[*]
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = true
charset = utf-8
[*.pas]
indent_style = space
indent_size = 2
[makefile]
indent_style = tab
indent_size = 8