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: g2news1.google.com!postnews.google.com!s20g2000yqh.googlegroups.com!not-for-mail From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: Newbie question Date: Thu, 12 Mar 2009 06:48:36 -0700 (PDT) Organization: http://groups.google.com Message-ID: <0ff2f139-06cf-4fa5-8c0d-f97c43a33186@s20g2000yqh.googlegroups.com> References: <49b90e2d$0$2847$ba620e4c@news.skynet.be> NNTP-Posting-Host: 153.98.68.197 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1236865717 5040 127.0.0.1 (12 Mar 2009 13:48:37 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 12 Mar 2009 13:48:37 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: s20g2000yqh.googlegroups.com; posting-host=153.98.68.197; posting-account=pcLQNgkAAAD9TrXkhkIgiY6-MDtJjIlC User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:4072 Date: 2009-03-12T06:48:36-07:00 List-Id: On Mar 12, 2:29=A0pm, 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 Solution 1: a variant record: type Square_T (Empty : Boolean) is record case Empty is when True =3D> null; when False =3D> Piece : Piece_T; end case; end record; type Board_T is array (1 .. 8, 1 .. 8) of Square_T; Solution 2: merge the Boolean directly into Piece_T: type Piece_T (Present : Boolean) is record case Present is when True =3D> Color : Color_T; Piece_Type : Piece_Type_T; when False =3D> null; end case; end record; Solution 3: introduce a new value for Piece_Type_T: type Piece_Type_T is (None, Pawn, Knight, Bishop, Rook, Queen, King); I don't know which is the best solution; perhaps you'd like to try them all and see how well they integrate with the algorithms. I think Solution 3 is the most error-prone, though. -- Ludovic Brenta;