⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wpw_wapi_misc_95.html

📁 VC programing
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<HTML>

<HR><A NAME=WINAPI_MISC_CARD_DLL>
Return to <a href="wpw_wapi_index.html#TOC">Table of Contents for this chapter</a><br>
<H4>Subject: Use Card.dll</H4><PRE>
Chris Marriott <chris@chrism.demon.co.uk> writes:

>In article <DA6KGx.MHC@unx.sas.com>
>           sasdav@talon.unx.sas.com "David Barron" writes:
>>I'm trying to write a card game using the bitmaps in the cards.dll that 
>>comes with WFWG.  I need a way to randomize the cards so that each card 
>>is selected once, but only once.  I assume Hearts, Solitare, and 
>>FreeCell each do this.  Does anyone have a suggestion of how this could 
>>be done?

>Easy. Have an array of 52 elements containing the numbers 1 to 52
>(initially in order) to represent the cards. Generate two random numbers
>in the range 0 to 51 and swap the numbers in those two array locations.

I.  There are a few problems/inefficiencies with this. It's best to set up
    your array with the bounds of 0..51 storing the numbers 0..51. (instead of
    1-52).  This way, you can do something like calculate the suit or face of
    a card with one math operation, to wit:

    if id = 0..51, then you could do something like the Ace of Clubs = 0, Two
    of Clubs = 1, Trey of Clubs = 2, ... King of Spades = 51.

    suit = id / 13   ( id divided by 13)
       so suit will have values of 0, 1, 2, 3 (e.g., Clubs, Diamonds, Hearts,
       Spades)

    face = id % 13   ( id mod/remainder 13)
       so face will have values 0..12 (e.g., Ace, Two, Trey, ..., King)

II. Loop backward from the high value (51) to the low value (0) and
    generate a random number between 0 and 51. Switch the value of the current
    (loop counter) subscript and the random number.

>Repeat a few thousand times and you've got a nicely "shuffled" pack!

This is unnecessary and on a slow machine, time-consuming. The algorithm
shown as item # II (above) is the commonly accepted method of shuffling a
deck with software.

Besides, even in "real life", mathematics have shown it takes [at most]
seven shuffles of a deck to maximize the "randomness" of a deck of
fifty-two cards. Anything after that is overkill. Seven times is not
necessary in software, however.


-- 
 "November 5, 1996"
 ------------------------------------
 Phil Paxton :: Fishers, Indiana, USA
</PRE>


<HR><A NAME=WINAPI_MISC_REGEX>
Return to <a href="wpw_wapi_index.html#TOC">Table of Contents for this chapter</a><br>
<H4>Subject: Use Regex</H4><PRE>
Howdy, could someone help me with this? I'd really appreciate it.

I am trying to put a regular expression search menu on my windows 
application. However, there seems no regular expression library in
Visual C++ or Borland C++ (Am I right?). So I need to build one.
Actually, I don't need a library, I only need a matching or searching
function like the string searching one. Certainly this will include 
the compilation routine which converts input string to internal
regular expression representation.

The first idea came to me was to dig some useful stuff out from the 
GNU library, "regex" or "rx", but they both are too large, and have
too much consideration over emacs and Posix, etc. What I need should
be much simpler than them. So I am wondering there might be some
simpler libraries or like over the net, or some free distributed
C or C++ packages contain simpler ones. Could guru's and experts
give me a hint?

Any advice is cordially welcome.

Tons of thanks in advance.

--
<f0833913@unicorn.it.wsu.edu>
<HR>
On Tue, 20 Jun 1995 16:25:07 GMT, f0833913@unicorn.it.wsu.edu (Gopher client) said in article <DAHC9w.oII@serval.net.wsu.edu>:
>
>
>Howdy, could someone help me with this? I'd really appreciate it.
>
>I am trying to put a regular expression search menu on my windows 
>application. However, there seems no regular expression library in
>Visual C++ or Borland C++ (Am I right?). So I need to build one.


Actually, Borland C++ implements regular expressions in their string class.


