Shifting elements in multidementional array

Hello,
I'm working on a boardgame project which uses an int[][] to represent the board. The elements in this array are numbers which represent vehicles. The equal numbers are one vehicle. A vehicle can perform a step left/right, or a step up/down (if there is no other vehicle blocking the way of course).
I've read about the arraycopy method, but I don't know how to use it with an array of arrays.
So an example of the matrix would look like this:
111002
300502
344502
300500
000000
666000
After a step of one vehicle the matrix could be:
011102
300502
344502
300500
000000
666000
I need to get matrices for all possible moves, for all vehicles.
I couldn't find any documentation about the use of copyarray with an array of arrays. Hope someone can point me in the right direction.
Thanks in advance

Ceylor wrote:
Hello all,
thanks very much for the quick replies.
prometheuzz, I've read the topic you mentioned and your explanation is great. Your UML makes it very clear.You're welcome.
I allready use OOP as much as possible. In my project I use a playField class (the board, also GUI), a node class (extends from rectangle, a cell in the field), a vehicle class (contains a collection of nodes and some other properties), a class for my algoritm and a state class.Good to hear that.
The state class is used for storing all possible states of the playField. (ie all valid moves). These states are needed for a shortest path algoritm, and are not automatically a state the playField gets. Therefor I can't use the vehicles stored in the playField class because this class only contains the initial state of the game. The playField only get's updated when the algoritm is done and a shortest path is found. So would it be a good solution to store a collection of vehicles inside my state class?I'm don't quite follow you here, I'm afraid.
The thing I'm a bit worried about is that there can be a lot of states. When adding the vehicles to each state object, doesn't this slow things down?
...Don't worry about inefficient code too soon. First get your logic correct: check your algorithm against a small puzzle, ensure that it works. After that, try some larger puzzles to see if a solution is found within the required time frame. If it takes too long, only then adjust your algorithm.
Feel free to post back if you have any questions.
Good luck.

