Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Chess programming puzzle

Author: Uri Blass

Date: 14:54:26 02/22/05

Go up one level in this thread


On February 22, 2005 at 17:06:28, Scott Gasch wrote:

>On February 22, 2005 at 16:46:58, Uri Blass wrote:
>
>>On February 22, 2005 at 15:30:49, Scott Gasch wrote:
>>
>>>On February 22, 2005 at 13:14:09, Uri Blass wrote:
>>>
>>>>On February 22, 2005 at 08:35:07, Andrew Wagner wrote:
>>>>
>>>>>Hi all.
>>>>>I got sidetracked this morning by an interesting chess programming problem. It
>>>>>took me a couple hours, but I think I have a working algorithm -- haven't tested
>>>>>yet though. Anyway, I got to wondering if others would approach it the same way.
>>>>>So I thought I'd make a little competition of it. Post your code here, and I'll
>>>>>pick the program I like best and shower praise and adulation on its author. If
>>>>>people like this challenge, maybe I'll do one each month or something. Anyway,
>>>>>here's the one I did this morning:
>>>>>There are 64 x 63 = 4032 ways to put a black knight and white knoght both on a
>>>>>chess board. Write a program -- from scratch -- to generate FENs for each of
>>>>>these positions. The FENs should look something like: Nn6/8/8/8/8/8/8/8 w - - 0
>>>>>1.
>>>>>
>>>>>I think my code will wind up weighing in at around 60-70 lines of C. Can you do
>>>>>better?
>>>>
>>>>Here is my code(not 100% sure of no bugs)
>>>>
>>>>It seems that there are better codes
>>>>based on looking at other codes
>>>>
>>>>#include <stdio.h>
>>>>int main(void)
>>>>{
>>>>int whiteknight,blackknight,rank,N,n,empty1,empty2,empty3;
>>>>char c1,c2;
>>>>for (whiteknight=0;whiteknight<64;whiteknight++)
>>>>  for (blackknight=0;blackknight<64;blackknight++)
>>>>		if (whiteknight!=blackknight)
>>>>		{
>>>>			for (rank=7;rank>=0;rank--)
>>>>			{
>>>>				N=8;
>>>>				n=8;
>>>>				if ((whiteknight>>3)==rank)
>>>>					N=whiteknight&7;
>>>>				if ((blackknight>>3)==rank)
>>>>					n=blackknight&7;
>>>>				if (n<N)
>>>>				{
>>>>					empty1=n;
>>>>					empty2=N-n-1;
>>>>					empty3=7-N;
>>>>					c1='n';
>>>>					c2='N';
>>>>				}
>>>>				else
>>>>				{
>>>>					empty1=N;
>>>>					empty2=n-N-1;
>>>>					empty3=7-n;
>>>>					c1='N';
>>>>					c2='n';
>>>>				}
>>>>				if (empty1>0)
>>>>				printf("%d",empty1);
>>>>				if (empty1<8)
>>>>					printf("%c",c1);
>>>>				if (empty2>0)
>>>>					printf("%d",empty2);
>>>>				if (empty3>=0)
>>>>					printf("%c",c2);
>>>>				if (empty3>0)
>>>>					printf("%d",empty3);
>>>>				if (rank>0)
>>>>					printf("/");
>>>>			}
>>>>			printf(" w - - 0 1\n");
>>>>		}
>>>>		return 0;
>>>>}
>>>>
>>>>Uri
>>>
>>>[ scott@wannabe:~/tmp ] % g++34 -O -S aaa.c ; wc -l aaa.s
>>>     196 aaa.s
>>
>>I do not understand what you want to say.
>>
>>I thought first that you accidentally posted some meaningless string for me but
>>I see now that you did the same in response to code of other people.
>>
>>Uri
>
>It means I think it's stupid to compare lines of C code.  As I said before: I
>can do it in one line (a really long line).
>
>It means that your solution is 196 lines of x86 assembly language when compiled
>with g++34 -O.

I do not understand assembler so I do not care about it.
I think that you take too serious the comparison in lines

The fact that you can write things in one line mean nothing.
I compare codes that I understand and Tim foden's was the best that I found.

I was interesting in the question because I may write something more general and
not because I am interested in exact comparison of length.

30 lines is better than 50 lines when there is no effort to do it artificially
short but 30 lines is not necessaraly better than 32 lines.

Uri



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.