Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Checkers Code Fails to Work for Jumps

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have attempted to code checkers for a school project, but I am unable to code a method for multiple jumps. In my current version, I have attempted to find the possible moves in a one piece radius, add those moves to an ArrayList known as mainList, and use recursion to find all possible moves. Afterward, for each possible final destination piece, the program adds the pieces that need to be reset to "NO" to an ArrayList known as sublist, which is one of the attributes of each piece. However, my jumps do not work.

I have attempted to debug why my program is not removing the correct pieces, and in the image with a trial run posted below, the underlined "RP" with coordinates of (4,3) is not reset, and instead, the program thinks that the piece with coordinates of (3,2) should be reset. Apparently, the program is trying to reset the final destination piece rather than the middle piece. What am I missing that is causing it to do this?

Note: Some of the code has been removed to fit character count.

image.PNG
[Thumbnail for image.PNG]
Trial Run
 
boe john
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I resolved the issue with the pieces not resetting, but my multi jump still does not work.
 
Sheriff
Posts: 7113
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch, boe john!

Debugging a class with variable names like x1, y2, etc. is very difficult for the author and nearly impossible for anyone else!  If you're using an IDE, use its Rename function and slowly name variable something that is describes their function.  x5 might be renamed pieceColorPrompt, for instance.

I know this doesn't solve your problem directly, but you will find that this process makes debugging much easier.

Some other tips:
  • Don't write if (something == true), just write if (something)
  • Class names should begin with an uppercase letter
  • Don't call a method recursively when you don't need recursion (example: line 52)
  •  
    Tongue wrestling. It's not what you think. And here, take this tiny ad. You'll need it.
    Free, earth friendly heat - from the CodeRanch trailboss
    https://www.kickstarter.com/projects/paulwheaton/free-heat
    reply
      Bookmark Topic Watch Topic
    • New Topic