|
|
@@ -5,16 +5,16 @@ const Shape = shapeModule.Shape;
|
|
|
const kShapeSize = shapeModule.kShapeSize;
|
|
|
|
|
|
pub const Area = struct {
|
|
|
- rows: u8 = 0,
|
|
|
- cols: u8 = 0,
|
|
|
+ rows: i32 = 0,
|
|
|
+ cols: i32 = 0,
|
|
|
data: []u8 = undefined,
|
|
|
dataAllocator: std.mem.Allocator,
|
|
|
|
|
|
- pub fn init(allocator: std.mem.Allocator, rows: u8, cols: u8) !Area {
|
|
|
+ pub fn init(allocator: std.mem.Allocator, rows: i32, cols: i32) !Area {
|
|
|
var area: Area = .{
|
|
|
.rows = rows,
|
|
|
.cols = cols,
|
|
|
- .data = try allocator.alloc(u8, rows*cols),
|
|
|
+ .data = try allocator.alloc(u8, @intCast(rows*cols)),
|
|
|
.dataAllocator = allocator,
|
|
|
};
|
|
|
|
|
|
@@ -32,7 +32,7 @@ pub const Area = struct {
|
|
|
const area: Area = .{
|
|
|
.rows = self.rows,
|
|
|
.cols = self.cols,
|
|
|
- .data = try allocator.alloc(u8, self.rows*self.cols),
|
|
|
+ .data = try allocator.alloc(u8, @intCast(self.rows*self.cols)),
|
|
|
.dataAllocator = allocator,
|
|
|
};
|
|
|
std.mem.copyForwards(u8, area.data, self.data);
|
|
|
@@ -49,17 +49,19 @@ pub const Area = struct {
|
|
|
return freeSize;
|
|
|
}
|
|
|
|
|
|
- pub fn getCell(self: *const Area, row: u8, col: u8) u8 {
|
|
|
- return self.data[row*self.cols + col];
|
|
|
+ pub fn getCell(self: *const Area, row: i32, col: i32) u8 {
|
|
|
+ return self.data[@intCast(row*self.cols + col)];
|
|
|
}
|
|
|
|
|
|
- pub fn setCell(self: *Area, row: u8, col: u8, cell: u8) void {
|
|
|
- self.data[row*self.cols + col] = cell;
|
|
|
+ pub fn setCell(self: *Area, row: i32, col: i32, cell: u8) void {
|
|
|
+ self.data[@intCast(row*self.cols + col)] = cell;
|
|
|
}
|
|
|
|
|
|
pub fn print(self: *const Area, allocator: std.mem.Allocator) !void {
|
|
|
- for (0..self.rows) |row| {
|
|
|
- for (0..self.cols) |col| {
|
|
|
+ const rows:usize = @intCast(self.rows);
|
|
|
+ const cols:usize = @intCast(self.cols);
|
|
|
+ for (0..rows) |row| {
|
|
|
+ for (0..cols) |col| {
|
|
|
const cell = self.getCell(@intCast(row), @intCast(col));
|
|
|
try std.fs.File.stdout().writeAll(
|
|
|
try std.fmt.allocPrint(allocator, "{c}", .{cell}));
|
|
|
@@ -70,7 +72,7 @@ pub const Area = struct {
|
|
|
}
|
|
|
|
|
|
pub fn appendShape(self: * const Area, allocator: std.mem.Allocator,
|
|
|
- shape: *const Shape, row: u8, col: u8, shapeSymbol: u8) !?Area {
|
|
|
+ shape: *const Shape, row: i32, col: i32, shapeSymbol: u8) !?Area {
|
|
|
var area = try self.copy(allocator);
|
|
|
for (0..kShapeSize) |shapeRow| {
|
|
|
for (0..kShapeSize) |shapeCol| {
|
|
|
@@ -78,13 +80,15 @@ pub const Area = struct {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- const areaRow:u8 = @intCast(shapeRow + row);
|
|
|
+ var areaRow:i32 = @intCast(shapeRow);
|
|
|
+ areaRow += row;
|
|
|
if (areaRow >= area.rows) {
|
|
|
area.deinit();
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- const areaCol:u8 = @intCast(shapeCol + col);
|
|
|
+ var areaCol:i32 = @intCast(shapeCol);
|
|
|
+ areaCol += col;
|
|
|
if (areaCol >= area.cols) {
|
|
|
area.deinit();
|
|
|
return null;
|