Author: Gerd Isenberg
Date: 11:47:09 02/23/04
Go up one level in this thread
On February 23, 2004 at 12:30:47, Steven Edwards wrote: >Heres some example code from Symbolic, the KBNK endgame class recognizer: > >(defun IsKBNK? (MyPos) > "Return White if KBNK, Black if KBNK reversed, nil otherwise" > (cond > ((and > (= (CountByColorPos White MyPos) 3) > (= (CountByColorPos Black MyPos) 1) > (= (CountByManPos WhiteBishop MyPos) 1) > (= (CountByManPos WhiteKnight MyPos) 1)) White) > ((and > (= (CountByColorPos Black MyPos) 3) > (= (CountByColorPos White MyPos) 1) > (= (CountByManPos BlackBishop MyPos) 1) > (= (CountByManPos BlackKnight MyPos) 1)) Black) > (t nil))) > >Comments: > >1. Does anyone really think that Lisp is hard to read? As a C++ programmer a bit unusual, yes. Is the cond operator for (nested) if else? > >2. While the above could have been done in the C++ code of the underlying >tookit, it wouldn't have been that much faster. Well maybe, because the first statement is most often false anyway ;-) > >3. The above code, like all of ChessLisp, is typesafe. This means that a >function that expects a color checks for a color value, one that expects a >position symbol checks for a position symbol, etc. > >4. Further work on KBNK will help with the design and implementation of the >pattern recognition and planning facilities. In C++ i may use typesafe inliners like this: (I like to avoid duplicate code for white and black) enum colorOrNil { white, black, nil }; bool CNode::oneSideHasKingOnly() { return nofPieces(white) == 1 || nofPieces(black) == 1; } colorOrNil CNode::isKBNK() { if ( nofPieces() == 4 && oneSideHasKingOnly() && nofBishops() == 1 && nofKnights() == 1 ) return colorOf(knight); return nil; } Gerd
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.