--
Robert Mashlan             R2M Software Company           Programmer for Hire
mailto:rmashlan@r2m.com    http://www.csn.net/~rmashlan     PGP key available
Resources for Windows Developers    -     http://www.csn.net/~rmashlan/windev
Windows Developers FAQ    -    http://www.csn.net/~rmashlan/win-developer-FAQ

<HR>
In article <DAHC9w.oII@serval.net.wsu.edu> f0833913@unicorn.it.wsu.edu (Gopher client) writes:
>From: f0833913@unicorn.it.wsu.edu (Gopher client)
>Subject: Help asked for regex on PC
>Date: Tue, 20 Jun 1995 16:25:07 GMT

>The first idea came to me was to dig some useful stuff out from the 
>GNU library, "regex" or "rx", but they both are too large, and have
>too much consideration over emacs and Posix, etc. What I need should
>be much simpler than them. So I am wondering there might be some
>simpler libraries or like over the net, or some free distributed
>C or C++ packages contain simpler ones. Could guru's and experts
>give me a hint?

In the April 95  issue of CUJ article "Two Wildcard Matching Utilities" 
provided a simplistic wildcard matching routine.  Two  "special" characters
are defined:

    *     matches the longest possible string of any character
    ?     matches a single character

A long way from regex, but it was implemented in about 50 lines of code, so 
it meets your size criteria!

Claude.

<HR>
f0833913@unicorn.it.wsu.edu (Gopher client) wrote: 
> 
> 
>Howdy, could someone help me with this? I'd really appreciate it. 
> 
>I am trying to put a regular expression search menu on my windows  
>application. However, there seems no regular expression library in 
>Visual C++ or Borland C++ (Am I right?). So I need to build one. 
>Actually, I don't need a library, I only need a matching or searching 
>function like the string searching one. Certainly this will include  
>the compilation routine which converts input string to internal 
>regular expression representation. 
> 
>The first idea came to me was to dig some useful stuff out from the  
>GNU library, "regex" or "rx", but they both are too large, and have 
>too much consideration over emacs and Posix, etc. What I need should 
>be much simpler than them. So I am wondering there might be some 
>simpler libraries or like over the net, or some free distributed 
>C or C++ packages contain simpler ones. Could guru's and experts 
>give me a hint? 
> 
>Any advice is cordially welcome. 
> 
>Tons of thanks in advance. 
> 
>-- 
><f0833913@unicorn.it.wsu.edu> 
 
I can only offer this simple compare routine that accepts 
wildcards *, ? and #  in parameter w: 
* ... 0 or some characters 
?.....1 character 
#.....one of the digits 0-9 
it returns 1 if matching else 0 
 
int matching(char* s, char* w, int slen) 
{ 
  while (*w) 
  { 
    if (*s == 0) 
    { 
      if (*w == '*') 
      { 
        w++; 
        continue; 
      } 
      return 0; 
    } 
    else if (*w == *s) 
    { 
      w++; 
      s++; 
      slen--; 
    } 
    else if (*w == '#') 
    { 
      if (*s == 0) 
        return 0; 
      if (*s >= '0' && *s <= '9') 
      { 
        s++; 
        slen--; 
        w++; 
      } 
      else 
        return 0; 
    } 
    else if (*w == '?') 
    { 
      if (*s == 0) 
        return 0; 
      s++; 
      slen--; 
      w++; 
    } 
    else if (*w == '*') 
    { 
      w++; 
      if (*w == 0) 
        return 1; 
      while (*w) 
      { 
        if (matching(s, w, slen)) 
          return 1; 
        if (slen == 0 || *s == 0) 
          break; 
        s++; 
        slen--; 
      } 
      break; 
    } 
    else 
      return 0; 
  } 
  if (*w != 0) 
    return 0; 
  if (slen != 0 && *s != 0) 
    return 0; 
  return 1; 
} 
 
guenter 
----------------------------------------------------------------- 
Guenter Nagler  
JOANNEUM RESEARCH, Institute for HyperMedia Systems (IHM) 
Schieszstattgasse 4A, A-8010 Graz, Austria 
email: gnagler@ihm.tu-graz.ac.at 

