SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Site Related Forums
 Article Discussion
 Article: SQLChess - A tutorial on thinking in sets
 New Topic  Reply to Topic
 Printer Friendly
Previous Page
Author Previous Topic Topic Next Topic
Page: of 2

Koji Matsumura
Posting Yak Master

141 Posts

Posted - 05/18/2007 :  00:55:39  Show Profile  Reply with Quote
How about

Select FromSquare, ToSquare
from AllMoves
where ABS(X-Xi) = ABS(Y-Yi)

for the Bishop?
Go to Top of Page

byrmol
Shed Building SQL Farmer

Australia
1591 Posts

Posted - 05/18/2007 :  01:25:25  Show Profile  Reply with Quote
quote:

Select FromSquare, ToSquare
from AllMoves
where ABS(X-Xi) = ABS(Y-Yi)



That seems to work very nicely! Cheers!


DavidM

Production is just another testing cycle
Go to Top of Page

jasmine2501
Starting Member

1 Posts

Posted - 05/21/2007 :  18:36:30  Show Profile  Visit jasmine2501's Homepage  Send jasmine2501 a Yahoo! Message  Reply with Quote
Very good article! You missed the 'castle' move of the King to the other side. You have the one side defined, but the other side is different.

Edited by - jasmine2501 on 05/21/2007 18:40:17
Go to Top of Page

byrmol
Shed Building SQL Farmer

Australia
1591 Posts

Posted - 05/21/2007 :  18:49:32  Show Profile  Reply with Quote
quote:

Your criteria for the King is not correct. It allows for a move of two spaces in a straight line.



Hmmm.... I can't replicate that behaviour jasmine2501
I ran this query and found the only "2 space" moves are the castling actions..


Select FromSquare, ToSquare, abs(X-Xi) as XMovement,  abs(Y-Yi) as YMovement
from dbo.AllMoves
where (ABS(X - Xi) < 2 AND  ABS(Y - Yi)  < 2 
OR (Y = Yi AND X = 5 AND ABS(X-Xi) = 2 AND Y in (1,8)))
--Movements greater than 1
AND (abs(X-Xi) > 1 OR abs(Y-Yi) > 1)


I would appreciate any information you can give.

quote:

Still, this is a very good article!


Thank you.

DavidM

Production is just another testing cycle
Go to Top of Page

DeveloperJim
Starting Member

2 Posts

Posted - 05/22/2007 :  18:43:14  Show Profile  Reply with Quote
quote:
Originally posted by Koji Matsumura

How about

Select FromSquare, ToSquare
from AllMoves
where ABS(X-Xi) = ABS(Y-Yi)

for the Bishop?



