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=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,aa7f494bf30adbc7 X-Google-Attributes: gid103376,public Path: g2news1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Roland Illig Newsgroups: comp.lang.ada Subject: Re: [newbie] simple(?) data structures Date: Wed, 16 Jun 2004 13:08:41 +0200 Message-ID: <2jao1qFvj2rgU1@uni-berlin.de> References: <2j1e30Fsrg8vU1@uni-berlin.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de 8K/R/J6pyphaFICXwZXg2ATV08zODTYCjGNx8LoBtGd1z+4DQ= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040528 Debian/1.6-7 X-Accept-Language: de-de, de, en-us, en In-Reply-To: <2j1e30Fsrg8vU1@uni-berlin.de> Xref: g2news1.google.com comp.lang.ada:1566 Date: 2004-06-16T13:08:41+02:00 List-Id: Roland Illig wrote: > Hi, > > I'm doing my first steps with Ada. I tried to model a Go board and > failed. In Java/C++, I would do it like this: > > enum Stone { Empty, Black, White }; > > class Go_Board { > ... > } > > How can I do this in Ada? I already tried something with packages and > generics, but that did not look nice. But I want it to look nice and > Adaish. Many thanks for all your help. As I'm just an Ada beginner, I'll stick to something simple. No packages, no inheritance. Perhaps it will evolve later. My first try is: with Ada.Finalization; package Go is type Stone is (Empty, Black, White); type Player is (Black, White); Other : constant array (Player) of Player := (Black => White, White => Black); To_Stone : constant array (Player) of Stone := (Black => Black, White => White); type Move is private; Pass_Move : constant Move; type Board (Size : Positive) is private; function Get_Stone (The_Board : Board; X, Y : Positive) return Stone; procedure Do_Move (The_Board : in out Board; The_Move : in Move); -- ... private type Move is record Pass : Boolean := False; X, Y : Positive; end record; Pass_Move : constant Move := (Pass => True, X => 1, Y => 1); type Stone_Array is array (Positive range <>, Positive range <>) of Stone; type Stone_Array_Access is access Stone_Array; type Board (Size : Positive) is new Ada.Finalization.Controlled with record The_Size : Natural := Size; Current_Player : Player := Black; Stones : Stone_Array_Access; end record; procedure Initialize(The_Board : in out Board); procedure Finalize(The_Board : in out Board); end Go; -- Roland