Click here to Skip to main content
16,008,469 members
Home / Discussions / C#
   

C#

 
GeneralRe: Lock a file for reading when uploading it to FTP Pin
thoru28-Jul-08 3:56
thoru28-Jul-08 3:56 
GeneralRe: Lock a file for reading when uploading it to FTP Pin
Luc Pattyn28-Jul-08 4:09
sitebuilderLuc Pattyn28-Jul-08 4:09 
GeneralRe: Lock a file for reading when uploading it to FTP Pin
thoru28-Jul-08 4:16
thoru28-Jul-08 4:16 
GeneralRe: Lock a file for reading when uploading it to FTP Pin
Luc Pattyn28-Jul-08 4:28
sitebuilderLuc Pattyn28-Jul-08 4:28 
QuestionDetermining valid moves for a chess game Pin
Gareth H28-Jul-08 3:00
Gareth H28-Jul-08 3:00 
AnswerRe: Determining valid moves for a chess game Pin
enginço28-Jul-08 3:21
enginço28-Jul-08 3:21 
GeneralRe: Determining valid moves for a chess game Pin
Gareth H28-Jul-08 3:31
Gareth H28-Jul-08 3:31 
AnswerRe: Determining valid moves for a chess game [modified] PinPopular
Luc Pattyn28-Jul-08 4:00
sitebuilderLuc Pattyn28-Jul-08 4:00 
Hi Gareth,

there are many ways to generate and store chess moves, I tried some of them.
The most popular nowadays has the following characteristics:
- use BOARD (a uint, that's unsigned int 64-bit) as the fundamental data type, and let each bit
represent one square.
- use as many BOARD items as you see fit, e.g. one to indicate the position of all white pieces,
one to indicate the position of all white rooks, etc.
- apply bitwise operators all the time: hence pieces=kings|queens|rooks|bishops|knights|pawns
- for move generation, try to use shifts, e.g. if wrooks is a BOARD indicating the position of
white rooks, then they could move one to the left by shifting left by one, except of course for
rooks in the "a" file; so it would look like wrooksLeft1=(wrooks & notAFile) << 1
- doing it this way, you can get very compact code, and avoid a lot of conditional branches and bugs.
- you have to work iteratively for long moves, so rookLeft7 does not make sense, you must iterate
with rookLeft1 since you have to detect occupied squares.
- you can't check yourself; the easiest way to avoid that is make your king behave as a queen, then
as a knight, and see whether it can capture a corresponding piece of the opposing color.
- and of course a lot of BOARD items can be precalculated and stored in some tables.

In my estimate it takes around a thousand lines of code to generate all moves correctly, including
castling, double pawn move, and en-passant.

Hope this helps.

Smile | :)

Luc Pattyn [Forum Guidelines] [My Articles]

Voting for dummies? No thanks. Dead | X|


modified on Monday, July 28, 2008 10:44 AM

AnswerRe: Determining valid moves for a chess game Pin
GuyThiebaut28-Jul-08 5:11
professionalGuyThiebaut28-Jul-08 5:11 
GeneralRe: Determining valid moves for a chess game Pin
Luc Pattyn28-Jul-08 5:25
sitebuilderLuc Pattyn28-Jul-08 5:25 
GeneralRe: Determining valid moves for a chess game Pin
GuyThiebaut28-Jul-08 5:43
professionalGuyThiebaut28-Jul-08 5:43 
QuestionType comparison syntax Pin
Mycroft Holmes28-Jul-08 2:58
professionalMycroft Holmes28-Jul-08 2:58 
AnswerRe: Type comparison syntax Pin
Gareth H28-Jul-08 3:03
Gareth H28-Jul-08 3:03 
GeneralRe: Type comparison syntax Pin
Mycroft Holmes28-Jul-08 4:13
professionalMycroft Holmes28-Jul-08 4:13 
QuestionScrapping a Datastore Pin
logicon28-Jul-08 2:54
logicon28-Jul-08 2:54 
AnswerRe: Scrapping a Datastore Pin
logicon28-Jul-08 3:26
logicon28-Jul-08 3:26 
Questionold value after validating event of datetimepicker Pin
tabstop28-Jul-08 2:25
tabstop28-Jul-08 2:25 
AnswerRe: old value after validating event of datetimepicker Pin
Kjetil Svendsen28-Jul-08 5:30
Kjetil Svendsen28-Jul-08 5:30 
GeneralRe: old value after validating event of datetimepicker Pin
tabstop28-Jul-08 20:49
tabstop28-Jul-08 20:49 
Questionupdate xml file Pin
arkiboys28-Jul-08 2:14
arkiboys28-Jul-08 2:14 
AnswerRe: update xml file Pin
teejayem28-Jul-08 2:39
teejayem28-Jul-08 2:39 
QuestionDeploying multiple projects Pin
jamesjk28-Jul-08 1:04
jamesjk28-Jul-08 1:04 
AnswerRe: Deploying multiple projects Pin
Thomas Stockwell28-Jul-08 1:33
professionalThomas Stockwell28-Jul-08 1:33 
GeneralRe: Deploying multiple projects Pin
jamesjk28-Jul-08 1:54
jamesjk28-Jul-08 1:54 
GeneralRe: Deploying multiple projects Pin
Thomas Stockwell28-Jul-08 2:03
professionalThomas Stockwell28-Jul-08 2:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.