<HR>
dcb> In article <DAHC9w.oII@serval.net.wsu.edu>
dcb> f0833913@unicorn.it.wsu.edu (Gopher client) writes:

    >> The first idea came to me was to dig some useful stuff out from the 
    >> GNU library, "regex" or "rx", but they both are too large, and have
    >> too much consideration over emacs and Posix, etc. What I need should
    >> be much simpler than them.

Get Henry Spencer's free regexp library: contains a regcomp() and
regexec() function.  It's small, relatively fast, and legally
unencumbered.  It's been around since 1986 and is just a great piece of
code.

It handles the normal constructs ("[]", ".", "*", "+", "?"), plus more
advanced ones like alternatives ("|") and grouping with "()".  It
doesn't handle all the fancy stuff that the GNU ones do, of course.

I have it running on PC's here: I think there may have been one or two
small issues with 16- vs. 32-bit when porting to the PC but mainly it
just worked.  It comes with a test suite so it shouldn't be too tough to
debug.

You should be able to find it at many archives.  One place I happen to
know about is:

  ftp.germany.eu.net:/pub/programming/lib/regexp/regexp.tar.gz

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <psmith@baynetworks.com>         Network Management Development
 Senior Software Engineer                                   Bay Networks, Inc.
-----------------------------------------------==<http://www.baynetworks.com/>-
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist
-------------------------------------------------------------------------------
     These are my opinions--Bay Networks takes no responsibility for them.

<HR>
In article <DAHC9w.oII@serval.net.wsu.edu>,
Gopher client <f0833913@unicorn.it.wsu.edu> wrote:

(Looking for regex packages)

>be much simpler than them. So I am wondering there might be some
>simpler libraries or like over the net, or some free distributed
>C or C++ packages contain simpler ones. Could guru's and experts
>give me a hint?
>
>Any advice is cordially welcome.
>
>Tons of thanks in advance.

><f0833913@unicorn.it.wsu.edu>

I've always liked Henry Spencer's implementation of regexp(3) as
a small, standalone regular expression package.

Here is the README on the copy I have.  I don't know where I got it from
originaly.
If there is a newer version than this, someone please let me know.

<f0833913@unicorn.it.wsu.edu>: I will try to mail the whole thing to you.

Steve

-----------------------------------------------------------------------------
This is a nearly-public-domain reimplementation of the V8 regexp(3) package.
It gives C programs the ability to use egrep-style regular expressions, and
does it in a much cleaner fashion than the analogous routines in SysV.

        Copyright (c) 1986 by University of Toronto.
        Written by Henry Spencer.  Not derived from licensed software.

        Permission is granted to anyone to use this software for any
        purpose on any computer system, and to redistribute it freely,
        subject to the following restrictions:

        1. The author is not responsible for the consequences of use of
                this software, no matter how awful, even if they arise
                from defects in it.

        2. The origin of this software must not be misrepresented, either
                by explicit claim or by omission.

        3. Altered versions must be plainly marked as such, and must not
                be misrepresented as being the original software.

Barring a couple of small items in the BUGS list, this implementation is
believed 100% compatible with V8.  It should even be binary-compatible,
sort of, since the only fields in a "struct regexp" that other people have
any business touching are declared in exactly the same way at the same
location in the struct (the beginning).

This implementation is *NOT* AT&T/Bell code, and is not derived from licensed
software.  Even though U of T is a V8 licensee.  This software is based on
a V8 manual page sent to me by Dennis Ritchie (the manual page enclosed
here is a complete rewrite and hence is not covered by AT&T copyright).
The software was nearly complete at the time of arrival of our V8 tape.
I haven't even looked at V8 yet, although a friend elsewhere at U of T has
been kind enough to run a few test programs using the V8 regexp(3) to resolve
a few fine points.  I admit to some familiarity with regular-expression
implementations of the past, but the only one that this code traces any
ancestry to is the one published in Kernighan & Plauger (from which this
one draws ideas but not code).

Simplistically:  put this stuff into a source directory, copy regexp.h into
/usr/include, inspect Makefile for compilation options that need changing
to suit your local environment, and then do "make r".  This compiles the
regexp(3) functions, compiles a test program, and runs a large set of
regression tests.  If there are no complaints, then put regexp.o, regsub.o,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -