Drag and Drop Chess

A new version is now available in Post #1 in this thread.

A game is now defined as ‘game name’ and ‘game start date’.
Dates are in ISO format yyyy-mm-dd
Example:
Rocky v Bullwinkle 1959-01-02
is a different game to
Rocky v Bullwinkle 1959-01-03
Resolution of difference is one (1) day.

Running short on screen real-estate particularly vertically at 1024x768:
To that end a Shortcut Menu Popup has been added.
Right click to activate. (A game must be selected to use it.)
1. To allow changing the board square colours and file properties.
2. To export the selected game as an email attachment. (Preferred)
3. To export the selected game as an email body. (Almost useless?)
4. To import a game file and either create a new game or update an old game.
(Within the header of the import file is both the game name and game start date. That defines if a new game is created or an old game is updated. It would be a good idea not to modify the import file at all.)

Configuration for file properties currently includes.
1. Setting the default file folder for export and import.
2. Setting the default file extension for export and import. (Problematic)
3. To reset to defaults (C:\ and TXT)

‘Colour picker’, ‘browse for folder’ and ‘browse for file’ have been included to make it a little easier to export and import games.

Game stepping buttons, Back and Next, now ‘Auto Repeat’ even though I didn’t tell them they should do it.
I guess they are happy in the service so I’ll just let them go for it. :)
(Which is another way of saying I don’t know how to stop them. :D )

The move validation code is still only partially done. However, in this version the validation stubs have been pushed out to a standard module, mdlValidation, rather than totally contained within the image Class module. The people at UA, who are writing the validation code, are doing so in a standard module, slowly. :( In this version each validation subroutine receives udtPieceArgs for the current piece and should return arguments to the piece by reference…no function return is required or allowed.

This is a 32 bit application and has not been tested as a 64 bit application.

Global error handling is turned off but it should not be needed. :rolleyes:

Plus everything else I forgot to mention.

Apart from that it’s been a big rewrite and cleanup.
There is now enough code in it to choke a horse.

Have fun…

Chris.
 
Chris

can you clarify the status that the app has reached?

is the download in post 1, up to date -as it isnt validating moves at present.
 
Dave.

My latest version is the one in post #1 in this thread.
I overwrite that version with the latest because that means there is only one version of mine.
The caption of the Form contains the version number and date as in
Version 2.0 (2011-01-11)
The date is in ISO format.
It is the only version, it has a version number and it has a version date.


As I said in my last post, post #21, “The move validation code is still only partially done.”

I am not writing validation code because other people at UA are way ahead of me and it would be a duplication of effort.

I am writing drag and drop, configuration, export/import, shortcut menus…that sort of code not validation code.

I have written validation ‘stubs’, callable routines if you like, so that it will (should) be easier to include the validation code that others may write.


Why don’t you write your own validation code and test it with the upload in post #1.
Try picking what you think is the simplest piece to validate and write the code for that piece.

Here is the validation stub I have written for the Pawn in module mdlValidation: -
Code:
Private Sub ValidatePawn(ByRef udtArgs As udtPieceArgs)
    Dim strBackgroundPiece As String
    
    If (conHandleErrors) Then On Error GoTo ErrorHandler

    strBackgroundPiece = GetBackgroundPiece(udtArgs)

    With udtArgs
        Select Case True
            Case .strSquareStart = .strSquareEnd
                .blnMoveIsValid = False
        
            Case strBackgroundPiece = ""
                .blnMoveIsValid = True
                
            Case Left(strBackgroundPiece, 1) <> Left(.strPieceName, 1)
                .blnMoveIsValid = True
        
        End Select
    End With

ExitProcedure:
    Exit Sub

ErrorHandler:
    DisplayError "ValidatePawn", conModuleName
    Resume ExitProcedure

End Sub
All you need to do is set .blnMoveIsValid to True or False for each or any condition you see fit.
That way .blnMoveIsValid will be sent back to the clsImage Class for processing.
The Class module should then accept or reject the move of that piece.

Chris.
 
Chris - thanks for the update - after posting, i downloaded the app, and reread everything.

To be honest, I think understanding the mechanics of the whole app takes a bit of doing. eg I haven't yet found the representation of the board/position yet!

I started trying to do my own implementation of a move validity check - and I found even that pretty tough. I wonder how they REALLY do it, in decent chess code.

I thought maybe to build a matrix of legal moves for the selected piece - but even that was tricky, and I gave up after a while, for the moment.

-------------------
ok - moves

am i right in thinking that you are saving the screen pixel position of the start and finish square, rather than the chess move itself.

the function GetGridSquaRereference does return a true chess notation reference (e2, d3, etc) - but this doesn't seem to be value that gets saved.

so if these is no logical representation of the position anywhere (eg an array(64) of string), or an array(8,8) of string)- then it seems pretty hard to validate any move.

