Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Symbolic: The KBNK recognizer

Author: Ian Osgood

Date: 18:14:20 02/24/04

Go up one level in this thread


On February 24, 2004 at 01:06:46, Christophe Theron wrote:
>
>I find Forth to be extremely elegant, because it is based on a very small number
>of concepts. Its syntax is minimalist, almost non-existent. It can be learnt
>very quickly, can be implemented (and has probably been implemented) on every
>computer out there, and it is even possible to write processors that interpret
>Forth directly (Chuck Moore has been working on a clockless one: it computes as
>fast as it can, without a clock!).
>
>Its only drawback to me is that it is not as easy to read as other languages, at
>least in the begining.
>
>However I must admit that I have not written enough Forth code. I do not know
>how it "feels" to program in that language every day.
>
>Maybe it's not that cool, but it's very tempting. The color version seems even
>more interesting.
>
>
>
>    Christophe
>

Forth does take some getting used to.  There have been studies that
schoolchildren
pick up Forth more easily than BASIC and Pascal.  (They might also pick up Logo,
Lisp, and SmallTalk as easily, though.)  So for us, it is a matter of unlearning
our
own hard learned infix habits.

Forth has been widely described as an amplifier.  Bad to mediocre programmers
write worse code, but good to exceptional programmers become 10x more
productive.  The lack of strict syntax is a double edged sword.  You can come
up with vocabularies that elegantly describe and solve your problem, but you
can also easily write cryptic line noise and get bogged down with "stack
juggling".

You know that Jeff Fox already ported a chess program to their prototype F21
Forth chips?  Unfortunately, they chose a really bad implementation so it never
went beyond depth 5.  Someday, I'm hoping he'll have the time to port FCP
(my TSCP Forth port) to one of those clockless chips.

As an example of readability, here is an excerpt from FCP's move generator:

Forth primer:

( sq -- sq ) is a stack comment.  This says an 0x88 square coordinate
  is the parameter on the stack, and the function does not consume it.
DUP ( a -- a a )
OVER ( a b -- a b a )
: starts a function definition, ; ends it
CREATE names a block of memory
, lays down one cell of data in memory
' obtains an execution token (like a function pointer) of the following symbol
['] does the same, but within a function definition
EXECUTE invokes the token
"condition IF doThis THEN continue"
@ dereferences the top item (like C's * operator)
"i CELLS array + @" is an idiom for C's array[i] (a cell is like C's int type)

==== start FCP excerpt =====

\ Kn1, No, NW etc. are all direction offset constants for a 0x88 board

: genN
  Kn1 genAdjacent Kn2 genAdjacent Kn3 genAdjacent Kn4 genAdjacent
  Kn5 genAdjacent Kn6 genAdjacent Kn7 genAdjacent Kn8 genAdjacent ;

: genK
  No genAdjacent Ea genAdjacent So genAdjacent We genAdjacent
  NE genAdjacent SE genAdjacent SW genAdjacent NW genAdjacent ;

: genB
  NE genSlider SE genSlider SW genSlider NW genSlider ;

: genR
  No genSlider Ea genSlider So genSlider We genSlider ;

: genQ
  genR genB ;

: genNil ." Illegal piece on square " DUP .sq CR ;

\ genVector is an interleaved table,
\  genSq indexes by [sq]-8 (piece + color: $11..$16, $21..$26)
\  genCapsSq indexes by [sq]

CREATE genVector
  ' genNil , ' genNil , ' genNil , ' genNil ,
  ' genNil , ' genNil , ' genNil , ' genNil ,
  ' genNil , ' genLP ,  ' genN ,   ' genB ,
  ' genR ,   ' genQ ,   ' genK ,   ' genNil ,
  ' genNil ,   ' genCapsLP , ' genCapsN , ' genCapsB ,
  ' genCapsR , ' genCapsQ ,  ' genCapsK , ' genNil ,
  ' genNil , ' genDP ,  ' genN ,   ' genB ,
  ' genR ,   ' genQ ,   ' genK ,   ' genNil ,
  ' genNil ,   ' genCapsDP , ' genCapsN , ' genCapsB ,
  ' genCapsR , ' genCapsQ ,  ' genCapsK , ' genNil ,

: genCapsSq ( sq -- sq )
  side OVER bd@mine? IF
    DUP bd@ CELLS genVector + @ EXECUTE  \ all vectors are ( sq -- sq )
  THEN ;

: genCaps
  genInitPly
  ['] genCapsSq forEverySq
  genEP ;

: genSq ( sq -- sq )
  side OVER bd@mine? IF
    DUP bd@ 8 - CELLS genVector + @ EXECUTE
  THEN ;

: gen
  genInitPly
  ['] genSq forEverySq
  genCastle
  genEP ;

===== end FCP excerpt =====

Hopefully the rest of what I have not explained is clear in context.

Ian



This page took 0.01 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.