![]() |
| | #1 |
| Slave Join Date: Jan 2005
Posts: 735
| Checkmate Thanks, -MC |
| MadCow257 is offline | |
| | #2 |
| Registered User Join Date: Aug 2002 Location: Hermosa Beach, CA
Posts: 446
| You really should probably try to write it yourself first. And then look at the source code to Crafty: http://www.cis.uab.edu/info/faculty/hyatt/hyatt.html Here's how I would guess it's written: Firstly the conditions for checkmate are: a) King is in check b) King can't move out of check. c) Check can't be blocked d) checking piece can't be captured So the main key is having a function that determines if the king is in check. We could do this as follows: 1) Generate a bitboard that is the bitwise AND of all the opponent's pieces attack boards. 2) AND that board with the location of the king, if the result is non-zero, then the king is in check. Next you need to generate all pseudo-legal moves (meaning we don't look at if we're moving into check or if the resulting position leaves us in check), and as a heuristic we do it in the following order: 1) all king moves first 2) all captures next 3) other moves last Then since we're using alphabeta (presumably) the other side will go into the evaluate function, and if we left the king in check in the previous step, then it will see that it can capture the king on this move (using the in-check test from above). In that case return some very large number (or very small number, as the case may be). If all legal moves leave the king in check, then you have your answer. It's checkmate. This should even handle double checks, discoveries, smothered mates, etc. Let me know if you find crafty's way to be significantly different. It would be interesting to know, and eventually I'll be writing my own game, after I finish connect four, and then probably checkers, gin, hold'em, and finally maybe chess...
__________________ The crows maintain that a single crow could destroy the heavens. Doubtless this is so. But it proves nothing against the heavens, for the heavens signify simply: the impossibility of crows. |
| IfYouSaySo is offline | |
| | #3 |
| Registered User Join Date: Sep 2003
Posts: 34
| I have quite a few articles at home about chess programming. I havn't looked at them all in depth but I'm sure some of them will have some info on this. If you'd like I can take a look later and upload them.
__________________ -gunder if (problem) postcount++; |
| gunder is offline | |
| | #4 |
| Registered User Join Date: Aug 2005 Location: Stockholm
Posts: 71
| Think about if it is better to always check for mate or to search one ply deeper. What consumes more processing time?
__________________ Bobby Fischer Live Radio Interviews http://home.att.ne.jp/moon/fischer/ |
| fischerandom is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Checkmate! | FearOfTheDark | A Brief History of Cprogramming.com | 10 | 04-20-2003 06:54 PM |