File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programming Diversions and the fly likes Can you beat this game? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Other » Programming Diversions
Bookmark "Can you beat this game?" Watch "Can you beat this game?" New topic
Author

Can you beat this game?

J Eisses
Greenhorn

Joined: Sep 05, 2007
Posts: 3
Hello all,

I started programming in java 3 days ago and after reading the tutorials on java.sun.com I tried to remake a small puzzle game I saw on a forum a few years back.
Clicky (Applet)

You have to click on the black tiles in the applet and can only make moves like the horse in chess.

Source:
http://www.chainswarriors.com/SmallGame.java
http://www.chainswarriors.com/Board.java

PS. Feel free to comment on the code, this is my first java creation ever, I could use it
[ September 07, 2007: Message edited by: Jesse Eisses ]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
I haven't really looked at the code, but it looks like you've done pretty well for only 3 days of Java.

I assume the goal is to land on every square exactly once, like a Knight's Tour? In that case it is provably impossible to solve this board. If you color in all the suqares in a checkerboard pattern, with the middle starting square black, then there are 24 black squares and 21 white squares. But a knight's move will always go from black to white or white to black. If it starts on black and makes 44 moves, it will reach 23 black squares and 22 white squares. There's no possible way to cover them all, for the given board.

If you enhance this to use other board shapes, may I suggest adding a reset key? And maybe an "undo" key. That would make it much easier to try different tactics without having to reload everything.


"I'm not back." - Bill Harding, Twister
J Eisses
Greenhorn

Joined: Sep 05, 2007
Posts: 3
Thanks for the comment .

Sorry for the bad explanation. The goal is to get an high as possible score, you can only touch each tile once and you're score will raise by 1 everytime you hit a tile.
I've managed to get a score of 41 (only 3 open squares left). I allready thought it would be impossible to totally complete the board, but maybe it'll be possible to get just one open square left.

Anyways, I think it can still be a quite fun challenge to 'nearly' complete the board. I'll create an undo and reset function later today, and maybe add some more boards if I can think of any good ones.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Yes, I can fill all but 3 squares too. At that point, if we color them in as a black and white checkerboard with the center square black, there are 21 black squares and 21 white squares filled, and the remaining squares are all white. (I misspoke earlier - if the center square is black, then there are 24 white and 21 black, not 24 black and 21 white.) The last move was on a white square, and so the next must be on a black square - but there are no black squares remaining. Thus, having 3 squares remaining is the best possible score for this game.

If getting the highest score is the goal, perhaps you could add a box labeled Score: which displays the current score. That would make the goal a bit clearer, I think.
J Eisses
Greenhorn

Joined: Sep 05, 2007
Posts: 3
Thanks for the advice, I'm going to update the game when I got some time. I'm thinking about creating a few levels, for each level you'll need a certain score to complete, maybe I'll also add a time limit of some sort.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can you beat this game?