aspose file tools*
The moose likes Java in General and the fly likes  MultiDimensional array doesnt work Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark " MultiDimensional array doesnt work" Watch " MultiDimensional array doesnt work" New topic
Author

MultiDimensional array doesnt work

Dmitri Makovetskiy
Ranch Hand

Joined: Jun 21, 2010
Posts: 128
i want the array to run from one place in diagnol to another place in the array.

i set the arguments. here they are



why the a is returned always as 0 and not being counted even once?
(i tested, there are nulls only from point to point)
sorry for the messy code
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Instead of apologizing for the messy code, why not just format it in a reasonable way? Almost every IDE will do this for you at the push of a button. Here's what it looks like in a way that makes it intelligible.Unfortunately, without knowing what the code is trying to do, or with some idea of what should be in pieces, or knowing what the start value of a is, it's difficult to answer your question. I'm also a little confused by the usage of both bishopNorthEast and bishopSouthEast--I don't know if this is a cut-and-paste error, or if it's meaningful in some way.
Dmitri Makovetskiy
Ranch Hand

Joined: Jun 21, 2010
Posts: 128
David Newton wrote:Instead of apologizing for the messy code, why not just format it in a reasonable way? Almost every IDE will do this for you at the push of a button. Here's what it looks like in a way that makes it intelligible.Unfortunately, without knowing what the code is trying to do, or with some idea of what should be in pieces, or knowing what the start value of a is, it's difficult to answer your question. I'm also a little confused by the usage of both bishopNorthEast and bishopSouthEast--I don't know if this is a cut-and-paste error, or if it's meaningful in some way.




newton. i think i got it to work. the problem is shown in the code.


>
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Glad you got it worked out, although I don't see how that code would compile because of the "><" constructs.

It sure seems like the code would be a good candidate for refactoring since there are four "chunks" that do essentially the same thing: is the goal to see if there are any pieces along any of the directions the bishop can move?

It also seems like determining the possible moves would be a prime candidate for moving into the Bishop subclass, no?
Dmitri Makovetskiy
Ranch Hand

Joined: Jun 21, 2010
Posts: 128
David Newton wrote:Glad you got it worked out, although I don't see how that code would compile because of the "><" constructs.

It sure seems like the code would be a good candidate for refactoring since there are four "chunks" that do essentially the same thing: is the goal to see if there are any pieces along any of the directions the bishop can move?

It also seems like determining the possible moves would be a prime candidate for moving into the Bishop subclass, no?


The bishop moves legally, i tested the code many times. but what the code fails to do is adhere to this law

