-
Notifications
You must be signed in to change notification settings - Fork 0
/
board_package.ads
59 lines (51 loc) · 2.54 KB
/
board_package.ads
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
generic
Side_Width : Positive;
Initial_Seeds : Positive;
type Player_T is (<>);
package Board_Package is
Num_Players : constant Positive :=
Player_T'Pos (Player_T'Last) - Player_T'Pos (Player_T'First) + 1;
subtype Side_Index is Integer range 1 .. Side_Width;
subtype Seed_Count is Integer range 0 .. Initial_Seeds * Side_Width * Num_Players;
type Side_T is array (Side_Index) of Seed_Count;
subtype Pond_T is Seed_Count;
type Sides_T is array (Player_T) of Side_T;
type Ponds_T is array (Player_T) of Pond_T;
type Board_T is tagged record
Sides : Sides_T;
Ponds : Ponds_T;
end record;
type Board_Index is record
Player : Player_T;
Is_Pond : Boolean;
Side_Idx : Side_Index;
end record;
function Next (Player : Player_T) return Player_T;
function Total_Seeds (Board : in Board_T) return Seed_Count;
function Valid_Move (Board : in Board_T; Board_Idx : Board_Index) return Boolean;
procedure Move (Board : in out Board_T; Player : in Player_T; Choice : in Side_Index; Next_Player : out Player_T) with
Pre => Board.Total_Seeds = Seed_Count'Last,
Post => Board.Total_Seeds = Seed_Count'Last;
procedure Move (Board : in out Board_T; Board_Idx : Board_Index; Next_Player : out Player_T) with
Pre => Board.Total_Seeds = Seed_Count'Last,
Post => Board.Total_Seeds = Seed_Count'Last;
function Finished (Board : Board_T) return Boolean;
function Winner (Board : Board_T) return Player_T;
function Is_Capture (Board : in Board_T; Board_Idx : in Board_Index) return Boolean;
procedure Reset (Board : in out Board_T);
function Get (Board : in Board_T; Board_Idx : in Board_Index) return Seed_Count;
procedure Set (Board : in out Board_T; Board_Idx : in Board_Index; Value : Seed_Count);
procedure Add (Board : in out Board_T; Board_Idx : in Board_Index; Value : Seed_Count);
procedure Inc (Board : in out Board_T; Board_Idx : in Board_Index);
function Next (Board_Idx : Board_Index; Player : in Player_T) return Board_Index;
procedure Next (Board_Idx : in out Board_Index; Player : in Player_T);
function To_String (Board : in Board_T) return String;
function To_String (Board_Idx : in Board_Index) return String;
function Pretty_String (Board : in Board_T; Player : Player_T) return String;
Initial_Board : constant Board_T :=
(Sides => (others => (others => Initial_Seeds)),
Ponds => (others => Pond_T'First));
Game_Not_Finished : exception;
Invalid_Board_Index : exception;
Too_Many_Players : exception;
end Board_Package;