From: david
Subject: please review my *new* code
Date: 
Message-ID: <3996a060-2661-47e6-9ba0-4e49b4357a21@d32g2000yqe.googlegroups.com>
heavy on commenting, light on code
back to the drawing board.
i could use some more help where indicated in comments.
i have outlined, i think, my whole idea for the program.
any input on thinking about program design will be avidly
read and maybe saved to a file on my desktop.
or i will read my textbooks some more.

i thank you all 1e6, david

;;;; fen.lisp
;;;; make a Forsythe Edwards Notation file with a random bishop knight
endgame
;;;; example: 8/2B5/2N1K3/8/8/8/4k3/8
;;;; numbers represent empty space in the file (on the chessboard)
;;;; capital letters are white pieces, lower case are black

;;; get a list of four unique random numbers
;;; thanks to  __Pascal Bourguignon__

(defun get-positions ()
  (loop
     :with results = '()
     :for alea = (random 64)
     :while (< (length results) 4)
     :do (pushnew alea results)
     :finally (return results)))

;;; determine the rank and file for a position between 0 and 63
;;; think of chessboard as 7 by 7 starting with 0.
;;; figure out how to do integer division to make it clearer (to me)

(defun rank-file (position)
  (multiple-value-list (truncate position 8)))





;;; create a lexical environment to work with rank file values
;;; i am really stuck on this part

;;; translating example into a list
;;; ((0 0 0 0 0 0 0 0)(0 0 wb 0 0 0 0 0)(0 0 wn 0 wk 0 0 0)(0 0 0 0 0
0 0 0)
;;;  (0 0 0 0 0 0 0 0)(0 0 0 0 0 0 0 0)(0 0 0 0 bk 0 0 0)(0 0 0 0 0 0
0 0))
;;; turn it into this: ((8)(2wb5)(2wn1wk)(8)(8)(8)(4bk3)(8))
;;; acl page 37


;;; flatten list somehow and change wk to K and bk to k
;;; add rest of fen string stuff


;;; print to a file, play with crafty and xboard.
;;; rewrite program with new common lisp knowledge.
;;; finish paip, adapt program to be friendly all-knowing ai.
From: Pascal J. Bourguignon
Subject: Re: please review my *new* code
Date: 
Message-ID: <7c63j61m80.fsf@pbourguignon.anevia.com>
david <······@gmail.com> writes:

> ;;; determine the rank and file for a position between 0 and 63
> ;;; think of chessboard as 7 by 7 starting with 0.

???

You should read:
http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html


Otherwise, you should distinguish the external data formats that may
be specified for interchange or other reasons (in the case of FEN,
it's a format specified for interchange) from the internal data.
Internally, you get to choose your data structures, and you can choose
them to make it easy to implement the algorithms you need to implement
with them.  Another thing is that you should abstract away the
representation.  We don't care whether you count from 0 or from 1, or
whether you store the data as a single number between 0 and 63 or two
numbers between 1 and 8 or a letter and a number or just a pointer to
the cell, etc.  Just define a set of functions that allow you to
manipulate the objects either way.

(def... cell ...)
;; defstruct, defclass, deftype, whatever.


(cell-at board row column) --> cell
(cell-row cell) --> row
(cell-column cell) --> column
(cell-number cell) --> number ; eg. from 0 to 63

The type of cell can itself be whatever you want, any representation
is good.  But you will never use it for what it is concretely, only
for what it is abstractly, that is, you will use cell values only
using these abstract functions.  By the same token, row and column can
be anything.  It could be numbers in [0,7] or [1,8] or objects or
anything you want or need them to be to make your algorithms efficient
and easy to implement.



For more details, read SICP.

SICP  = Structure and Interpretation of Computer Programs
        http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-4.html
        http://swiss.csail.mit.edu/classes/6.001/abelson-sussman-lectures/

        http://eli.thegreenplace.net/category/programming/lisp/sicp/
        http://www.codepoetics.com/wiki/index.php?title=Topics:SICP_in_other_languages

-- 
__Pascal Bourguignon__