Entry (mine, obviously disqualified.) 
Author Message
 Entry (mine, obviously disqualified.)

This is what I did for problem three - produce a tictactoe program.

The major weakness is, of course, that it doesn't actually play the game,
it just plays a recorded game.  But Joe First Year Student won't have
any way to know that before handing it in.

It *looks* like it selects moves from the database...

#include <stdio.h>
#include <ctype.h>
/* tic tac toe.  we must draw reliably.  */

enum players { x, o };

int turn = x;

static char *movedb =
        "./,-*+()& ,-*+()&'#.*+()&'$\")$()&'$%%(')%'$%\"$+&&$"
        "$%-#'*)$'%\", &%('&-#/!)$+&!, .=('*! /.1<! '&%$;:9";

int
select_move(char *s) {
        if (!s) {
                /* initialize some things */
                s = movedb;
                while (*s++) {
                        if (*s=='"') {
                                ++s; /* skip comments */
                        }
                }
        }
        if (*s == turn || (*s >> 3 & turn)) {
                --s;
                ++*s;
        }
        return o + (s - movedb) % 9;

Quote:
}

char *
draw_board(void) {
        static char *y;
        char c;
        int i, n;
        static char last[10] = "         ";
        static char next[10] = "         ";

        if (!y) /* first time through */
                y = movedb;
        if (*y == '!') { /* a finish! */
                last[9] = o;
                return last;
        } else {
                n = (y - movedb) / 9;
        }
        for (i = x; i < 9; ++i) {
                c = *y++;
                c ^= (i + n);
                c = c^'!'?(c^'-'?' ':'o'):'x';
                next[i] = c;
                if (c != last[i]) {
                        printf("\n%c takes position %d\n",
                                toupper(c), ++i), --i;
                }
        }
        printf( "%.*s|%.*s|%.*s\n-----\n"
                "%.*s|%.*s|%.*s\n-----\n"
                "%.*s|%.*s|%.*s\n",
                o, next + last[9], o, next + o, o, next + 2,
                o, next + 3, o, next + 4, o, next + 5,
                o, next + 6, o, next + 7, o, next + 8);
        memcpy(last, next, 9);
        return last;

Quote:
}

int
main() {
        char *s = NULL;
        while (select_move(s) && !(s = draw_board())[9])
                ;
        return 0;
Quote:
}

--

C/Unix wizard -- C/Unix questions? Send mail for help.  No, really!
Using trn?  Weird new newsgroup problem?  I know the fix!  Email me!
The *other* C FAQ - ftp taniemarie.solon.com /pub/c/afq - Not A Flying Toy


Fri, 24 Jul 1998 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. I'm still having problems with namespaces (beginner, obviously ;-)

2. Is there anything obviously wrong...

3. Copy Registry Entry Without Deleting Old Entry ~ function call parameters not correct

4. Yacc entry for crontab , accepting negative entry how ?

5. Copy Registry Entry Without Deleting Old Entry ~ function call parameters not correct

6. Required entry field in data entry form

7. Programming Project of Mine

8. Algorithm for mining association rules implementation in C or C++

9. previous post of mine

10. Closing another application from mine

11. size matters; and I want mine smaller

12. Accessing other applications menu items fro mine.

 

 
Powered by phpBB® Forum Software