This seems to be the correct query for the Bishop. the query supplied in the article includes incorrect moves such as a2 -> g6 (unless i'm missing something)

total valid moves should equal 560, not 736

Jim
Go to Top of Page

byrmol
Shed Building SQL Farmer

Australia
1591 Posts

Posted - 05/22/2007 :  19:05:05  Show Profile  Reply with Quote
quote:

This seems to be the correct query for the Bishop. the query supplied in the article includes incorrect moves such as a2 -> g6 (unless i'm missing something)

total valid moves should equal 560, not 736



Ahh shit! Spot on Jim!

The beauty of the open source model in action...


DavidM

Production is just another testing cycle
Go to Top of Page

david.wendelken
Starting Member

USA
2 Posts

Posted - 05/22/2007 :  20:00:40  Show Profile  Reply with Quote
quote:
Originally posted by jezemine

there's also the "en passant" attack that the pawn can do, but it's fairly rare. basically it can attack a pawn that is next to it rather than diagonally under some circumstances, to make up for the fact that enemy pawns can move forward 2 spaces on their first move and thus "escape" attack by your pawns. the attack is only allowed if you take it on the first chance it appears though, so would add some complexity to the query of allowed moves, since it depends on what the opponent did last.

http://www.google.com/search?q=pawn+en+passant


www.elsasoft.org



En Passant is part of the standard rules for modern chess, as is Castling.

Technically speaking, the queries presented so far show squares that a given piece might be allowed to move to from a given square - if circumstances allow. Future articles will have to deal with "if circumstances allow", considering such factors as intervening pieces, whether the King or Rook has moved prior to castling (they cannot have done so), whether a piece exists to be captured by the pawn, etc.

An en-passant attack moves the attacking pawn to the normal square it would normally attack into.

What makes an en passant capture different is that the pawn that is captured is not IN the target square at the time it was captured. It had to pass thru that square in its player's prior turn.

I would like to note that the query presented for pawns is not complete. Pawns, unlike other pieces in modern chess, are uni-directional. There needs to be a WhitePawnPossibleMoves and a BlackPawnPossibleMoves query. White pawns can only move if Y increases, Black pawns can only move if Y decreases.


Go to Top of Page

byrmol
Shed Building SQL Farmer

Australia
1591 Posts

Posted - 05/22/2007 :  20:33:18  Show Profile  Reply with Quote
quote:


Technically speaking, the queries presented so far show squares that a given piece might be allowed to move to from a given square - if circumstances allow. Future articles will have to deal with "if circumstances allow", considering such factors as intervening pieces, whether the King or Rook has moved prior to castling (they cannot have done so), whether a piece exists to be captured by the pawn, etc.

An en-passant attack moves the attacking pawn to the normal square it would normally attack into.

What makes an en passant capture different is that the pawn that is captured is not IN the target square at the time it was captured. It had to pass thru that square in its player's prior turn.

I would like to note that the query presented for pawns is not complete. Pawns, unlike other pieces in modern chess, are uni-directional. There needs to be a WhitePawnPossibleMoves and a BlackPawnPossibleMoves query. White pawns can only move if Y increases, Black pawns can only move if Y decreases.


Thanks David.

Yes I am aware of the rules of en passant and castling and they will be dealt with fully in the coming articles.

To be honest, I didn't know how popular the article was going to be, so decided to just outline the basic technique I will be using. Plus, as you can see from the comments, allow other people to critique and test it! One nasty bug already!

Considering this article has attracted 3 new members, then I think graz (the owner of this site) will post articles 2 and 3.

FYI, the next article deals with path calculations, modelling a piece and a database schema capable of applying all the rules of chess. The final article will deal with check and bring it all together.

EDIT: Quote instead of Code tag

DavidM

Production is just another testing cycle

Edited by - byrmol on 05/22/2007 20:36:19
Go to Top of Page

byrmol
Shed Building SQL Farmer

Australia
1591 Posts

Posted - 05/23/2007 :  00:30:06  Show Profile  Reply with Quote
jasmine2501,

AFAIK, there are only 4 possible moves for castling (2 per colour)
e1 -> c1 (White Long Castling)
e8 -> c8 (Black Long Castling)
e1 -> g1 (White Short Castling)
e8 -> g8 (Black Short Castling)

Which the query below generates.

Select FromSquare, ToSquare, abs(X-Xi) as XMovement,  abs(Y-Yi) as YMovement
from dbo.AllMoves
where (ABS(X - Xi) < 2 AND  ABS(Y - Yi)  < 2 
OR (Y = Yi AND X = 5 AND ABS(X-Xi) = 2 AND Y in (1,8)))
--Filter for possible castling moves
AND (abs(X-Xi) > 1 OR abs(Y-Yi) > 1)


One bug was bad enough. Please tell me you are mistaken jasmine2501. I might be unemployable with 2 bugs!

A thankyou to Koji Matsumura and Developer Jim for spotting the Bishop bug. The article has been updated with the corrected code and acknowledgement to you both. Cheers!

DavidM

Production is just another testing cycle
Go to Top of Page

DeveloperJim
Starting Member

2 Posts

Posted - 05/23/2007 :  14:30:14  Show Profile  Reply with Quote
quote:
Originally posted by byrmol
A thankyou to Koji Matsumura and Developer Jim for spotting the Bishop bug. The article has been updated with the corrected code and acknowledgement to you both. Cheers!

DavidM



Great article David. These were fun queries to play with. Thanks!
Go to Top of Page

Koji Matsumura
Posting Yak Master

141 Posts

Posted - 06/07/2007 :  04:01:53  Show Profile  Reply with Quote
When will next article be up?

Koji
Go to Top of Page

byrmol
Shed Building SQL Farmer

Australia
1591 Posts

Posted - 06/07/2007 :  05:11:09  Show Profile  Reply with Quote
>> When will next article be up?

ASAP. I have to give graz the updated second article with the bishop fix. It is 98% done.

I was on a roll but then got hammered by work commitments.

Specifically, a project has gone into final testing phase.
Is there anything more humbling than being grilled by 5 testers, a compliance officer, a couple of investors and the primary customer?

Time for more drinks....

DavidM

Production is just another testing cycle
Go to Top of Page

Koji Matsumura
Posting Yak Master

141 Posts

Posted - 09/06/2007 :  04:52:59  Show Profile  Reply with Quote
quote:
Originally posted by byrmol

>> When will next article be up?

ASAP. I have to give graz the updated second article with the bishop fix. It is 98% done.

I was on a roll but then got hammered by work commitments.

Specifically, a project has gone into final testing phase.
Is there anything more humbling than being grilled by 5 testers, a compliance officer, a couple of investors and the primary customer?

Time for more drinks....

DavidM

Production is just another testing cycle



Still waiting.....
Go to Top of Page

northview
Starting Member

United Kingdom
1 Posts

Posted - 11/14/2007 :  08:51:34  Show Profile  Reply with Quote
Just found this site. Any idea of an ETA for the next article?

Also, as well as Pawn moves being White or Black specific, the same applies to castling a King (eg castling from e1 only for White).
Go to Top of Page

bjoerns
Posting Yak Master

Germany
154 Posts

Posted - 07/08/2008 :  11:33:31  Show Profile  Reply with Quote
In the first example it is pointed out that the piece must actually move, FromSquare <> ToSquare. It seems this is missed later on? A bishop in a corner can do 7 moves, not 8 etc...

Bjoern
Go to Top of Page
Page: of 2 Previous Topic Topic Next Topic  
Previous Page
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.51 seconds. Powered By: Snitz Forums 2000