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.

 All Forums
 Site Related Forums
 Article Discussion
 Article: SQLChess - A tutorial on thinking in sets

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2007-05-14 : 07:52:51
Chess makes a fantastic game for programming examples. You will find hundreds of examples on the internet. Some dedicated to OO patterns, others to algorithms and so forth. Unfortunately, most of these examples do not use a database or if they do, treat the database as nothing more than a storage repository. In this series of articles we will use SQL Server and T-SQL to implement the game of chess with an emphasis on thinking in sets.

Article Link.

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-05-14 : 15:18:50
I have a doubt ... why teh chess game doesn't work? Plz help !!!

...

just kidding! Great article, a nice start to what should be a very interesting idea for a SQL tutorial ... Looking forward to more in the series.


- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

byrmol
Shed Building SQL Farmer

1591 Posts

Posted - 2007-05-14 : 15:43:44
>>I have a doubt ... why teh chess game doesn't work? Plz help !!!

That's funny Jeff! I'll throw in a UI at the end.



DavidM

Production is just another testing cycle
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-05-14 : 15:59:52
Where is the "pawn-to-queen" move?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2007-05-14 : 16:01:25
You've all seen the SQL Checkers script, I assume? If not, I can find a copy of it in my files. It actually will play checkers against you using SQL.

e4 d5 xd5 Nf6
Go to Top of Page

byrmol
Shed Building SQL Farmer

1591 Posts

Posted - 2007-05-14 : 16:04:36
>>Where is the "pawn-to-queen" move?

Are you talking about promotion Peso?

>>You've all seen the SQL Checkers script, I assume.

No.

DavidM

Production is just another testing cycle
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-05-14 : 16:05:15
quote:
Originally posted by Peso

Where is the "pawn-to-queen" move?


Peter Larsson
Helsingborg, Sweden



Pawn-to-Queen ??

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-05-14 : 16:08:29
quote:
Originally posted by byrmol

>>Where is the "pawn-to-queen" move?

Are you talking about promotion Peso?
Yes. It sounds right.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-05-14 : 16:13:34
That's not really a move, that's more of an "event".



- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-05-14 : 16:19:54
Aha.. Same as "Castling" then, which is described.
Ok, see "promotion" on page 2 of the article, then?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

byrmol
Shed Building SQL Farmer

1591 Posts

Posted - 2007-05-14 : 16:20:36
>>Yes. It sounds right.

Given the current schema, we don't have enough information for that. I model a chess piece in the next article, but it was my understanding that promotion is not compulsory and does not have to be a queen.

I will be treating promotion as a "special transition". Something that alters that state of the board without actual piece movement.



DavidM

Production is just another testing cycle
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2007-05-14 : 17:15:42
Promotion is compulsory, but can be to any piece except a King or a Pawn.
Promotion to a piece of lesser value is called "under-promotion", and is relatively rare. A pawn may be promoted to a knight to effect an immediate checkmate, or check the opponent's king to prevent him from checkmating you on the next turn. A pawn may be promoted to a bishop or a rook to avoid stalemating the opponent.

e4 d5 xd5 Nf6
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-05-14 : 17:52:12
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
Go to Top of Page

byrmol
Shed Building SQL Farmer

1591 Posts

Posted - 2007-05-14 : 18:30:10
quote:

Promotion is compulsory, but can be to any piece except a King or a Pawn.
Promotion to a piece of lesser value is called "under-promotion", and is relatively rare. A pawn may be promoted to a knight to effect an immediate checkmate, or check the opponent's king to prevent him from checkmating you on the next turn. A pawn may be promoted to a bishop or a rook to avoid stalemating the opponent.

e4 d5 xd5 Nf6



You know, I should have thought about this a little more before I posted. There is probably a dozen closet chess master as members of SQLTeam. I'm screwed!

The variant I will be using has en passant and castling. That promotion rule makes en passant and castling look mild.

DavidM

Production is just another testing cycle
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2007-05-14 : 22:32:56
en-passant is not all that rare. But I would think it would be much more difficult to implement than promotion, because it require additional exception logic while promotion is just object substitution.

e4 d5 xd5 Nf6
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-05-14 : 23:26:18
that's what I was thinking. knowing when en-passant is allowed requires you to remember what the last player did.


www.elsasoft.org
Go to Top of Page

byrmol
Shed Building SQL Farmer

1591 Posts

Posted - 2007-05-14 : 23:37:12
If I read those promotion rules correctly, then anything other than a queen promotion, requires detemining stalemate or check mate.

Far harder than en passant...

DavidM

Production is just another testing cycle
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-05-15 : 01:27:19
I don't think it's a rule that you must promote to a knight (or any other piece for that matter) if it forces a checkmate. it's up to the player that wins the promotion what piece they want. it's just that if by taking a knight a player gets an instant checkmate, then the player should do that - unless of course they don't want to win for some reason

I think blindman was only listing some circumstances when you might want to promote to a piece other than a queen. another circumstance would be if you already have a couple queens. it's rather easy to end up in a stalemate if you have several queens on the board.

btw I am definitely not a sqlteam closet chess master. I played on the chess team in high school but that was it. I'm just a hack.


www.elsasoft.org
Go to Top of Page

elwoos
Master Smack Fu Yak Hacker

2052 Posts

Posted - 2007-05-15 : 03:41:48
quote:
There is probably a dozen closet chess master as members of SQLTeam.


I'm a chess idiot as spirit and many others will attest though he could be in trouble at the moment [url]http://gameknot.com/chess.pl?bd=7070610&r=126[/url]

Seriously though I find this really interesting stuff

How about doing GO [url]http://en.wikipedia.org/wiki/Go_(board_game)[/url] as a future topic?


steve

-----------

Don't worry head. The computer will do all the thinking from now on.
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2007-05-15 : 09:23:37
Correct jezemine. It is the player's choice which piece he wants to promote to. I was just listing circumstances under which one would want to under-promote.

e4 d5 xd5 Nf6
Go to Top of Page

byrmol
Shed Building SQL Farmer

1591 Posts

Posted - 2007-05-16 : 17:59:54
>> It is the player's choice which piece he wants to promote to. I was just listing circumstances under which one would want to under-promote.

That is what I thought. I thought I was following a standard variant, but you seriously had me worried!

The first article was just to setup the technique that I am using.

DavidM

Production is just another testing cycle
Go to Top of Page
    Next Page

- Advertisement -