Drag and Drop Chess

ChrisO

Registered User.
Local time
Today, 19:26
Joined
Apr 30, 2003
Messages
3,202
Drag and Drop Chess in Access…

A little background: -
At Utter Access a thread was started with regard to playing Chess in Access.
A request, suggestion, was made by the site owner for drag and drop for the pieces.
He gave an example by me which was a rewrite I did of a Russian program I found a few years ago.
No one had taken up the challenge, so here it is.

Access 2003.
1024 x 768 and above.
No references required.
Tested with English, French and German regional settings.

Graphics by CyberCow.
http://www.utteraccess.com/forum/index.php?app=portal

Original table design by Dane.
http://www.utteraccess.com/forum/index.php?app=portal

Start of thread at Utter Access.
http://www.utteraccess.com/forum/Chess-Board-Access-t1958050.html

Official request for drag and drop help by ghubbell (site owner) in post #21
http://www.utteraccess.com/forum/Chess-Board-Access-t1958050.html&st=20

Drag/drop, validation and GUI by ChrisO.
http://www.access-programmers.co.uk/forums/

Testing by Chris(stopher) and John Big Booty.
http://www.access-programmers.co.uk/forums/


The latest version includes…

Drag and drop of pieces.
Lockout of the non-player.
Castling.
En passant capture.
Promotion.
Move validation for all pieces.
Check highlighted for King and checking piece(s).
Moves which would place or leave its own King in check are rejected and returned to its 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.

Right click shortcut menu with: -
Resignation of side in play.
Configuration; board colours, checking colours, directory, extension and times for replay.
Import game from file.
Export game to file.
Export to email body.
Export to email attachment.
Links to rules of chess; Castling, En passant capture and Promotion.


Thanks again to all those who helped with the testing, particularly Chris(stopher) who put a lot of hard work into it.


Note:
The attachment has now been placed in the Sample Databases Forum and removed from this thread.

Regards,
Chris.
 
Last edited:
not looked, but does the cpu "play", or is this just to manage legal moves?

I wrote a draughts/checkers program in Pascal years ago for my degree project. I had very inefficient structures I am sure, but i used a minimax algorithm to prune the tree of available moves, searched depthwise for quiescent positions (ie no captures), and came up with a static position evaluation algorithm.

It only examined 10s or 100s of positions a second (from memory) - but it did manage to solve FIRST POSITION (a standard checkers position) - and I was pleased at the time!

I used a similar algorithm to write a connect-4 programme.

but I gave up on Chess as too hard!
 
An interesting project.

I do however seem to have done something to the board, by making (completely invalid) moves with the White King, which does not reset when a new game is created.
 

Attachments

OK, thanks John.

I have seen that before and thought I fixed it.
Looks like three white squares have reset from yellow to black.

Can you reproduce it or remember how you did it?

Oh! XP or Windows 7?

Chris.
 
Just had a bit of a play and it seems to happen only on games after the initial game, and only when you try and make an illegal opening move with the White King. I can't recall the sequence I used to get the effect in the screen shot, but I do recall that it happened on subsequent games not all on the same game.

Using XP, I'll see if I can reproduce in Vista when I get home.
 
Thanks, John, your description was correct.

When a Black square piece is dropped on a White square it saved the Black square colour for replacement when the Yellow was removed. When a new game was created it used the same Black square colour to replace the White colour making the White square Black.

The problem boiled down to using the old arguments in the Image Class for the new game.
The latest version reinitializes the Image Class when a new game is created or when a stored game is loaded.

New attachment version 1.1 (2011-Jan-06) in post #1.

Thanks again,
Chris.
 
That seems to have fixed it :) I'll be interested to see the move validation when it's implemented.
 
Thanks, John, and glad it fixed it.

>>I'll be interested to see the move validation when it's implemented.<< Indeed, so would I.
I have seen some of it but I would not like to simply (?) incorporate it into this version without his permission. Besides, I will not know if he has finished it until he says so. It would only cause more work to continually go back and make changes so, as far as I’m concerned, it’s up to him to say… go for it.

The logic of a piece move seems primarily quite simple in that the validity of the move only involves knowing what piece is being moved. At its simplest it is a finite set of moves which remains static throughout the game.

However, where things become complicated would seem to be in the dynamics of the game. For example, a King when Castling needs to be aware of moving from, through and to a position of check. That’s a dynamic of the game and quite simply I don’t know how to program it. There is also the Pawn that might be promoted but to what and under what circumstances. That too is a dynamic of the game and I do not know how to program it.

So it’s up to Dane, or other people, to write the validation for each piece individually and in such a way as to return True if valid and False if not. It’s actually a big job and writing the code to display the piece moves becomes rather insignificant.

Chris.
 
An interesting project, at least :p
 
I suspect that the logic behind validating a move to be far more straight forward than the logic required to determine the optimal move :D
 
I’m glad you think that, John, because you have just been elected to do so. :D
 
when you try to validate all moves don't forget the king.
It will make things complex, as any move even if it's a move that can be done will not be valid if it put the king in a Chess situation. this apply both to moves of the king itself and any other piece.
 
In all seriousness though, the problem has piqued my curiosity somewhat.
 
In all seriousness though, the problem has piqued my curiosity somewhat.

what - the optimal move?

the things to research here are

minimax algorithm
quiescence
static position evaluation


personally, i would think this is very difficiult to achieve in VBA, although nothing quite seems to be (and many posters here are extremely resourceful) - the problem is that the easiest way is to construct and walk a tree with a recursive algorithm , and this isn't possible in vba - becuase you don't have a pointer type


effectively you need to examine a starting position

then make a move

examine that position

follow this down a tree of further moves, until you reach the limit of the analysis

then go back to earlier positions and examine alternative moves.

the technique is easier to accomplish with a tree structure - and I think it would be very difficult without.

It's similar to examining an XML file without a MSXML library, if you like.
 

Users who are viewing this thread

Back
Top Bottom