Turing tetris removing and adding arrays
Author 
Message 
axianna

Posted: Sun Jan 20, 2019 10:27 am Post subject: Turing tetris removing and adding arrays 


What is it you are trying to achieve?
Add and remove an array element into a flexible 2d array
Describe what you have tried to solve this problem
I'm tried to make a new flexible array and then add the elements from the original array into the new array skipping over the rows that are full, but now I have a problem in adding empty values on top
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Turing: 
function removeRow(grid:array 1..26 of array 1..12 of int):array 1..26 of array 1..12 of int
var gridcopy : flexible array 1..0 of array 1..12 of int
var emptygrid : array 1..12 of int :=init(100,0,0,0,0,0,0,0,0,0,0,0,0,100)
var fullrows: int := 0
var toprow: int :=0
for i :1..11
if checkRowFull(grid)(i)=false then
new gridcopy, i
gridcopy(i):=grid(i)
toprow:=i
else
fullrows+=1
end if
end for
for i : 1.. fullrows
new gridcopy, toprow+i
gridcopy(toprow+i):= emptygrid
%%%this part doesn't work%%%%%%
end for
end removeRow

Please specify what version of Turing you are using
<Answer Here>






Sponsor Sponsor



Insectoid

Posted: Sun Jan 20, 2019 11:05 am Post subject: RE:Turing tetris removing and adding arrays 


You're taken an interesting approach to solving this problem. Unfortunately it's also the slowest and most complicated. Flexible arrays are extremely slow every time you call new, the entire array gets copied to a new one, and the old one gets deleted. On top of that, multidimensional flexible arrays were never fully implemented in Turing so some things that should work, don't. Surely your Tetris game board doesn't change size during the game, so why not just use regular arrays preset to the max size?
Anyway, this line is a problem: gridcopy(i):=grid(i)
Your full rows *are* being skipped, but your nonfull rows are being copied to the same position in the new array, instead of being moved to the bottom.
What is the value of toprow after the first for loop runs?
In the line gridcopy(toprow+i), what does tomorrow+i resolve to? Your empty rows are being added to the array, but where are they?
If you were not using flexible arrays, Turing would have given you an error that would have helped you solve this. Instead of trying to delete the data structure itself, try just deleting the contents of the data structure. Your algorithm is a bit like rebuilding an entire house just to change the wallpaper.






axianna

Posted: Sun Jan 20, 2019 12:50 pm Post subject: Re: Turing tetris removing and adding arrays 


ok thank you so much for the advice! I'll go test some new stuff now ty ty







