Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Chess applet  (Read 4878 times)
0 Members and 1 Guest are viewing this topic.
Offline mike_bike_kite

Senior Devvie


Medals: 1
Projects: 2



« Posted 2012-02-28 13:44:09 »

I thought I'd better show my chess program to you guys, it's called Fun Chess. It plays ok at the moment (1800 ELO) but I'm trying to get it up to master level - this might be difficult as this is a lot stronger than I am. You can change the board, pieces, background as in most programs. The default level is an average club player. There are also various coaching options available. Any feedback welcome.



Mike

Arcade swarm
Board Chess - Checkers - Othello
Offline ReBirth
« Reply #1 - Posted 2012-02-28 13:54:33 »

It's very interesting.

Just one issue, I played white for start. In the middle game I clicked undo (just cheat) but the white got taken to AI and I played black. And then a processor 1.6GHZ doesn't seem enough to play.

Offline mike_bike_kite

Senior Devvie


Medals: 1
Projects: 2



« Reply #2 - Posted 2012-02-28 14:10:11 »

Undo takes back one move (yours or the opponents). Just click it twice to remove the computers last move and your own. It offers a bit more flexibility to do it this way (ie if you want to change sides) rather than always taking back 2 half moves (or ply) at a time.

Not sure why 1.6 Ghz processor not enough. I play it on a small netbook with an atom processor and it seems to play reasonably well. Perhaps it depends on what else you have running. Can I ask why you say this - was it playing bad moves or were the graphics messed up?

Mike

Arcade swarm
Board Chess - Checkers - Othello
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ReBirth
« Reply #3 - Posted 2012-02-28 14:16:16 »

There is no bad move. Graphics did well. Just it took more than promised 5sec for AI to made a turn, then a flashing message said my pc is too slow.

Offline mike_bike_kite

Senior Devvie


Medals: 1
Projects: 2



« Reply #4 - Posted 2012-02-28 16:45:17 »

My apologies then. I did have an issue where someone would play the program and complain that a move was very poor but then it turned out that they were doing video editing (or similar) in the background and the program didn't really have a chance to search very deep at all. As a compromise it always searches at least so many moves at a given depth (I think 2) and then displays that message before quitting the search. Hopefully it doesn't wait too long before playing. If it always shows that message and you're doing nothing else then I might change the set up.

Arcade swarm
Board Chess - Checkers - Othello
Offline ReBirth
« Reply #5 - Posted 2012-02-29 23:53:24 »

What AI do you use? searching, reasoning or learning?

Offline mike_bike_kite

Senior Devvie


Medals: 1
Projects: 2



« Reply #6 - Posted 2012-03-01 09:12:24 »

What AI do you use? searching, reasoning or learning?
Searching: I search moves to a given depth. I then extend that depth if there are still captures at the end of the search. Alpha beta pruning is used to cut down the size of the search tree. Ordering the moves using MVV/LVA ordering makes the alpha beta pruning more efficient. Killer moves (moves that were pretty good before) are also tried before anything else. Iterative deepening is then used to search deeper and deeper until the time runs out. For the first move the scores returned by the previous search dictate the order in which they are tried. I also use stand pat evaluations to decide whether it's worth even trying given exchanges. A small opening book provides some variation at the start of the game. Board evaluation covers most things including material, piece positioning and pawn structure.

I aim to include null moves and transposition tables in the next month and perhaps IID. Sadly I also need to fix a few bugs. The program still only plays like a moderately strong club player and in all honesty I was hoping to get it to master level by now. One thing I have learnt is that it's surprisingly difficult writing a decent chess program. I guess it will just be a work in progress for some considerable time to come.

Learning won't work simply because there are too many positions to learn - I did once write a learning OXO program which played well but obviously there are infinitely less positions to learn in OXO than in chess. Reasoning sounds like a good idea (that's how we play ourselves) but getting computers to think in the same way we do has never been achieved yet so doing this (and getting it to play chess) might be a fair challenge.

Arcade swarm
Board Chess - Checkers - Othello
Offline philfrei
« Reply #7 - Posted 2012-03-01 20:05:58 »

Awesome accomplishment! 1800 elo is pretty darn strong.

