• 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

Draughts Board

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to make a 10x10 Draughts board for my application.
An application that loads and visualizes this notation by putting the pieces on the correct location of the board.

example FEN notations

(W18,24,27,28,K10,K15:B12,16,20,K22,K25,K29)
(W white pieces :B black pieces , K in front of number = KING piece the numbers are the black squares (1-50) where the piece has to be placed)


Now I am a java novice so I could use some pointers as in how to proceed at making the board.

My plan was to add 100 jPanels to jPanel chessBoard. And then use a % algorithm to fill the right squares with a black or white ImageIcon. (the assignment requires me to use these).

Would this be a viable approach?
 
Ranch Hand
Posts: 686
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

harrie harrison wrote:I'm trying to make a 10x10 Draughts board for my application.
An application that loads and visualizes this notation by putting the pieces on the correct location of the board.

example FEN notations

(W18,24,27,28,K10,K15:B12,16,20,K22,K25,K29)
(W white pieces :B black pieces , K in front of number = KING piece the numbers are the black squares (1-50) where the piece has to be placed)


Now I am a java novice so I could use some pointers as in how to proceed at making the board.

My plan was to add 100 jPanels to jPanel chessBoard. And then use a % algorithm to fill the right squares with a black or white ImageIcon. (the assignment requires me to use these).

Would this be a viable approach?



Well, in my chess program my board is a single JPanel, and I move pieces by using a mouseListener on the panel. in mousePressed, e.getX() and e.getY() can be transformed via formula to algebraic chess notation, likewise for mouseReleased.

for drawing the pieces, my Board class has a paint routine that queries an 8x8 char array representing the position to determine what piece to draw, and the same formula I decsribed for my mousePressed and mouseReleased is more or less used in reverse to tell paint where to draw the piece.

Hope that helps, any more questions I'm happy to help out.
 
harrie harrison
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is my first version of the DraughtsBoard. (code below) I used Jlabels with imageicons. This is not optional, i have to use the square .gif icons provided with the assignment.

I wanted to try another solution to see if that was more workable with mouselisteners, this JLabel version gave me trouble with it. (note im not very good with java.. yet:))
So if i could get some advice what would be the easiest solution that'd be great.

Also with this 10x10 grid how can i pinpoint which jLabel i have selected so the piece will be put on the correct spot. I'm sorry if this is a stupid question but as i said im still learning.

Thanks :)

 
Fred Hamilton
Ranch Hand
Posts: 686
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok p.s. I did not notice that this was an assignment, and that you had to use imageicons. I have no idea how I would implement 100 imageicons on a single panel. Maybe a GridLayout manager? ANother possibility is to have the mouseListener on the underlying panel of JFRame rather than a mouseListener for each square. e.getX and e.getY could be used to determine which square is being clicked on.

ANyways, I'm not an expert or anything, this chess program was basically a learning project that has undergone a couple of rewrites. my current solution is based on the following, which in retrospect probably doesn't fit well with your requirements.

1. instead of using ImageIcons for the pieces, I use a combination of graphics commands such as fillArc, fillOval, etc. This makes the idea of using just a single JPanel for the entire board easier to implement.

2. Any time the position changes, the entire board is repainted. I'm not sure this is necessary, but it is simpler to implement. Intuitively and esthetically I'm not thrilled about redrawing the entire board for each move, but it works fine and does not seem to cause any resource issues.

Anyways, first time around I had the same idea as you, ImageIcons and JLabels and separate JPanels for each square, but I was not thrilled with the idea of 64 JPanels. That's just me, I can't really say that my idea is better or worse than yours, I'm sure you can make yours work ok. Does that answer your question?

My program is available online at the link in my signature. You will find there a technical overview of the design that you may benefit from.

Anyways, I enjoy this kind of stuff, so we can discuss more if you like. Do you intend to program your own draughts "engine" to play against? That will be a challenge. A proper engine would use some sort of recursive algorithm to think ahead, and I find that sort of stuff very difficult to wrap my head around.

p.s. if you edit your post to reduce the indents in your code, that should eliminate the need to scroll horizontally to read the posts in the thread.


p.s.s. here is my paint method, which should give you an idea of how the board is set up.
 
harrie harrison
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your tips, but I really have to use those .gifs for the pieces and squares provided. As i said its part of the assignment.
So I'm gonna have to stick with JLabels

And my board wont be a game yet, its just a FEN viewer for now. An application that can read FEN notations from a file and loads those into diagrams.
I might turn it into a real game when I am ready for it but that time isnt here yet ;D.

Your game is nice i think, making algorithms for moves seems very hard to me. So for a few weeks work its quite nice already.


Anyway if anyone has some practical tips its greatly appreciated.
 
Fred Hamilton
Ranch Hand
Posts: 686
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah, I didn't notice you had to use the gifs until later. I have updated my previous post with a couple of ideas

p.s. not sure where you got the idea of a couple of weeks work. It took me much longer to figure all that stuff out.
 
Every plan is a little cooler if you have a blimp. And a tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic