Thread: The puzzle again...Swapping elements of 2D array

  1. #16
    Registered User
    Join Date
    Nov 2008
    Posts
    31
    i need help rewriting a few of the functions because i was curious about the different ways, specifically the last function and the "domove" function, any hints or help?

  2. #17
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Could you be more specific? In what way do you need help? How do you need it to be changed? The one thing I would definitely change are the names of your variables.

  3. #18
    Registered User
    Join Date
    Nov 2008
    Posts
    31
    Yes i plan on doing that, well i figure i cant really change the swap function becasue that is pretty legit. I just need help changing the others i mentioned around cause i also have this program to complete. is there any way to do those two that i mentioned a different way such as a different if statement for the last one?

  4. #19
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I should mention there is a difference between optimal amounts of coding and optimal amounts of CPU cycles. If you are asking "how do I change my condition to a loop" I should remind you that the way you have been writing isn't necessarily the cleanest looking, but they are the least amount of ticks.

  5. #20
    Registered User
    Join Date
    Nov 2008
    Posts
    31
    ok so your saying the if statement can be "cleaner" by using a loop ?

  6. #21
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I am saying you have things written to be fast. Which in my opinion is good. I am more of a speed over neatness kind of fella.

  7. #22
    Registered User
    Join Date
    Nov 2008
    Posts
    31
    ok, what other way could i possible do it?

  8. #23
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Loops. I refuse to help someone produce code I find to be less than optimal. So you can wait for someone kind explainer of alternate methods to jump into this one (matsp).

  9. #24
    Registered User
    Join Date
    Nov 2008
    Posts
    31
    ok thank you..what about the do move function?

  10. #25
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I don't see a problem with the doMove() function. Assuming the logic works properly (I didn't check that).

  11. #26
    Registered User
    Join Date
    Nov 2008
    Posts
    31
    ok im trying not to use the same code as the other one, any more possible hints?

  12. #27
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    The big massive if at the bottom can be improved a bit, in my opinion. There's not much here: find the chosen tile, find the blank, swap if legal. That's what a move is in this game, so you're going to have to more-or-less follow that pattern.

  13. #28
    Registered User
    Join Date
    Nov 2008
    Posts
    31
    ok thanks , what other variable names can i use

  14. #29
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by cprogrammer22 View Post
    ok thanks , what other variable names can i use
    Ones that make sense (that is, whose names match what they are).

  15. #30
    Registered User
    Join Date
    Nov 2008
    Posts
    31
    ok is it necessary to initialize all my variables to 0 in function 1 or the others?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Swapping rows in a 2D array
    By bassist11 in forum C Programming
    Replies: 5
    Last Post: 03-11-2010, 12:04 PM
  2. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  3. 2D array becoming "deallocaded"
    By Aaron M in forum C Programming
    Replies: 2
    Last Post: 09-23-2006, 07:53 AM
  4. Merge sort please
    By vasanth in forum C Programming
    Replies: 2
    Last Post: 11-09-2003, 12:09 PM
  5. 2d Array access by other classes
    By deaths_seraphim in forum C++ Programming
    Replies: 1
    Last Post: 10-02-2001, 08:05 AM