I played a game and promptly went down two pawns (at my peak I was 1804 UCSF rating), but managed an opposite bishops ending. This gave me an opportunity to test out your end game play and "drawn game" provisions. I pretty much sat my King in the center and moved my Bishop back and forth between two squares for about a hundred moves.

I *think* you algorithm avoided repeating a position 3 times, but am not certain, and that it also avoided the rule where there has to be a pawn advance in fifty moves, but it sure seemed to lose its sense of direction once I staked out a passive, defensive position. I think it had a won game, though there are a few challenges to opposite Bishops.

Then, it froze on move 145.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
Exception in thread "Thread-12" java.lang.ArrayIndexOutOfBoundsException: 300
   at chess.findNextMove(chess.java:5248)
   at chess.findNextMove(chess.java:5365)
   at chess.findNextMove(chess.java:5365)
   at chess.findNextMove(chess.java:5365)
   at chess.findNextMove(chess.java:5365)
   at chess.findNextMove(chess.java:5365)
   at chess.findNextMove(chess.java:5365)
   at chess.findNextMove(chess.java:5365)
   at chess.findNextMove(chess.java:5365)
   at chess.findNextMove(chess.java:5365)
   at chess.findNextMove(chess.java:5365)
   at chess.findNextMove(chess.java:5076)
   at chess.playCompMove(chess.java:5708)
   at chess.run(chess.java:7073)
   at java.lang.Thread.run(Unknown Source)

Maybe you need to provide for more moves?

I was able to copy the move history, if that is of any help.

1. e4 d5 2. exd5 Qxd5 3. Nf3 Bg4 4. Be2 Bxf3 5. Bxf3 Qe6+ 6. Qe2 Qxe2+ 7. Bxe2 Nd7 8. d4 e5 9. dxe5 Nxe5 10. Bf4 Bd6 11. Nc3 Nf6 12. O-O-O O-O 13. Nb5 Nd3+ 14. Rxd3 Bxf4+ 15. Kb1 Ne4 16. Rd4 Nxf2 17. Rf1 Bxh2 18. Rd7 Ne4 19. Bc4 Nf6 20. Re7 c6 21. Nc3 b5 22. Bd3 Bd6 23. Re2 Rf8d8 24. Ne4 Nxe4 25. Bxe4 Ra8c8 26. Re2f2 Re8 27. Bd3 Re7 28. Re2 Rc8e8 29. Rxe7 Rxe7 30. c3 h6 31. Kc2 Re8 32. a4 a6 33. Rd1 Bg3 34. axb5 cxb5 35. Ra1 Re6 36. c4 Rc6 37. b3 Rf6 38. Rf1 bxc4 39. Bxc4 Rxf1 40. Bxf1 a5 41. Kd3 g6 42. Ke4 h5 43. Bc4 Bd6 44. Kd5 Bg3 45. Kc6 Bf2 46. Kd7 Kg7 47. Kd6 Bg3+ 48. Kd5 Be1 49. Kd6 Bd2 50.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d5 Bc3 137. Bc4 Bb2 138. Bd5 Ba1 139. Bc4 Bc3 140. Bd5 Be1 141. Bc4 Bd2 142. Bd5 Bb4 143. Bc4 Bc5 144. Bd5 Bb6 145. Bc4

Can the move history be set so that the most recent moves are always on display?

One other very modest tip: when you first init the game, go ahead and play a "silent" version of your sound effect. Then, when the first move occurs, the first sound won't lag so much.

Very impressive!!

And welcome to JGO! I remember meeting you at JavaRanch.


"It's after the end of the world! Don't you know that yet?"
Offline mike_bike_kite

Senior Devvie


Medals: 1
Projects: 2



« Reply #8 - Posted 2012-03-01 21:45:06 »

Hi Phil, nice to see you here.

I believe the error you had is simply because it ran out space in the move array - I never play such long games and so I never met the bug. I'll fix it later tomorrow. If you try it again in a day or so and just paste in those moves then you can continue where you left off but it looks like a draw to me even though it's 2 pawns up. You did very well to get a draw (I usually loose against it these days).