if(pieces[rowStart+b][columnStart+b]==nulll......

it keeps on counting even if there are objects ..as if the whole array was one big null. that does frustrate it. and it is beyond my comperhension of java to see why it happens..henceforth i posted it here.so someone could tell me
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

It'd be a lot easier to help if you posted a board configuration that exhibits the error/
Dmitri Makovetskiy
Ranch Hand

Joined: Jun 21, 2010
Posts: 128
David Newton wrote:It'd be a lot easier to help if you posted a board configuration that exhibits the error/



it doesnt show any error. the bishop piece simple moves to any position i ask it too and the game continues.
so for example,

bishop from 1,1 to 8,8. it will be there. and it doesnt listen to the rule .. if(pieces[][]==null... it considers everything as null
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I think you misunderstood me: an "error" is anything that doesn't work the way you want it to. What I asked for was a board configuration that exhibits the error--rather than making us reverse engineer *everything*, provide an SSCCE for us to examine. It's difficult enough to read your code without having to also figure out how to create a scenario that causes the undesired behavior.
Dmitri Makovetskiy
Ranch Hand

Joined: Jun 21, 2010
Posts: 128
David Newton wrote:I think you misunderstood me: an "error" is anything that doesn't work the way you want it to. What I asked for was a board configuration that exhibits the error--rather than making us reverse engineer *everything*, provide an SSCCE for us to examine. It's difficult enough to read your code without having to also figure out how to create a scenario that causes the undesired behavior.



newton, i can give you the code after i debugged it. it has a different array (of strings) and 4 variables to change to move the pieces (rowstart, columnstart.....), other than that everything else is the same. all the algorithm
is copied and pasted....



i think conceptually something happens that prevents my if test to be executed. i dont know how to reach teh sscce code
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Are you trying to work on the rook, or the bishop? In other words, post the exact code you're trying to debug: when you're trying to get help from people, do as much as you possible can for them.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

(And, as I mentioned, the bishop code you posted will not compile: rather than force me to guess your intent, better to post working code.)
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

(And I can't tell if you have a cut-and-paste error in your code, or if it's what you really mean: perhaps posting an explanation of your algorithm would also be useful to the dwindling number of people that are still trying to help.)
Dmitri Makovetskiy
Ranch Hand

Joined: Jun 21, 2010
Posts: 128
David Newton wrote:(And I can't tell if you have a cut-and-paste error in your code, or if it's what you really mean: perhaps posting an explanation of your algorithm would also be useful to the dwindling number of people that are still trying to help.)


The bishop and the rook algorithm is based on the same principle they both dont work on the same principle


here is bishops debugged code. works..

just feed new numbers and see for yourself. you could also add or remove the nulls from an array.


>
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

If the debugged bishop code works, what's the issue? The rook code?

You're confusing on several levels... And please, *please* format your code.
Dmitri Makovetskiy
Ranch Hand

Joined: Jun 21, 2010
Posts: 128
David Newton wrote:If the debugged bishop code works, what's the issue? The rook code?

You're confusing on several levels... And please, *please* format your code.



The debugg works. cause i put everything in a class. but in my original code i put the things in one method and call it from the main. that kind of order makes it fail..
it doesnt pay attention to the objects.. it counts every piece as a null
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

The code above will not compile--do you understand that? You need to post the exact code that doesn't work the way you expect, you need to state how you want your code to work, and so on.
Dmitri Makovetskiy
Ranch Hand

Joined: Jun 21, 2010
Posts: 128
David Newton wrote:The code above will not compile--do you understand that? You need to post the exact code that doesn't work the way you expect, you need to state how you want your code to work, and so on.



my code does compile. i used it for 3 days, i feed it with different values.


try to see whats the problem when you copy it and paste it. may be you are missing a bracket
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Maybe I'm missing a bracket? Really?

That aside:Tell me how that compiles. (Hint: it doesn't. It's on line 185 above, and in the other three blocks as well.)

Why won't you format your code nicely?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38412
    
  23
David Newton wrote:Maybe I'm missing a bracket? Really?

That aside:Tell me how that compiles. (Hint: it doesn't. It's on line 185 above, and in the other three blocks as well.)

Why won't you format your code nicely?
I think there is a bug on the Ranch which produces >< every now and again when you are supposed to have only one of those characters.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

I noticed that bug earlier this year and made a bug-report about it. I believe that Ulf fixed it.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Bug or not (and I can believe it is), the OP needs to at least tell us which character is the correct one.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38412
    
  23
Do you have Pawn objects and Bishop objects and Knight objects, etc?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38412
    
  23
I have probably made the code legibility even worse by getting rid of some of the long lines so as to avoid horizontal scroll-bars.
Dmitri Makovetskiy
Ranch Hand

Joined: Jun 21, 2010
Posts: 128
Campbell Ritchie wrote:Do you have Pawn objects and Bishop objects and Knight objects, etc?


i do have all that!!!

here is my array of pieces in the main:

The class that is called ChessInterface






ChessPiece is the name of my abstract class:




all the algorithm of hte chess piece collsion is inside the method in the rook (or bishop class, they are quite similar..but different enough)



what intrigues me. how that pieces array behaves? may be it doesnt work cause of jumbing between classes and methods\| cause i have an if condition that counts or is aware of whether there is an object or condition
 
jQuery in Action, 2nd edition
 
subject: MultiDimensional array doesnt work