Similar Messages

  • Summing specified elements in 2D array.

    Hi!
    I have a little problem with summing elements in 2D array… I have signal from 64 sources in the 2D array - 64 colums and (time*sampling) rows. I have to add some deley to every signal (different for each)  and then sum signals from all of the sources. I hope the picture below explains what I have to do:
    What's more - I have a 2D array of delays. By now I'm doing this by creating an 1D array of "0" and then putting in it the 1D signal array at index specified by delay value.
    And it works ok. But... It takes long time... Is there any method to do the summing "at once" for all the delays? Is there sth like "pointer" in array, so I could take elements from the array from specified element?
    Rgds,
    Mordimer 

    One problem with your solution is also that the subset is of variable lenght due to truncation, so the shift register needs to be reallocated whenever the size changes. (Even if you define a lenght for the subset, you run out of elements and the result will be shorter!). You might want to e.g. truncate all to the shortest subset (longest delay) before summing for better inplaceness.
    Why do you have a 2D array of delays? isn't the time spacing of each column constant?
    What is your definition of "takes a long time": microseconds?, minutes?
    Message Edited by altenbach on 12-03-2009 03:20 PM
    LabVIEW Champion . Do more with less code and in less time .

  • Updating elements in my array

    Hello
    Im very new to Labview and this may seem like a trivial problem to some. But it is driving me crazy. I have an array that i want to display as a table. I want to be able to input into this table and be able to add rows or delete rows as i please. The problem is that if I enter a number in an element of the array and i add a row it blanks out whatever I had written. Attached is my code. I think there should be a simple solution to this coz i havent been able to find much online help to it.
    Attachments:
    test-1.vi ‏208 KB

    The changes of the array values are not recorded in the shift register. You have to catch another event : the array value change, and pass the new array value to the right shift register.
    CC
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        

  • How to insert elements into an array after each iteration of a for loop

    I am new to labview and working on an application where I am supposed to store an element into an array (without overwriting) after each iteration in a for loop. I have tried using Build Array Function keeping the indicator outside the for loop and played with indexing but didn't work. Please suggest me an idea how to do it.
    Thanks
    Solved!
    Go to Solution.

    Thank you for your suggestion.Here is my actual application attached . In the first image, a difference in time is evaluated and an enum const of insert into array is passed to the shift register where it takes to Insert element into array phase (Second image). I need to enter the time difference into an array after every loop iteration. Please have a look and could you let me know where I am mislead.
    Attachments:
    Image 1.JPG ‏88 KB
    Image 2.JPG ‏71 KB

  • How to find the defference between elements in an array

    hi guys,
    this is probs an easy one for you but how can you find the diffence between all elements in an array?
    e.g array = 1 2 3 4 5 6
    so difference between 1 and two is 1, difference between 1 and 3 is 2. all the way to trough to the differece between 6 and x is x etc.
    i have been trying to use shift registers but cant quite get it.
    Thanks
    Message Edited by adamkse on 09-02-2009 01:18 AM
    Solved!
    Go to Solution.

    or maybe this:
    Harold Timmis
    [email protected]
    Orlando,Fl
    *Kudos always welcome
    Attachments:
    buildarraysubtract.JPG ‏58 KB

  • Is there a way of determining what element in an array is being clicked on?

    Hi all.  I would like to setup an event to determine what element in an array is being clicked on/hovered over.  I think I tried this before and found it wasn't working due to limitations of LV 7.0.  If this code already exists, it would be great if I don't have to do a scavenger hunt for the solution.
    I think one possibility I nixed was to use the refnum of the elements to determine which one it is.  IIRC, this is not possible because the refnum of the element is for the edit box only.
    The second possiblity is to get the on click event, and somehow determine which element in the array it is.  This doesn't sound too difficult as it should be a simple calculation, but may get in to some hairryness based on if the indicies are visible or not, and if I am using a new or old array with new or old control (calc would change based on boarder size of the controls).  I might just simplify it by removing indicies and using older control set which has minimal boarder size.
    And just for fun, can I force a tool tip to show up?
    Thanks all,
    A
    Using LV7.0 on WinXP.

    blawson wrote:
    Been bitten by LabVIEW wrote:
    I think one possibility I nixed was to use the refnum of the elements to determine which one it is.  IIRC, this is not possible because the refnum of the element is for the edit box only.
    Using LV7.0 on WinXP.
    This is indeed possible, at least in the newer versions I use.
    Take the array refnum from the click event data terminal and get a reference to the array element.  This refers to the element that was clicked, but you do need to work out how to get the index.  My method is to use property nodes to get the screen position and size of the element and the screen position and size of the array, as well as the array's Visible Index property. For each direction, take the quotient of the relative position of the element (account for padding!) over the size of an element.
    I suspect that taking the mouse coords and comparing to the array's sizes in pixels is similar, although I trust my method for events that don't have mouseclicks (what coords does Array:shortcut menu selection(User) return if you used the keyboard?)
    Here's an old version I happened to have open.  I've posted about this before, I suspect I have a clearer version in my gallery.  I use this method in my example code contest entry to work out which square of the chessboard is clicked.
    Thank you for that one!
    I am currently "locked up behind a down-rev fence" (working an old app in an old version) so I had not heard of that.
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • How do you assign multiple values to a single element in an array?

    I'm probably not wording the question right.
    I have an array, let's call it M[], and for each element in the array (we'll say M[1]), I need assign three integers: row, col and value.
    I need to set it up so I can do something like this:
    A.row = M[i].col;
    A[i].col = M[i].row;
    A[i].value = M[i].value;
    The algorithm isn't what I need help with, it's assigning .col, .row and .value to an index of an array.
    Please help if you can.

    You are right. You did not word your question perfectly, but I still think I get what you want.
    First of all: A single element in an array always has exactly one value. No more, no less.
    But that's not a problem. The element in an array is either of a primitive type (boolean, byte, char, short, int, long, float, double) or it's a reference (to a Object, String, MyClass, ...).
    You can simply write a class that holds your three values and create an array of that type:
    public class SomeData {
      public int row;
      public int col;
      public int value;
    // somewhere else:
    SomeData[] a = new SomeData[10];
    a[0] = new SomeData();
    a[0].row = 10;
    a[0].col = 5;
    a[0].value = 42;Note how you only assign a single value to the element (a[0]) itself. All other assignment actually go to fields of the object refered to by that element in the array.
    Also note that in Java types (such as classes, interfaces, ...) should start with a upper-case letter, while variables (local variables, members, parameters) and method names should start with a lower-case letter.
    Edit: I'm getting old ...

  • How can I change the properties of only one element in an array of booleans?

    I'm displaying an array of booleans to my operators, with each boolean in the array representing some system status check.  Some of these checks are critical and some are not, therefore I want some of these booleans to have a different color when in the TRUE state (Red for the critical ones and Yellow for the non-critical ones).  I can change the boolean colors with a property node, but that effects every element in the array.  Is there any way to change a property of an individual element in an array?  I know that I could take the incoming array and break it into two arrays - one for critical and one for non-critical, but this system is replacing an older system and the operators are accustomed to seeing their indicator lights a certain way and I'm trying to replicate what they had exactly.

    Here's what I had in mind
    Of course you can use as many colors as you want.
    Message Edited by altenbach on 12-21-2005 04:53 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    LEDarray.png ‏7 KB
    ColorArray3.vi ‏23 KB

  • In LabVIEW6i, is there a way to make particular elements of an array invisible while the others stay visible (without losing any element's info.)?

    I have an array of clusters. Each cluster pertains to a certain oscilloscope I am controlling. There is another control which specifies which oscilloscopes I have "on".
    If a particular oscilloscope is "on" I want its cluster to be VISIBLE in the array. If a particular oscilloscope is "off" I want its cluster to be INVISIBLE in the array.
    How can I implement this in my program without losing ANY of the info. in my array?

    I suggest to use two arrays; one for user interface holding the ON clusters,
    and one for internal use holding all clusters. The diagram periodically
    updates the internal array with user interface array data.
    By INVISIBLE do you mean "skipped from the array" or displayed as an empty
    placeholder? To hide an OFF cluster you could put in the cluster a flat
    button boolean that is small and transparent when ON and large enough to
    cover the whole cluster area (and other controls) when OFF.
    Jean-Pierre Drolet
    Scientech R&D
    "mcmastal" a écrit dans le message news:
    [email protected]..
    > In LabVIEW6i, is there a way to make particular elements of an array
    > invisible while the others stay visible (without losing any element's
    > info.)?
    >
    > I have an array of clusters. Each cluster pertains to a certain
    > oscilloscope I am controlling. There is another control which
    > specifies which oscilloscopes I have "on".
    > If a particular oscilloscope is "on" I want its cluster to be VISIBLE
    > in the array. If a particular oscilloscope is "off" I want its
    > cluster to be INVISIBLE in the array.
    > How can I implement this in my program without losing ANY of the
    > info. in my array?
    LabVIEW, C'est LabVIEW

  • How to highlight a specific element of an array

    I'm having some trouble selecting which element in an array has key focus. I want to be able to selectively highlight individual elements in an array of strings and set the key focus so that the user can immediately enter the text into that specific element.
    I have been able to get "selection.start" and "selection.end" to work, but when I get a reference to "array element" it always returns a reference to the last element manually clicked. This way, I can only programatically highlight different elements by manually clicking on them, which somewhat defeats the purpose.
    Does anyone know if this is possible, or if I need to move to tables or something else in order to give me this functionality?
    I'm using LV 6.1
    on W2k.
    Thanks
    Shane.
    Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)

    I had the problem that I would like to highlight more than one cell in a 2d array.
    multicolumn listbox is very slow working with large data volumes so I had to use a 2d array instead, but then I lose the possibility to highlight.
    The solution I used was to bundle a LAD and control an put this in the array, takes a bit more coding but works fine. 
    Attachments:
    2d array with marker.vi ‏23 KB

  • How to pass a single element in an array to XSL from BPEL

    In a bpel (2.0) process I have a for-each loop iterating through a list in the original input document.  Within that loop I need to construct an  input document  for a call to a web service based on data in the current node of the list objects I am looping through.
    Constructing the input document via BPEL assign activity copies within the for-each loop is an option but due to the complexity of that document I would prefer to use XSL.  But I don't know how to pass the index information (ie. the for-each counter) into XSL and use it there (and I would prefer not to have to do so, since that will prevent use of the XSL GUI in jdev), so I would prefer to send  the current node of the list as input to XSL instead.
    Is it possible to pass a sub-section of an XML document (e.g. one node in the array) as input into XSL rather than the whole document?  In other words, I would like to send the current array element from the original input document rather than the entire original input document because I will be using the data within that array element to create the web service input document.
    Example:
    <forEach parallel="no" counterName="i"
                         name="ForEachEntry">
                  <startCounterValue>1</startCounterValue>
                  <finalCounterValue>$numTimeEntries</finalCounterValue>
    If I used the BPEL assign activity to populate the input document I would need lots of copies similar to this:
                  <copy>
                      <from>$inputVariable.OteStgTimecardCollection/ns3:OteStgTimecard[1]/ns3:oteStgTimecardDetailCollection/ns3:OteStgTimecardDetail[$i]/ns3:origtransactionreference</from>
                      <to>$InvokeOteDetailAbsenceErrorStatusService_OteAbsenceDetailFailureService_InputVariable.OteAbsenceDetailFailureServiceInput_msg/ns19:OrigTransactionReference</to>
                  </copy>
    I would prefer to send the current list object as an input variable into an XSL transform: 
         $inputVariable.OteStgTimecardCollection/ns3:OteStgTimecard[1]/ns3:oteStgTimecardDetailCollection/ns3:OteStgTimecardDetail[$i]
    Is there syntax in bpel that would do that?
    Thanks

    You need use While Element and use Array like Element[number]
    With While element you iterate <employee> node
    and with Element[number] you can extract information from that node.
    I wrote a BPEL that scan a XML file, the input is:
    <cliente>
            <codigo>01</codigo>
            <nombre>Deiby Mauricio Gomez</nombre>
                    <productos>
                            <producto>
                                    <nombre>Camisa Polo</nombre>
                                    <precio>50</precio>
                            </producto>
                            <producto>
                                    <nombre>Pantalon Lona</nombre>
                                    <precio>100</precio>
                            </producto>
                    </productos>
            </cliente>
            <cliente>
            <codigo>02</codigo>
            <nombre>Julio Cesar Ayapan</nombre>
                    <productos>
                            <producto>
                                    <nombre>Camisa Polo</nombre>
                                    <precio>50</precio>
                            </producto>
                    </productos>
            </cliente>
    In my BPEL I added up all article prices and after that I write to txt file the client and the Total.
    Example:
    Deiby Gomez, 150
    Cesar Ayapan, 50
    My while element is this (Please pay attention in bold words):
      <while name="While1"
               condition="bpws:getVariableData('variable1')&lt;=count(bpws:getVariableData('Receive1_input_files','body','/ns4:clientes/ns4:cliente'))">
          <sequence>
            <assign name="Assign1">
              <copy>
                <from expression="sum(bpws:getVariableData('Receive1_input_files','body','/ns4:clientes/ns4:cliente[number(bpws:getVariableData(&quot;variable1&quot;))]/ns4:productos/ns4:producto/ns4:precio'))"/>
                <to variable="Invoke1_process_InputVariable" part="payload"
                    query="/ns5:process/ns5:cantidad"/>
              </copy>
              <copy>
                <from variable="Receive1_input_files" part="body"
                      query='/ns4:clientes/ns4:cliente[number(bpws:getVariableData("variable1"))]/ns4:codigo'/>
                <to variable="Invoke1_process_InputVariable" part="payload"
                    query="/ns5:process/ns5:id"/>
              </copy>
            </assign>
            <invoke name="Invoke1" inputVariable="Invoke1_process_InputVariable"
                    outputVariable="Invoke1_process_OutputVariable"
                    partnerLink="ValidacionBancos2WS" portType="ns5:BPELProcess1"
                    operation="process" bpelx:invokeAsDetail="no"/>
            <switch name="Switch1">
              <case condition="bpws:getVariableData('Invoke1_process_OutputVariable','payload','/ns5:processResponse/ns5:resultado')='true'">
                <bpelx:annotation>
                  <bpelx:pattern>Si el cliente es aprobado</bpelx:pattern>
                  <bpelx:general>
                    <bpelx:property name="userLabel">Si Aprobado</bpelx:property>
                  </bpelx:general>
                </bpelx:annotation>
                <sequence>
                  <assign name="Assign4">
                    <copy>
                      <from variable="Receive1_input_files" part="body"
                            query='/ns4:clientes/ns4:cliente[number(bpws:getVariableData("variable1"))]/ns4:codigo'/>
                      <to variable="Approved_Write_input" part="body"
                          query="/ns7:clientes/ns7:cliente/ns7:id"/>
                    </copy>
                    <copy>
                      <from variable="Receive1_input_files" part="body"
                            query="/ns4:clientes/ns4:cliente[number(bpws:getVariableData(&quot;variable1&quot;))]/ns4:nombre"/>
                      <to variable="Approved_Write_input" part="body"
                          query="/ns7:clientes/ns7:cliente/ns7:nombre"/>
                    </copy>
                    <copy>
                      <from expression="sum(bpws:getVariableData('Receive1_input_files','body','/ns4:clientes/ns4:cliente[number(bpws:getVariableData(&quot;variable1&quot;))]/ns4:productos/ns4:producto/ns4:precio'))"/>
                      <to variable="Approved_Write_input" part="body"
                          query="/ns7:clientes/ns7:cliente/ns7:total"/>
                    </copy>
                  </assign>
                  <invoke name="Invoke2" inputVariable="Approved_Write_input"
                          partnerLink="fileAdapterWriteApproved"
                          portType="ns6:Write_ptt" operation="Write"
                          bpelx:invokeAsDetail="no"/>
                </sequence>
              </case>
              <otherwise>
                <sequence name="Sequence1">
                  <assign name="Assign5">
                    <copy>
                      <from variable="Receive1_input_files" part="body"
                            query='/ns4:clientes/ns4:cliente[number(bpws:getVariableData("variable1"))]/ns4:codigo'/>
                      <to variable="Rechazados_Write_input" part="body"
                          query="/ns9:clientes/ns9:cliente/ns9:id"/>
                    </copy>
                    <copy>
                      <from variable="Receive1_input_files" part="body"
                            query="/ns4:clientes/ns4:cliente[number(bpws:getVariableData(&quot;variable1&quot;))]/ns4:nombre"/>
                      <to variable="Rechazados_Write_input" part="body"
                          query="/ns9:clientes/ns9:cliente/ns9:nombre"/>
                    </copy>
                    <copy>
                      <from expression="sum(bpws:getVariableData('Receive1_input_files','body','/ns4:clientes/ns4:cliente[number(bpws:getVariableData(&quot;variable1&quot;))]/ns4:productos/ns4:producto/ns4:precio'))"/>
                      <to variable="Rechazados_Write_input" part="body"
                          query="/ns9:clientes/ns9:cliente/ns9:total"/>
                    </copy>
                  </assign>
                  <invoke name="Invoke3"
                          inputVariable="Rechazados_Write_input"
                          partnerLink="fileAdapterWriteRechazados"
                          portType="ns8:Write_ptt" operation="Write"
                          bpelx:invokeAsDetail="no"/>
                </sequence>
              </otherwise>
            </switch>
            <assign name="Assign2">
              <copy>
                <from expression="''"/>
                <to variable="Invoke1_process_InputVariable" part="payload"
                    query="/ns5:process/ns5:id"/>
              </copy>
              <copy>
                <from expression="bpws:getVariableData('variable1')+1"/>
                <to variable="variable1"/>
              </copy>
              <copy>
                <from expression="''"/>
                <to variable="Invoke1_process_InputVariable" part="payload"
                    query="/ns5:process/ns5:cantidad"/>
              </copy>
            </assign>
          </sequence>
        </while>

  • How can I change all Inf elements in an array to a specific value?

    I would like to change all Inf elements in my array to -1. Basically, I am looking for something similar to the range and coerce function, except that I want all values above a certain value to be a specific negative value, rather than go to that value.
    I could use a case structure and go through each element in the array, but I am hoping to find something more efficient.Any ideas?
    Solved!
    Go to Solution.

    P@Anand wrote:
    I would do that in this way.
    Here's a simpler version...
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines
    Attachments:
    Replace in Array.png ‏4 KB

  • I want to create an array that goes into a case structure where each element in the array is an individual case and gets done in order

    I want to create an array that goes into a case structure where each element in the array is an individual case and gets done in order. Any ideas, I've been playing with the idea but have had no luck, is this even possible?

    Hi,
    Please check it out the attached Vi.. Is this you need?
    Sasi.
    Certified LabVIEW Associate Developer
    If you can DREAM it, You can DO it - Walt Disney
    Attachments:
    Event.vi ‏11 KB

  • How to change the properties of individulal elements in an array?

    Hi all,
    I have an array (size is 25) of string and I want to disable and grayout half of them. But how do I do it? How do I change the properties of individual elements in an array? I have tried to use some of the examples given in the discussion forums, but it didint work for the task mentioned above. Anybody would be able to help me with a suitable example that can be specifically used for disable or enable the individual array  elements?
    Dev

    Telemaque wrote:
    The user will see the first half of the string elements filled-in and the lower half grayed-out (to be filled in later).  Make a test VI, play around.
    ... except that all elements "greyed out" with this method contain the default string for the array element (blank by default, but changeable). There is no way to have meaningful, unique text in the greyed out elements.
    I would suggest to use a listbox as control/indicator. Here elements can easily be disabled programmatically.
    LabVIEW Champion . Do more with less code and in less time .

  • How do I determine what element in an array was right clicked on?

    I have an array set up on my front panel. When the user right clicks on an element in that array, I would like them to be able select from 3 different options. I have the shortcut menu working, but I need to know which element in the array the user right clicked on to determine what values to change. How can I get the index of the element?
    Thanks for any help!
    Solved!
    Go to Solution.

    Couldn't you get index values from the array property node?
    Also this doesn't account for if scrollbars are seen or not.  And I usually like to know if my range is valid, because again I could be clicking on a scrollbar, or label and still get the Mouse Down event.
    Here is one I posted a while ago.
    http://forums.ni.com/t5/LabVIEW/Interesting-way-to-detect-array-index-from-mouse-position/m-p/286841...
    Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
    If 10 out of 10 experts in any field say something is bad, you should probably take their opinion seriously.

Maybe you are looking for