or am I missing something obvious.

[I was actually messing around with an array(8,8) of long to store the board (a numeric value for each piece), and an array(8,8) of boolean to use to store legal moves]
 
Last edited:
Dave.

>>Chris - thanks for the update - after posting, i downloaded the app, and reread everything.<<
Why did you not download it and reread everything before posting?

There is no function called GetGridSquaRereference in my code.
There is not even the word Rereference in my code.
There are only two ‘reference’ and they are in comments.
There is no ‘screen pixel position of the start and finish square’.

Do you not understand how much extra work is involved in trying to answer typos and assumptions?

I’ve been working on this for about two weeks and it’s complicated enough without having to make a guess as to what you refer.

Be succinct, be correct and I’ll try to answer your questions.

>>[I was actually messing around with an array(8,8) of long to store the board (a numeric value for each piece), and an array(8,8) of boolean to use to store legal moves]<<
Fine, if that’s what you want to do then just go for it.
But what numbers will you use for each piece?
And, if you do change it, then you will be up for a total rewrite.

So what I would suggest to you is to head down, backside up and start writing it.
Meaning, actually produce something that others can see and test.

And, by the way, there was a bug in my code in version 2.0.
Pieces which were captured, I use the word Seized in my code because it has two less letters and formats better using Tab when exporting a game, did not have their event handlers turned off. That raised an error within the Class MouseDown event on Seized pieces. That has been fixed and I added a blnPieceSeized variable for each piece and properties to set or get it.

So, the current version is now 2.1. (2011-01-12)

Chris.
 
Hey Chris, given that you're still posting, I take it that you don't have the river lapping at your ankles currently :)
 
Last edited:
Chris has not been on line for a good 24 hours, so that doesn't look good, so I must apologies for my previous rather flippant post :o
 
Dave.

>>Chris - thanks for the update - after posting, i downloaded the app, and reread everything.<<
Why did you not download it and reread everything before posting?

There is no function called GetGridSquaRereference in my code.
There is not even the word Rereference in my code.
There are only two ‘reference’ and they are in comments.
There is no ‘screen pixel position of the start and finish square’.

Do you not understand how much extra work is involved in trying to answer typos and assumptions?

I’ve been working on this for about two weeks and it’s complicated enough without having to make a guess as to what you refer.

Be succinct, be correct and I’ll try to answer your questions.

>>[I was actually messing around with an array(8,8) of long to store the board (a numeric value for each piece), and an array(8,8) of boolean to use to store legal moves]<<
Fine, if that’s what you want to do then just go for it.
But what numbers will you use for each piece?
And, if you do change it, then you will be up for a total rewrite.

So what I would suggest to you is to head down, backside up and start writing it.
Meaning, actually produce something that others can see and test.

And, by the way, there was a bug in my code in version 2.0.
Pieces which were captured, I use the word Seized in my code because it has two less letters and formats better using Tab when exporting a game, did not have their event handlers turned off. That raised an error within the Class MouseDown event on Seized pieces. That has been fixed and I added a blnPieceSeized variable for each piece and properties to set or get it.

So, the current version is now 2.1. (2011-01-12)

Chris.


Chris

I just rechecked, and the function I noted was "GetGridSquareName" which returns the square in chess notation format, I think.

All I was saying is that I found it difficult to understand how the programme worked, and I decided I didn't have the time (and maybe the skills) to really investigate it. But a cursory examination seemed to indicate that a move was detected and stored merely by examining the screen.

So if there is no representation of the board as (say) some array of size 64 - then I struggle to understand how moves can be validated.

--------------
As I say, I started to write some move validation code. My idea was to store an array of booleans, to take the starting piece, and then set the boolean array to true for all legal moves for the selected piece - which required

a) evaluate the potential moves for the piece style, moving away from the start square.
b) stop evaluation at the point where the path is blocked (note that this needs slightly different code for captures, as opposed to blockages by same colour pieces)
c) ignoring issues like castling, en passant, and promotions temporarily.

[and of course i needed another array to store the position - and after some independent thought decided, as I later saw that the drag and drop did, that all the pieces should be indivdiually distinguished. ie the KN and QN are 2 different pieces, and each P is also a different piece.]

I THEN thought an added difficulty was that for the potential move, you would also need to ensure that the piece wasn't pinned, so that the move didn't leave the mover in check.

And decided that it was all too difficult to spend a lot of time on.

Hence the general comment that I wondered exactly how chess engines actually did all this (and to go further, how they are able to examine and evaluate a tree of moves)


------------
I am not decrying the work involved so far - its a fantastic amount of work, and deeply impressive. I had just expected to see a move table showing something like

1. e2-e4 e7-e5
2. g1-f3 b8-c6