I'll try to implement your suggestions but I'm not sure how to play a sound with out it playing. I'll have to look in those damn manuals  Cry

Mike

Arcade swarm
Board Chess - Checkers - Othello
Offline philfrei
« Reply #9 - Posted 2012-03-01 22:24:09 »

A work-around, if you can't find a way to change volume, is to record a short amount of  silence and make that your first cue.

Manuals? What are you using for sound? I'm afraid I'm only familiar with the javax.sound.sampled library at this point.

"It's after the end of the world! Don't you know that yet?"
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline pjt33
« Reply #10 - Posted 2012-03-01 22:40:19 »

A work-around, if you can't find a way to change volume, is to record a short amount of  silence and make that your first cue.
Why record silence? It's pretty easy to generate on-the-fly.
Offline mike_bike_kite

Senior Devvie


Medals: 1
Projects: 2



« Reply #11 - Posted 2012-03-01 23:53:16 »

Sound is done with the following with the sounds held in the jar.
         URL url = this.getClass().getClassLoader().getResource( name );
         AudioInputStream audioIn = AudioSystem.getAudioInputStream(url);

         // Get a sound clip resource.
         Clip clip = AudioSystem.getClip();

         // Open audio clip and load samples from the audio input stream.
         clip.open(audioIn);

         clip.start();

Arcade swarm
Board Chess - Checkers - Othello
Offline philfrei
« Reply #12 - Posted 2012-03-02 20:41:33 »

A work-around, if you can't find a way to change volume, is to record a short amount of  silence and make that your first cue.
Why record silence? It's pretty easy to generate on-the-fly.
@pjt33 Agreed, if you know your way around with sounds. If he doesn't know how to change volume, generating on-the-fly might also be a bit of a lift. But maybe you know of a nifty way to do this? (I'd be writing zeroes to a SourceDataLine, I think.)

By the way, if the end of the existing Clip is silent, one could also move to just before the end of the clip before starting, via setFramePosition() or setMicrosecondPosition(), and prime the sound system that way. (Theoretical--I haven't actually done this yet, but it should work.)

@Mike: do you know that you only have to load and open the clip once, right? Replays are done by resetting to the start of the clip (using either of above methods) before using the start() method again. That will cue off more quickly than reloading the Clip from memory for each playback (something just about everyone does until the light-bulb goes off).
http://docs.oracle.com/javase/tutorial/sound/playing.html

This is SO minor, compared to what already works in your program. I feel bad taking up so much space with this discussion.

BTW: have you seen the articles by Larry Kaufman on how the point values of pieces varies during the course of the game or depending upon piece match ups? He alludes to this knowledge in "The Chess Advantage in Black and White"--but I can't recall whether he cites the articles there. He has done computer analysis of games to test or verify point values used in evaluation of positions. Perhaps incorporating this knowledge would be the key to getting your program up to Master level, more so than adding plies or increasing processing speed.

"It's after the end of the world! Don't you know that yet?"
Offline mike_bike_kite

Senior Devvie


Medals: 1
Projects: 2



« Reply #13 - Posted 2012-03-02 22:04:28 »

Sound : is the issue to do with getting the sound code into place or just loading up a particular sound for the first time? From your solutions it looks like the former but the latter seems more obvious. I'll try a blank sound first as this is the easiest to fit in plus your other suggestions guys.

Piece values : the piece values change all the time. Bishops pairs count more, knights are better in blocked positions, the pawns are very dependant on overall structure. Each time I make a change I seem to make a little progress in certain situations but never enough to really leap forwards. It is gaining strength by approx 50 ELO points each month but maintaining this progress is getting harder now.

Settings : I'm trying to incorporate a memory of what settings each user has ie level, board appearance, coaching preferences and the state of the current game. At the moment I'm just saving everything against a users IP address but the user can supply a name - type in "I am fred" and it will load fred's settings and current game on any computer - not sure if this is even slightly intuitive though  Undecided. When I've done this I'll do another release which will include the larger move array and whatever I can manage with the sounds.

Any other suggestions very welcome.

Mike

Arcade swarm
Board Chess - Checkers - Othello
Pages: [1]
  ignore  |  Print  
 
 

 
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!