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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,e4042699db4db63b X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!p36g2000prp.googlegroups.com!not-for-mail From: "tmoran@acm.org" Newsgroups: comp.lang.ada Subject: Re: Newbie question Date: Thu, 12 Mar 2009 18:59:14 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <49b90e2d$0$2847$ba620e4c@news.skynet.be> NNTP-Posting-Host: 24.6.101.70 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1236909554 16417 127.0.0.1 (13 Mar 2009 01:59:14 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 13 Mar 2009 01:59:14 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: p36g2000prp.googlegroups.com; posting-host=24.6.101.70; posting-account=8G1j8QkAAABAQTolGCWUf6Arl0PZneMD User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727),gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:5065 Date: 2009-03-12T18:59:14-07:00 List-Id: On Mar 12, 5:29=A0am, Olivier Scalbert wrote: > Hello, > > I start learning Ada and I try to define types for a chess engine. > > I have create some "obvious" types: > > =A0 =A0 =A0type Color_T is (White, Black); > > =A0 =A0 =A0type PieceType_T is (Pawn, Knight, Bishop, Rook, Queen, King); > > =A0 =A0 =A0type Piece_T is record > =A0 =A0 =A0 =A0 =A0Color: Color_T; > =A0 =A0 =A0 =A0 =A0PieceType: PieceType_T; > =A0 =A0 =A0end record; > > Now, I want to create an array of 64 squares representing the chess > board. A square should contain nothing or a Piece_T > > I have tried: > > =A0 =A0 =A0type Board_T is array(1..64) of Piece_T; > > But I can not have an empty square ! > > What is the best way of doing that ? > > Thanks, > > Olivier A piece in a game is not so much a physical object as a characteristic of a particular square. You don't want to say for instance Synod : array(1 .. 5) of (Color=3D>White, Kind=3D>Bishop); ... Board(G,3) :=3D Synod(4); So how about type Occupants is (Empty, Black_King, Black_Queen, Black_Bishop, .... White_King, White_Queen, .... White_Pawn); subtype Blacks is Occupants range (Black King .. Black_Pawn); subtype Whites is Occupants range (White King .. White_Pawn); Board : array(Files, Ranks) of Occupants; then your code can say things like if Board(G,4) in Whites then ... if Board(G, 5) =3D Black_King and Board(G,6) =3D Empty then ...