Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
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

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, multi-dimensional 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 non-full 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
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 3 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: