• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

MultiDimensional array doesnt work

 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It'd be a lot easier to help if you posted a board configuration that exhibits the error/
 
Dmitri Makovetskiy
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(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
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I noticed that bug earlier this year and made a bug-report about it. I believe that Ulf fixed it.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you have Pawn objects and Bishop objects and Knight objects, etc?
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Do you want ants? Because that's how you get ants. And a tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic