Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

 SQL Server Forums Profile | Active Topics | Members | Search | Forum FAQ
 All Forums  Site Related Forums  Article Discussion  Article: SQLChess - A tutorial on thinking in sets Reply to Topic  Printer Friendly
Author  Topic
Page: of 2

Koji Matsumura
Posting Yak Master

141 Posts

 Posted - 05/18/2007 :  00:55:39 How aboutSelect FromSquare, ToSquarefrom AllMoveswhere ABS(X-Xi) = ABS(Y-Yi)for the Bishop?

byrmol
Shed Building SQL Farmer

Australia
1591 Posts

 Posted - 05/18/2007 :  01:25:25 quote:Select FromSquare, ToSquarefrom AllMoveswhere ABS(X-Xi) = ABS(Y-Yi)That seems to work very nicely! Cheers!DavidMProduction is just another testing cycle

jasmine2501
Starting Member

1 Posts

 Posted - 05/21/2007 :  18:36:30 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

byrmol
Shed Building SQL Farmer

Australia
1591 Posts

 Posted - 05/21/2007 :  18:49:32 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 jasmine2501I 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.DavidMProduction is just another testing cycle

DeveloperJim
Starting Member

2 Posts

 Posted - 05/22/2007 :  18:43:14 quote:Originally posted by Koji MatsumuraHow aboutSelect FromSquare, ToSquarefrom AllMoveswhere 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 736Jim

byrmol
Shed Building SQL Farmer

Australia
1591 Posts

 Posted - 05/22/2007 :  19:05:05 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 736Ahh shit! Spot on Jim! The beauty of the open source model in action...DavidMProduction is just another testing cycle

david.wendelken
Starting Member

USA
2 Posts

 Posted - 05/22/2007 :  20:00:40 quote:Originally posted by jezeminethere'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+passantwww.elsasoft.orgEn 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.

byrmol
Shed Building SQL Farmer

Australia
1591 Posts

 Posted - 05/22/2007 :  20:33:18 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 tagDavidMProduction is just another testing cycle Edited by - byrmol on 05/22/2007 20:36:19

byrmol
Shed Building SQL Farmer

Australia
1591 Posts

 Posted - 05/23/2007 :  00:30:06 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!DavidMProduction is just another testing cycle

DeveloperJim
Starting Member

2 Posts

 Posted - 05/23/2007 :  14:30:14 quote:Originally posted by byrmolA 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!DavidMGreat article David. These were fun queries to play with. Thanks!

Koji Matsumura
Posting Yak Master

141 Posts

 Posted - 06/07/2007 :  04:01:53 When will next article be up?Koji

byrmol
Shed Building SQL Farmer

Australia
1591 Posts

 Posted - 06/07/2007 :  05:11:09 >> 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....DavidMProduction is just another testing cycle

Koji Matsumura
Posting Yak Master

141 Posts

 Posted - 09/06/2007 :  04:52:59 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....DavidMProduction is just another testing cycleStill waiting.....

northview
Starting Member

United Kingdom
1 Posts

 Posted - 11/14/2007 :  08:51:34 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).

bjoerns
Posting Yak Master

Germany
154 Posts

 Posted - 07/08/2008 :  11:33:31 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
Page: of 2  Topic
 Reply to Topic  Printer Friendly Jump To: Select Forum General SQL Server Forums       New to SQL Server Programming       New to SQL Server Administration       Script Library       Data Corruption Issues       Database Design and Application Architecture SQL Server 2012 Forums       Transact-SQL (2012)       SQL Server Administration (2012)       SSIS and Import/Export (2012)       Analysis Server and Reporting Services (2012)       Replication (2012)       Availability Groups and DR (2012)       Other SQL Server 2012 Topics SQL Server 2008 Forums       Transact-SQL (2008)       SQL Server Administration (2008)       SSIS and Import/Export (2008)       High Availability (2008)       Replication (2008)       Analysis Server and Reporting Services (2008)       Other SQL Server 2008 Topics SQL Server 2005 Forums       Transact-SQL (2005)       SQL Server Administration (2005)       .NET Inside SQL Server (2005)       SSIS and Import/Export (2005)       Service Broker (2005)       Replication (2005)       High Availability (2005)       Analysis Server and Reporting Services (2005)       Express Edition and Compact Edition (2005)       Other SQL Server Topics (2005) SQL Server 2000 Forums       SQL Server Development (2000)       SQL Server Administration (2000)       Import/Export (DTS) and Replication (2000)       Transact-SQL (2000)       Analysis Services (2000)       MSDE (2000) Development Tools       ASP.NET       Reporting Services Development       Other Development Tools Site Related Forums       Site Related Discussions       Article Discussion       Poll Discussion       The Yak Corral Other Forums       SQL Server 6.5 \ SQL Server 7.0       Other Topics       MS Access       ClearTrace Support Forum Old Forums       CLOSED - General SQL Server       CLOSED - SQL Server 2005/Yukon  -------------------- Home Active Topics Frequently Asked Questions Member Information Search Page
 SQL Server Forums © 2000-2019 SQLTeam Publishing, LLC