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
posted
0
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.
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
posted
0
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
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
posted
0
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
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.
(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
posted
0
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.
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
posted
0
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
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
posted
0
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
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.
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: 32599
4
posted
0
Do you have Pawn objects and Bishop objects and Knight objects, etc?
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32599
4
posted
0
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
posted
0
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