From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.140.97.244 with SMTP id m107mr12686749qge.20.1459018255624; Sat, 26 Mar 2016 11:50:55 -0700 (PDT) X-Received: by 10.182.125.225 with SMTP id mt1mr165332obb.17.1459018255576; Sat, 26 Mar 2016 11:50:55 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!au2pb.net!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!y89no9521096qge.0!news-out.google.com!pn7ni16908igb.0!nntp.google.com!nt3no4819063igb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 26 Mar 2016 11:50:55 -0700 (PDT) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2601:191:8201:bb5a:5985:2c17:9409:aa9c; posting-account=fdRd8woAAADTIlxCu9FgvDrUK4wPzvy3 NNTP-Posting-Host: 2601:191:8201:bb5a:5985:2c17:9409:aa9c User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <72436e28-13a7-4580-9503-0bd7111f4bab@googlegroups.com> Subject: Playing cards. From: rieachus@comcast.net Injection-Date: Sat, 26 Mar 2016 18:50:55 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Received-Bytes: 5056 X-Received-Body-CRC: 923960565 Xref: news.eternal-september.org comp.lang.ada:29899 Date: 2016-03-26T11:50:55-07:00 List-Id: I am working on a package which provides playing cards (and a surface) for = programs that need. I'm working on a program for testing bridge bidding sy= stems. In other words to find hands that have no defined bid, or more than = one bid in a must situation. I would like to avoid using GTK if possible, to make installation easier, b= ut if anyone already has such a package no need to duplicate effort. Packa= ge spec is below. If you want to discuss the random number issues, start a= new discussion. I am sure it will get long quickly. ;-) package Cards is -- an object, model, view of a deck of cards and a playing surface. -- decks can be single or double, regular or pinocle, with or without joker= s. -- Cards can be invisible, located on the table, or in a "hand", cards may = be -- assigned to a stack or stacks on the table, and are face up or down. type Card is private; type Deck is array (Integer range <>) of Card; type Decks is (Single, Double, Single_Pinochle, Double_Pinochle, One_Joker, Two_Jokers); function Create_Deck(Deck_Type: Decks) return Deck; type Rank is (Ace, Deuce, Trey, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King); type Suit is (Spade, Heart, Diamond, Club, Joker); -- Joker rank is undefined, but can be assigned, for example when -- showing a poker hand. function Rank_Is (C: in Card) return Rank; function Suit_Is (C: in Card) return Suit; procedure Shuffle(D: in out Deck); -- all cards are set to in_hand, face_down. And -- well shuffled. Long note: A 52 card deck has 52! (~8x10^67) -- possible orders. Game mechanics lower the number of different -- deals. For example there are only 5.36x10^28 differen bridge -- deals. Obviosly, a 32-bit (around 4 billion if unsigned) -- pseudo-random number generator won't do justice. A 64-bit PRNG -- is not much better. The method used here is to use four -- different unsigned PRNGs to assign values to cards in turn, -- then sort on these values. It is a task left to the reader to -- compute what percentage of the possible bridge deals can -- actually occur. ;-) procedure Face (C: in Card); -- make a card visible; procedure Face_Down (C: in Card); -- show the back of the card if/when it is displayed. function Face_Up return Boolean; type Position is record X: Positive; Y: Positive; end record; procedure Create_Table(Far_Corner: Position :=3D (320, 320)); -- Initial value is really there it insure that tables always have sizes= . procedure Play(C: Card; P: Position); -- move the card from its current location to the table and turn it face -- up if necessary. procedure Discard(C: Card; P: Position; Display: Boolean :=3D True); -- same intent as Play but with the card face down, or completely gone -- from the display. Note that discarded cards are still part of the -- deck. procedure In_Hand(C: Card); -- place a card in the hand. function In_Hand (C: Card) return Boolean; function Hand return Deck; -- the deck in this case is an array of cards usually smaller than the -- original deck. returns a full array from 1 to n of the cards -- currently in the hand. procedure Sort_Hand (Suits: Boolean :=3D True; Up: Boolean :=3D True); -- sort the hand. Suits first if suits is true; higher ranking cards -- get higher numbers if Up is true. procedure Update; -- Update the physical display to match the current card locations. -- Fancy transition graphics optional. private type Real_Card; type Card is access all Real_Card; -- Model magic is going on here. Creating a deck does not need to -- use the heap, and will usually create an array of Real_Cards on -- the stack. When you leave the scope of a Deck, everything goes -- away in finalization. end Cards;