as a starting point, and couldn't find one!

etc.
 
John.

For the moment the high water levels have past.
I have not been affected at all but there are many thousands of people that are.

I did not answer in this thread because Rabbie asked the same question in this thread: -
http://www.access-programmers.co.uk/forums/showthread.php?t=203588

What Brisbane faces now is a big and long cleanup.
Not mentioned on the media so far is the need to discharge an enormous volume of water from the flood mitigation dams. This, of course, can’t be done at a high rate because it would only exasperate the situation. However, it must be done because full flood mitigation dams are useless due to their lack of remaining storage capacity. In order to dump the water I suspect they will need to vary the discharge flow rate so that they discharge maximum at low tide. The main reason the river peaked at about 0.6 metres below expected was that they slowed the discharge rate at high tide. In doing so they saved around 8000 homes from being flooded.

However, they must dump about half capacity in order to create a buffer. If we got hit by more rain, and there’s a low depression east of Queensland, then the place could be in far more of a mess than it is at the moment. So even if no one is talking about it at the moment that discharge from the dams is vital and will inevitably slow the river dropping its level.

Chris.
 
Dave.

Do you see what I mean; GetGridSquareName <> GetGridSquaRereference.

What I’ve been complaining about with your posts for some time is that you do not take care.
It only creates more work for others to try and figure out what you mean.

I’m not going to get into some discussion about how this thing works or should work.
If someone wants to do it their way then let them do it their way.

Now, the validation of piece moves is to me a luxury. When we play chess on a physical board with physical pieces we do not have move validation, apart from our opponent saying ‘you can’t do that’. So, it’s a luxury we can live without. We can still use it as it stands and play how we want. We can even email games for our opponent to make their move.

I may write my own move validation but, then again, I may not.

So you just do what you want to do, I can’t help you do it the way you want to do it.

Chris.
 
John.

For the moment the high water levels have past.
I have not been affected at all but there are many thousands of people that are.

I did not answer in this thread because Rabbie asked the same question in this thread: -
http://www.access-programmers.co.uk/forums/showthread.php?t=203588

...
Missed that, as I rarely visit that part of the forum :o

We've got almost 24 hour coverage of the situation down here, so glad to hear that you have escaped, physically, unscathed so far. I can well image that the coming months will not be easy.
 
Dave.

Do you see what I mean; GetGridSquareName <> GetGridSquaRereference.

What I’ve been complaining about with your posts for some time is that you do not take care. It only creates more work for others to try and figure out what you mean.
That's a bit petty. I knew exactly what function Dave was talking about and I've only briefly looked at your code. I've always found Dave's posts constructive and positive and I think his contributions here are very worthwhile.

So why exactly have you posted this here? Personally I find your post interesting, particularly along the vein Dave is discussing. I've also found your code very interesting/inspiring. So why be so dismissive about any discussion beyond your own code? If you feel this way, why didn't you just post in the sample databases section and be done?

Chris

PS belated happy birthday :)
 
Last edited:
Chris.

>>That's a bit petty.<<
You may think so but I don’t. When people do not post clearly and concisely their lack of care and attention only makes more work for the person trying to answer.

>>So why exactly have you posted this here?<<
I wanted to leave it open so that people could test it and make comments, both good and bad, about what they find. I was also hoping that the two people at UA who have written some of the validation code may want to use their validation code within it. That’s part of the reason for trying to write fairly simple validation stubs. Written the way it is it should mean that they, the people at UA, or anyone else for that matter, would have a standard way to do it. Meaning that each piece has its own validation stub and it receives the full compliment of arguments for that piece. It then only requires the stub to pass back True or False based on the validity of the move and the interface handles it from there on.

That is why it was written that way and also why it was posted here. If I posted it in the sample database forum that forum would get locked. People would not have a common place to answer and I would have to wait each time I increased the version number. So it’s about logistics. The logistics of people being able to ‘cut in’ their version of validation code, the logistics of having a common thread for doing so and the logistics of me being able to manage version increases.

>>So why be so dismissive about any discussion beyond your own code?<<
I’m only being ‘dismissive’ about making structural changes to the code. It was written in a specific way for the reasons as stated above. If I try to follow someone else’s method of achieving the incorporation of validation code it would never get finished. I could end up in a vicious circle trying to accommodate other people’s ideas of how their code should be interfaced.

But no one else on this site has posted any code whatsoever and so I might just write my own.

Dave seems to be taking the engineer’s way of doing things. That is, if you don’t understand it then redesign it. An 8x8 grid of numbers may very well be a good idea and if I had to rewrite it I may very well have gone that way. But it would not be a simple 1 to 64 numbering system. If people have done their own research they may have found a better way to number the squares: -
http://en.wikipedia.org/wiki/ICCF_numeric_notation

