Please turn on javascript in your browser to play chess.
Developers Forum

Developers Forum

  1. 22 Aug '04 15:43
    Hey this is aimed at Russ but would welcome comment from any one with thoughts...

    I am currently teaching myself Java, and thought an interesting long term goal would to make a java application that works as a chess database. I see it as you entering games you've played either by moving the pieces and ecording it or by importing a PGN such as is provided by RHP or from notes you might make on OTB games. Initialy it would have functionality similar to the anaylse board function here, but I'd like to add the ability to search trhough your games for board postions that are the same. Maye add functionality for multiple databases (My Games, My speed Gambes, Famous Games etc)

    Any way, thats my ambitious project. I know there's many chess programs out there already with simlar functionality but I think I have some good idea's and mainly want to do it to improve my own programming....

    So, as I set out my question for now is about how information is best stored, here's the thoughts I've had...

    For each game you can

    1)store a PGN and when a user wants to analyse that game calculate the board postions on the fly. The major disadvantage to this seems that if you want to skip 10 moves ahead you have to calculate all the moves in between, which seems processor wasteful.

    2)store a PGN and when a user loads a game calculate a corrosponding FEN for each move and so you can jump to points in the game with no processing involved. Advantage here is you only need calculate once when you load the game then can move swiftly to different moves.

    3) store a PGN and corosponding FEN for each move thus when a game is loaded you can just move between FEN's, Disadvantage is you store a lot of redundant data.

    I think 2's the best but 1 may well work well to, I'm not sure how long all that calculating will take, it's pretty simple so I doubt it's much.


    The second question is the link between game ID and the actuual game infomation.

    1)I could store the names, dates, events, Etc in a file with a game ID for each game, then have a file with that game name that stores the PGN data.

    2) I could store it all in one file. This seems more elgant but I've not learnt to much about reading/writing to files yet so not sure how easy ether option is.

    also how would either these idea's effect searching for similar postions? How would this be tied into the FEN/PGN debate. To search for a same postion you need to check to see if 2 games have and identical FEN, if you are only storing PGN data this could be intensive. What about diffenrent files for you different databases


    This is obviously a key point, if i don't get it right it may be hard to add the functionality I'm eventually going to want to add. Any advice/idea's would be fantastic.
  2. 22 Aug '04 16:04 / 2 edits
    I would recommend idea number 3. Each board position is given by its modified FEN string. I say modified, because the FEN includes information such as the number of moves since the last pawn movement and/or piece capture. Obviously, if a move is determined to be best for a position where only 5 moves have been made since the last pawn movement and/or piece capture, then this same move is probably best for FENs where the number of pawn movemements and/or piece captures is 6, 7, 8 up to a certain value.

    I would use a reduced FEN as the primary key. The FEN would have its number of moves information stripped and this would become a minimum and maximum range value. So, a given FEN would hit a certain record in the database iff its FEN matched your reduced FEN key and the number of moved was within the given range.

    I suggest using either an SQL or an ISAM table to store this information. The particular implementation will decide whether the informartion is stored in a single file or multiple files.

    The PGN information is irrelevant for your purposes as a given position may be encountered in any number of game move sequences. It is irrelevant how you arrived at a position. In all cases, the very same moves will be considiered best.

    -Ray.
  3. 24 Aug '04 02:32
    Yep, I think your probably right (I think that's how russ does it looking at the source for the analyse board... there is a Fen array there..)

    Spent a happy 5 hours producing a chess board, the tiles change color as the mouse passes over like the analyse board feature and there place holders for the pieces (I "borrowed" your piece gif's Russ, hope ya don't mind! Will make my own if ya do but i'm no artist and I only have paint (does not fo gifs)). Have not tired to make the piece movable and it's 3:30am so enough for now me thinks
  4. Standard member thire
    Xebite
    24 Aug '04 16:34
    Hi Simonm!
    I don't know too much about Java, but I've tried to realize a little project myself, but I was unsuccessfull.
    Perhaps you've heard about Java MIDP, Java for mobile devices. I wanted to make a little programm that lets you import "over the air" your chessgames from RHP (some xml-Data has to be made ready by Russ) try moves on your mobile phone (or PDA) and send it to RHP.
    If you are experiened and motived enough to make such a "third party project" - many players here would wellcome that!
    There are some threads in the developperforum around this theme, check them out if you want!
    a bit off topic, I know, but perhaps you are interested!
    th

    PS: Allthough I know that you know that there are many chessdatabases around in the net, I want to name "Scid" as a very good and free one!
  5. 24 Aug '04 20:45
    Hey, I have looked at most of the threads here, but the mobile thing is way beyond me for the moment... I've only just started to learn!
  6. 26 Aug '04 02:39 / 1 edit
    Originally posted by Simonm
    Yep, I think your probably right (I think that's how russ does it looking at the source for the analyse board... there is a Fen array there..)

    Spent a happy 5 hours producing a chess board, the tiles change color as the mouse passes over ...[text shortened]... the piece movable and it's 3:30am so enough for now me thinks
    Not sure if any ones keeping up to date but if i keep posting maybe Russ will come give some words of wisdom...hint hint!

    I have made a fully working chess board, behaves the same as the anaylse board feature (just the board, the input to set the piece positions is a FEN but the only way to change this FEN is to change it in the source code at the moment!), will add the ability to move through a game over the next couple of days... need to learn how to handle file input/output first though!


    One thing thats got me thinking if you do turn up Russ...
    My board is set up to go through the FEN in such a way that black is at the top and white is at the bottom. I can't quite work out how to get it to do it the other way round (so white is at the top, this of course involves flipping my grid references round the edge of the board too)... any idea's on an easy way to do this...? any one...?
  7. Standard member thire
    Xebite
    26 Aug '04 16:22
    Originally posted by Simonm
    Hey, I have looked at most of the threads here, but the mobile thing is way beyond me for the moment... I've only just started to learn!
    I'd it shoudn't be too difficult. JAVA MIDP is JAVA as normal, but some things are missing - this could make things even easier!
    To see what it does, have a look at . There you find all the existing classes.
    Just get the KToolbar and start beeing a Midlet-developper! It should be fun for you! There are many tutorial and starting guides out there which may help you. Search for keywords like: Java, mobile edition, MIDP, Midlet...
    If you were able to create something like the boardanalysis, an import (via some xml-data) of a game into a Midlet should be feasable for you
    Have you read http://www.redhotpawn.com/board/showthread.php?id=12844 ?
    I just want to encourage you!
    th
  8. 26 Aug '04 17:59
    Originally posted by Simonm
    My board is set up to go through the FEN in such a way that black is at the top and white is at the bottom. I can't quite work out how to get it to do it the other way round (so white is at the top, this of course involves flipping my grid references round the edge of the board too)... any idea's on an easy way to do this...? any one...?
    Just think about how do you map your chessboard onto the screen array. You obviously start at one corner of the board and work your way to the opposite end, correct? Well, start at the opposite end and work your way back to the starting corner when the board should be flipped.

    -Ray.
  9. Standard member thire
    Xebite
    26 Aug '04 18:56
    ...and I forgot one thing:
    if you want to transform your software to a Midlet, you should just change the graphical user interface (which is different from the Swing or ATW classes) and not the "core" classes.
    just some thoughts...
    th

    PS: In my previous post I forgot to fill in the URL for the javadoc:http://www.wmlscript.it/j2me/api20/index.html
  10. 26 Aug '04 19:19
    Originally posted by rgoudie
    Just think about how do you map your chessboard onto the screen array. You obviously start at one corner of the board and work your way to the opposite end, correct? Well, start at the opposite end and work your way back to the starting corner when the board should be flipped.

    -Ray.
    I'm such a fool! Yeah that works, add a little bit to make the frame back to front as well so the letters and numbers are in the right place and I now have a flippable board!

    thanks for the encouragement thire, maybe Ill have a look at it once i got this project working.
  11. 30 Aug '04 23:35 / 1 edit
    Another update and a beg of help from Russ (or any one else!)

    I've been developing so far using text files equivilent to PGN export format, except that I tag on a full FEN list for each move, taken from this site, after the PGN list. This has a allowed me to get to the stage where I can read a file and display the game for perusement with out having to attemp the extremely nasty task of writting an algorithm that can read PGN's and make FENs

    So, tomorrow, I start this epic task... I've been hunting around the internet for an open source one but can not find one. This is a pretty fundimental part of the program but also one thats been done a 1000 times before. All the code up to this point is entirely my own but given how time consuming I expect this to be I'd really be happy to use some one esles and credit them!!

    So if any body has some insight please let me know. Even just basic theory of it would be nice (so far my idea is to test the length of the single move then work on it appropriately e.g. length = 2 can only be e4, c5 etc...a pawn move...) but there quite a lot of possiblities!


    EDIT - as for how i store the data i don't think is going to be so important...the program will load the whole database once when you start it and then each game will be easily a quickly accessable. ONly question on sotrage is how quickly it loads up a Databse with/without FEN's and how much extra space it takes but i can make that descion when i've had a chance to mess about with some larger files (only got 3 games in my PGN/FEN file at the moment!)...thinking about it i could even leave it up to the user to decide which method they like if it makes a big difference...
  12. 04 Sep '04 22:11 / 3 edits
    It seems to me that parsing PGN shouldn't be too difficult.
    Ignoring annotations and omitting to describe the tags, the grammar is roughly
    <PGN> ::== <tags><moves><lastmove><result>
    <moves> ::== <nothing> | <moves><move>
    <move> ::== <movenumber><halfmove><halfmove>
    <movenumber> ::== "one or more digits followed by a period and space"
    <halfmove> ::== <what><where><space>|<castling><check><space>
    <what> ::== <piece><fromfile><fromrank><takes>
    <where> ::== <tosquare><promotion><check>
    <piece> ::== <nothing> | "R" | "N" | "B" | "Q" | "K"
    <fromfile> ::== <nothing> | "lowercase letter"
    <fromrank> ::== <nothing> | "digit"
    <takes> ::== <nothing> | "x"
    <tosquare> ::== "lowercase letter" "digit"
    <promotion> ::== <nothing> | "=" <piece>
    <check> ::== <nothing> | "+" | "#"
    <castling> ::== "O-O" | "O-O-O"
    <lastmove> ::== <nothing> | <movenumber><halfmove>
    <result> ::== "*"|"1-0"|"1/2-1/2"|"0-1"
    You could define a Java class for each token, extending a common Token class.

    The trickiest bit is parsing <what> because all its components can be <nothing>. I suggest you parse <halfmove> from right to left, that is, once you have a string that might be "e4 " or "Nh5xf6+ ", you say "is there a + or #; is there a pawn promotion; there has to be a to-square; is this a capture; is there a from-rank; is there a from-file; is there a piece-letter (or is this a pawn move)".

    I hope this is useful. If you want more direct advice, you can send me an email address via a PM, if you like.
  13. 04 Sep '04 22:56
    Googling around, I found this link:

    http://www-cgi.cs.cmu.edu/afs/cs/project/ ai-repository/ai/areas/games/chess/san/0.html
    (You will need to take out the space that I have inserted to avoid the WORD TOO LONG message.)

    The SAN Kit is a freeware ANSI C source programming toolkit for chess
    software authors and researchers. It consists of some twelve thousand
    lines of portable code that includes everything needed to write a
    chess-playing program except a search function and an evaluation
    function. A set of public, portable standards for move notation
    (SAN), position notation (FEN), and game notation are described and
    implemented.
  14. 05 Sep '04 18:23
    Thanks for the input, am working away at it at the moment....

    Am starting a new job tomorrow though so am not going to be able to give too much time to the project for a bit...
  15. 25 Sep '04 18:16
    Just a little update if any one was following this...

    I've had a very hectic 3 weeks in my new job so not too much done. However I am about 80% done in translating SAN moves (SAN is an individaul half move in a PGN, e.g. e4 or 0-0 etc) At the moment it only accepts back row pieces in the format Qe4e5 (i.e. not Qe5). This makes coding alot easier because i don't have to deal with ambiguities. This is ok for now as RHP export PGN is in this format (thankfully) and RHP comaptibility is my main concern. As time goes by i'll make it more robust.

    Fianly it's been mentioned here and i've seen it in the Site idea's forum to make a client. I believe Russ set upt the XML so a client can communicate with it. As of yet I know nothing about this area of coding but it's something I'm very keen to learn so I may incorperate this functonality into the program at some time...