Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Chess programming puzzle

Author: Uri Blass

Date: 12:06:32 02/22/05

Go up one level in this thread


On February 22, 2005 at 14:45:07, Dann Corbit wrote:

>On February 22, 2005 at 14:10:10, Tim Foden 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's my attempt, although I did squidge the lines together a bit (20 lines) :)
>>
>>#include <stdio.h>
>>int main( int, char** ) {
>>    for( int i = 0; i < 64; i++ ) {
>>        for( int j = 0; j < 64; j++ ) {
>>            if( i == j ) continue;
>>            for( int cnt = 0, k = 0; k < 64; k++ ) {
>>                if( k && (k & 7) == 0 ) printf( "/" );
>>                if( k == i || k == j ) {
>>                    if( cnt != 0 ) { printf( "%d", cnt ); cnt = 0; }
>>                    printf( k == i ? "N" : "n" );
>>                } else {
>>                    cnt++;
>>                    if( (k & 7) == 7 ) { printf( "%d", cnt ); cnt = 0; }
>>                }
>>            }
>>            printf( " - - 0 1\n" );
>>        }
>>    }
>>    return 0;
>>}
>>
>>Cheers, Tim.
>Exactly the same, only completely different:
>
>#include<stdio.h>
>char q0??(9??)=??<'0','1','2','3','4','5','6','7','8'??>;int main(void
>)??<int q1,q2,q3,q4;for(q1=0;q1<64;q1++)??<for(q2=0;q2<64;q2++)??<if(
>q1==q2)continue;for(q4=0,q3=0;q3<64;q3++)??<if(q3&&(q3&7)==0)putchar(
>'/');if(q3==q1||q3==q2)??<if(q4!=0)??<putchar(q0??(q4??));q4=0;??>
>putchar(q3==q1?'N':'n');??>else??<q4++;if((q3&7)==7)??<putchar(q0??(q4
>??));q4=0;??>??>??>puts("\40\55\40\55\40\60\40\61");??>??>return 0;??>


I find that it works but unfortunately I do not understand your code.
I never use ?? in code that I write and I do not know what it means.

Tim's code is the shortest code that I can understand.

Uri



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.