Jump to content
xisto Community
Sign in to follow this  
eubanksd

Scrutinize My Chess Game! Check out my coding skillz

Recommended Posts

OK, so here's the skinny:

 

Back when AOL was THE place to be online (1998/1999), me and a few friends became internet vandals, using punters and things of that ilk to reek havoc in the chatrooms. Our heyday was short-lived, as punting became virtually impossible with AOL 4.0 and pretty much a thing of the past with later patches/releases. However, 'progs' -- as they were referred to, usually named by their creator with some variation of the words "Hacker," "Elite," and "Toolz" -- did not die. Their golden age had passed, but souls desperate to keep them alive (like us) persevered.

 

Somewhere along the way, we figured out what the MaGuSes and MoNkEGoDs were using to create these (formerly) fun little toys, and entered my life Visual Basic. I was enthralled. I don't know what it was (or is), but the puzzle-solving nature of programming combined with my interest in computers makes programming fun. Certainly not monotonous tedium, as most other complex things are to me. And by complex, I simply mean things that require effort to understand. I'm a simple man.

 

Anyway, I'll fast forward a bit and try to avoid the nostalgic reminiscing from here on out, k?

 

So here I am today, trying to get back into programming as I should have been doing for years. I could have a career by now if I wouldn't have been such an idiot these past few years, but you live and learn. I've been trying to learn Java for the past month or so, and I've certainly made progress coming from nothing to where I'm at now, with only a For Dummies book and the Sun Java Tutorials to guide me.

 

To get to the point: The past few weeks I've been making a pretty straightforward chess game (calling it simple just feels wrong!) and have got the game itself (mechanics/logic) pretty much done with. All except for castling and a couple of stale-mate scenarios, to be precise. I'm not planning on implementing AI and a single-user mode, but instead want to figure out how to make two applets of the game communicate with eachother so two people can use a webpage to play eachother. I've got a ways to go, and actually haven't done anything towards this end other than a little bit of research, but that's mostly because I'm always working; I plan to get busy here soon. In the mean-time, I thought I'd post a link to my game and the source and (hopefully) have some more experienced coders with nothing better to do scrutinize it and maybe give me some pointers, or flame me or whatever. Feedback is feedback ;)

 

So, you can check out http://www.angelfire.com/crazy/eubanks/chess.html just to catch a glimpse of my game and the GUI that needs to be redone. The full Eclipse IDE project can be downloaded from http://forums.xisto.com/no_longer_exists/

 

If you've got some spare time, download the source and check it out, and tell me what you think. After doing some research, I was surprised to find out that the methods I used for the game mechanics were pretty much on point as far as how people usually go about doing it. The only other method I found was the whole bitwise thing, and that's beyond me right now ;)

 

A few things to note for those who check it out:

 

** I've been wondering just what the hell is up with my GameBoard class (which extends JLayeredPane) and why it's layers are so funky. If you notice in the ChessInterface interface, the BACKGROUND layer is 1, the PIECE_LAYOUT layer is 2, and the PIECE_DRAG layer is 0. This is the only way I could keep pieces being dragged from going behind pieces still in the PIECE_LAYOUT layer. If I set PIECE_DRAG layer to 3 (as I would think it should be) the dragged piece will end up behind some of the pieces in the PIECE_LAYOUT layer when they overlap, which boggles my mind.

 

** I've currently got move-switching disabled (in MouseEventHandler.grabPiece method) because I needed to test some things and having to move white>black>white>black made it a P.I.T.A.

 

** You might notice a method or two are straight out of the Sun Java Tutorials (such as the ImageHandler.getImage method).

 

** I've been getting a weird error recently when I terminate the game, but only some of the time for some reason. If you can tell me where this is originating, thanks:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: component argument pData

at sun.awt.windows.Win32SurfaceData.initOps(Native Method)

 

 

Well, that's about it guys. Hope one or two of you out there can share some wisdom with me ;)

Share this post


Link to post
Share on other sites

I took a look at your game (haven't taken a look at the source code though) and was quite impressed. I have a few suggestions to make it better:

Don't allow a piece to capture the King. This is never possible in a real chess game as only a checkmate can end the game.

Allow for en passant ("In passing")- a special pawn move where a pawn can capture a pawn next to it. Click here for the rules.

I'm sure you've thought of this, but... don't let one side move more than once before the other side moves. You could also include a simple undo which would allow a player to take back a move within a mutually acceptable time-limit.

Include ability to make timed games. Speed chess is VERY popular online, so if you include a timer that starts/stops whenever a move is made (you'd have a timer for each player), that would make the game quite seamless.

Allow for multi player online. You could put a list of possible players and allow two players to play against each other. This can get quite tricky, but it would be really cool if you got it to work correctly.

Make the pieces more close to the center of the square. It looks like you just made a little buffer of about 10-20 and calculated the drawing from the bottom. You should draw the pieces from the middle so the pieces are more centralized in the square. This is just a minor GUI change, but I think it is nice to have the pieces centralized (personal preference). You could also make the pawns a little bigger so that every piece is the same size. I've seen this done in many chess games.

These changes are pretty easy to do, except for the multi player one (find a good Socket tutorial if you are confused). I liked your game and it seemed quite professional; just make sure that your code is professional as well. The applet took a little long to load the first time, so perhaps you should try to reduce the amount of code in the startup and build the board and all of that after it is loaded. A simple "Start Game" button would do the trick. Good work, I am impressed.

Share this post


Link to post
Share on other sites

There's just a few features missing:- Pawn promotion- En passant- Turns (ie. each player has their turn instead of someone being allowed to move over and over again)- And of course, capturing the king can't be done

Share this post


Link to post
Share on other sites

some pretty good coding done for a chess game, at least for the most part you got the basic of the basic moves done which is a good thing. I didn't try it out but was castling possible in this version of the game? Other then what was recommend I can't say to much about it since I have really touch a chessboard in a long time so their could be other special moves that could be missing as well.

Share this post


Link to post
Share on other sites

If I remember later when I get home I'll try to find my old chess game code. I actually had to make an online chess game for a university course a couple years back and I got it oooh, lets say 95% functional. As with yours, AI wasn't implemented (it was meant to be a two player implementation of the game) but otherwise mine had most functionality. En Passant I remember was the only thing that was a pain to implement because I forgot about it until the end and tried to implement it in probably the most stupid way possible, but the second way I did it was a piece of cake. Basically in the end I had a functional net based chess game that worked over tcp/ip. The main problems with it had to do with tracking captured pieces and displaying them as they were captured and scores and stuff like that, sort of the bells and whistles rather then the core game itself which basically worked fine.But yea, if I remember later I'll post my code and look at yours a bit, see if I can notice anything good to suggest. Obviously the things mentioned by the others are important to implement otherwise you just have a piece tracking system, not a chess game B)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.