www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/11/04/14:46:22

From: Charles Krug <charles AT pentek DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Newbie asking for Help !!!!
Date: Mon, 03 Nov 1997 09:16:28 -0500
Lines: 37
Message-ID: <345DDCBC.9415074D@pentek.com>
References: <62tqij$mt9$1 AT news00 DOT btx DOT dtag DOT de>
NNTP-Posting-Host: mail.pentek.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Knut Pape wrote:

> I have just started programming with djgpp in C.
> After reading some Tutorials and Book's I'm trying myself on my first
> programm (4Gewinnt).
> Now I have a big problem. I have a board of 42 fields, variables from f1
>
> to f42.
>

All good C/C++ programmers use f0 to f41

> Now the KI has to look up for deadly combinations

Make your squares a struct:

typedef struct square {
    bool filled;       /* 1 if the square is filled */
    int directions;   /* Set a bit for each direction you want to search */
};

squares board[41];

(etc)Every square has a finite number of directions to be checked.  Use a
bit field to determine which directions to look.  Given the size of your
field, a breadth first search may be helpful.  (look it up in your algroithm
book)  (Go out and buy and algorithm book)

You might want to consider looking at the source code for grep as an aid in
pattern matching.  Yes, this can be a pattern matching problem.

>

--
Charles Krug, Jr.


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019