[英]Replace characters in a table - ADA
我用表中的字符创建了一个表(62 x 35)。 我正在尝试从中间替换10 x 10表格中的字符。
例如,如果我有一个看起来像这样的表:(62 x 35)
##############################################################
##############################################################
##############################################################
##############################################################
##############################################################
##############################################################
##############################################################
##############################################################
##############################################################
##############################################################
##############################################################
##############################################################
##############################################################
##############################################################
##############################################################
##############################################################
##############################################################
##############################################################
我希望能够加载包含(10x10)的文件:
//////////
//////////
//////////
//////////
//////////
//////////
//////////
//////////
//////////
//////////
以便此文件中的字符替换先前创建的表中的字符
即有一张看起来像的桌子
##############################################################
##############################################################
##############################################################
##############################################################
##############################################################
##############################################################
##########################//////////##########################
##########################//////////##########################
##########################//////////##########################
##########################//////////##########################
##########################//////////##########################
##########################//////////##########################
##########################//////////##########################
##########################//////////##########################
##########################//////////##########################
##########################//////////##########################
##############################################################
##############################################################
##############################################################
##############################################################
##############################################################
我认为我要做的事情不是很清楚,所以如果您想了解更多细节,请询问。
procedure Grid_Pilliers(A: out Grid) is -- creates grid with pilliers --
begin
for I in 0..31 loop
for J in 0..75 loop
if (I mod 4 = 1 or I mod 4 = 0) and (J mod 4 = 1 or J mod 4 = 0) then
A(I,J) := true ;
else
A(I,J) := false ;
end if ;
end loop ;
end loop ;
end Grid_Pilliers ;
procedure New_Grid_Random_Fill(A : in out New_Grid) is
type Numero is range 0 .. 1;
package Grid_Random is new Ada.Numerics.Discrete_Random (Numero);
use Grid_Random;
Random_Number : Numero;
G : Generator;
begin
Reset (G);
for I in A'Range(1) loop
for J in A'Range(2) loop
Random_Number := Random (G);
A(I,J) := (Random_Number = 1);
end loop;
end loop;
end New_Grid_Random_Fill;
您可能应该使用切片...但是在此示例中,我将使用一对for循环。 假设您已将表类型( Grid
)定义为Array (Positive Range <>, Positive Range <>) of Character
...
procedure copy_into( Working : in out Grid; subimage : in Grid;
Offset_X, Offset_Y : Natural ) is
begin
-- insert checks for subimage lengths [plus offsets]
-- to be less than Working's lengths.
for index_x in subimage'Range(1) loop
for index_y in subimage'Range(2) loop
Working(index_x+offset_x, index_y+offset_y):= subimage(index_x, index_y);
end loop;
end loop;
end copy_into;
获取偏移量很简单:
offset_x = big_grid_width + small_grid_width / 2。
offset_y =以上,但使用高度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.