• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with chessboard location method  RSS feed

 
William Pen
Greenhorn
Posts: 7
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm writing a location method for a chess board, my approach:



When I create an object of the class, such as Location loc = new Location ("d8") and then print the location, it is always (0,0). (Shouldn't be, d8 would be 0,3)

Any ideas? Thanks for reading and thanks in advance for advice/help.
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah. Never use == for value comparison. St‌ring is a reference type, so == compares references, not values.

Anyway, you can do this without looping through arrays. char is an integral type that you can perform arithmetic on. All you need is String.charAt() and some maths.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!