In post #25 I asked Dave a question: -
>>But what numbers will you use for each piece?<<
And I got no answer but the reason I asked the question should now be obvious.

If Dave is at a point where that question can’t be answered then his attempt is still in its infancy, either that or Dave didn’t read the question.
So the way I see it is that I would be starting anew, with a person who has not made a start and is not likely to read questions or answer them accurately.

Now if Dave wants to start his own version of Chess then that’s fine by me. But I’m not going to get involved again with someone else’s project from the ground up. Many years ago I co-wrote a database with someone from Switzerland. Just the fact of the time difference meant it was months not weeks. Throw in the uncertainty and lack of clarity in communication and my answer is no.

But that should not stop other people answering Dave or helping him with his project.

As for this project then if people want to help they are free to do so. However, I would ask them to comply with the boundaries of the stubs as written so far else we’ll get in a hell of a mess. If they need more or different arguments passed to the stubs I will try to accommodate their requests.

For example, the current version I’m writing passes a string variable for Control Tip Text. If a stub rejects a move the Control Tip Text is updated with the reason for the rejection. So if a piece snaps back to its pickup point then the reason is available in its Control Tip Text.

But what I do not want is for this to simply become a wish list by people who are not prepared to actually write testable code. Someone is eventually going to ask for the board and pieces in Braille and I don’t particularly feel up to it. :rolleyes:

Chris.
 
It was raining last weekend and since UA don't seem to have got there yet I thought I'd give the validation a shot (see attached - well commented).

Just add the two classes (clsAnalyse ans clsPiece) and change the MoveIsValid function to the code attached.

It validates all chess moves I'm aware of including castling and en passant. It also tests for check. E.P was quite easy. Castling was more tedious due to the need to test castling through check or out of check. Testing for previous moves was quite easy due to ChrisO’s move storage.

A clsAnalyse instance is used to grab the position and analyse a move against the position.

Reading the board is done by examining the controls on the form and using GetSquareName().

The validation is done in two steps. The first step tests the move to see if it can legally move to the destination square (testMove). The second step tests the subsequent position to see if the friendly king is in check.

The second step is achieved by iterating through all the enemy pieces on the board and testing them to see if they can legally move to the friendly king’s square (so we use testMove again:D). Note that for this second stage we have to have the ability to test all types of pieces even though we are only testing the one move in the first stage. So writing individual code for each piece case is not appropriate – hence I didn’t use the stubs – sorry.

In testMove, I decided to test against characteristics of a move e.g. isDiagonal, isHorizontal, Distance etc. This makes it easier to sense check and helped stop me going insane.

I really don’t know if I’ve managed to trap every illegal move. Testing is arduous to say the least.

Chris
 

Attachments

Hi stopher, looking good.

It recognises En passant to be a legal move but the captured enemy pawn remains in play. There also seems to be no mechanism to deal with the promotion of a pawn at this point.

As a suggestion would it be possible for the king's square to be highlighted (say in red) when he is put in check, moved into check or exposed to check?
 
A new version is now available in Post #1 in this thread.

UA HAS COLLAPSED, AWF MARCHES ON. :D

This version includes…

Drag and drop of pieces.
Lockout of the non-player.
Castling.
En passant capture.
Promotion.
(Click to select spare Queen, Bishop, Knight or Rook. {8 spare pieces for each.})
(A consequence of the rules implies that there could be 9 Queens of the same colour on the board and that is allowed for.)
(There is still a sticky problem here but at this stage I don’t even know how to describe it.)
Move validation for all pieces.
Moves which place the King in check detected and highlighted.
Move which would place or leave its own King in check rejected returned to starting position.
Control Tip Text information for piece after move or rejection of move.
Automatic replay of a game with pause/manual/continue.
Manual stepping of a game, first, back, next and last.
Shortcut menu, right click, which includes links to rules of game.
(The rules by which it was designed.)
Configuration of board colours, checking colours, directory names and step times.
Export and import of selected game.

I have had a quick look at the demo in post #35 but, to do it credit, it deserves more time on my part.

Thanks again to Chris and John for the time taken to test these things; it ain’t an easy thing to test. :)

Chris.
 
Looking good Chris :)

Although I did get a 2465 Run Time error somehow? See the attached screen shot.
 

Attachments

... Then when I created a new game, I got a Run time error 91 :eek: so I guess something got out of kilter after the previous error.
 
G’day John.

The attachment in post #38 looks to be in binary, so I can’t read it.

The project is running with error handling turned off. After an error it would not be appropriate to continue but it is done that way at the moment just to let the crash happen on the line which caused it.

If you get an error on a ‘clean game’ please post the actual error and the line on which it occurred.

Thanks again for the testing.

Regards,
Chris.
 

Users who are viewing this thread

Back
Top Bottom