This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sorting out Strings from a filereader

 
harrie harrison
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to make an application that can read positions from a Draughts game and update it in a diagram (10x10 board).
Im running into a lot of problems and I would appreciate any help a lot.

the positions are stored in this format.

W7,13,50:B25,30,45 C. Blankenaar (1898)

everything after W goes in the white pieces textual display (jTextframe)
everything after B goes in the black pieces textual display (jTextframe)
the last part goes in another seperate jTextframe

I'm reading the files with a buffered filereader, and the next step is to separate the lines and put the positions in the correct display.
I would appreciate if it you could give me any pointers how to do this.

Thanks in advance.
 
Ankit Garg
Sheriff
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Harrie, please change your display name to meet the javaranch naming policy.

It doesn't seem to be a tough task to me. The method must parse the file using regex and then set the values to the text frames.

You can use a regex like W.*?: to get white coordinates and then use the split method to split the coordinates from commas. Same can be done for black coordinates. I hope I have understood the problem correctly ...
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think regex is probably overkill: the positions are delimited by the first space. Perhaps just grabbing up to the space, splitting on colon, then splitting on commas would be sufficient (taking the color character into account).
 
Gavin Tranter
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pretty random I know and possible off topic. But I thought Draughts was played on an 8 x8 board just like Chess.

I would parse each line into an object and put that into Lists, one for white one for black and one for other, that way you can release the FileHandle pretty quick.

I think regex would be over kill for this, just use the standard String methods.

You should be able to send each List to the required dispaly element.
 
harrie harrison
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the advices, I figured out a way to do it. It aint pretty but it works.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic