Still more changes to gwars

Christopher Rodd SPEIRS crs at students.cs.mu.oz.au
Wed Feb 19 11:00:33 AEDT 1997


Thomas,
	Here are a couple of changes to gwars, for your reviewing.

Added a "PlayerPlanetSeparation" global variable, which defines the minimum
distance between a player and a planet.
Changed the create_ships function, to decrease the player separation
if gwars was having trouble fitting all the players on the screen.  
Added a "MinimumPlayerSeparation" global, so that players cant end up too
close

gwars/gwars.m:
	Added MinimumPlayerSeparation and PlayerPlanetSeparation global
	variables

gwars/objects.m:
	Changed create_planets, create_intersecting, and create_ships so
	that they use the new variables

Index: gwars.m
===================================================================
RCS file: /home/staff/zs/imp/gwars/gwars.m,v
retrieving revision 1.2
diff -u -r1.2 gwars.m
--- gwars.m	1997/02/18 04:41:45	1.2
+++ gwars.m	1997/02/18 23:36:41
@@ -15,7 +15,17 @@
 	init_globals,
 	set_global("NumPlanets", 20),
 	set_global("PlayerRad", 3.0),
+	% this is the default distance between players
 	set_global("PlayerSeparation", 55.0),
+	% This is the minimum distance between players.
+	% If gwars is having difficulty fitting all the players on
+	% the board (this happens when there are more than 5 players)
+	% then it will decrease the Player Separation to this minimum level
+	% with the MinSeparation on 20, gwars can handle about 30 players
+	set_global("MinPlayerSeparation", 20.0),
+	% PlayerPlanetSeparation is the minimum distance between a player 
+	% and a planet
+	set_global("PlayerPlanetSeparation", 5.0),
 	{ init_playerparams(Params) },
 	set_global("PlayerParams", Params),
 	set_global("PlayField", playfield(-100.0, 100.0, -100.0, 100.0)),
Index: objects.m
===================================================================
RCS file: /home/staff/zs/imp/gwars/objects.m,v
retrieving revision 1.3
diff -u -r1.3 objects.m
--- objects.m	1997/02/18 22:22:02	1.3
+++ objects.m	1997/02/18 23:46:41
@@ -76,6 +76,7 @@
 	get_global("RadRange", RadRange),
 	get_global("Ships", Ships),
 	get_global("Rnd", Rnd0),
+	get_global("PlayerPlanetSeparation", PlayerPlanetSep),
 	{ copy(Rnd0, Rnd1) },
 	{ Lambda = lambda([Line::out] is nondet, (
 		list__member(Ship0, Ships),
@@ -93,19 +94,19 @@
 	)) },
 	{ solutions(Lambda, Lines) },
 	{ list__length(Lines, Intersecting) },
-	{ create_intersecting(Lines, PlayField, RadRange, Ships,
-			[], Planets0, Rnd1, Rnd2) },
-	{ create_planets(NumPlanets - Intersecting, PlayField, RadRange, Ships,
-		Planets0, Planets, Rnd2, Rnd) },
+	{ create_intersecting(Lines, PlayField, PlayerPlanetSep,
+			RadRange, Ships, [], Planets0, Rnd1, Rnd2) },
+	{ create_planets(NumPlanets - Intersecting, PlayField, PlayerPlanetSep,
+		RadRange, Ships, Planets0, Planets, Rnd2, Rnd) },
 	set_global("Rnd", Rnd),
 	set_global("Planets", Planets).
 
-:- pred create_intersecting(list(line), playfield, radrange, list(ship),
+:- pred create_intersecting(list(line), playfield, float, radrange, list(ship),
 		list(planet), list(planet), random__supply, random__supply).
-:- mode create_intersecting(in, in, in, in, in, out, mdi, muo) is det.
+:- mode create_intersecting(in, in, in, in, in, in, out, mdi, muo) is det.
 
-create_intersecting([], _, _, _, Planets, Planets, Rnd, Rnd).
-create_intersecting([L|Ls], PlayField, RadRange, Ships,
+create_intersecting([], _, _, _, _, Planets, Planets, Rnd, Rnd).
+create_intersecting([L|Ls], PlayField, PlayerPlanetSep, RadRange, Ships,
 		Planets0, Planets, Rnd0, Rnd) :-
 	rnd(D0, Rnd0, Rnd1),
 	L = line(Xmin, Xmax, Ymin, Ymax),
@@ -129,23 +130,24 @@
 				list__member(S, Ships),
 				S = ship(X1, Y1, R1, _),
 				Dist = sqrt(sqr(X - X1) + sqr(Y - Y1)),
-				Dist < R + R1*1.1
+				Dist < R + R1 + PlayerPlanetSep
 			)
 		)
 	->
-		create_intersecting([L|Ls], PlayField, RadRange, Ships,
-			Planets0, Planets, Rnd3, Rnd)
+		create_intersecting([L|Ls], PlayField, PlayerPlanetSep,
+			RadRange, Ships, Planets0, Planets, Rnd3, Rnd)
 	;
 		NewPlanet = planet(X, Y, R),
-		create_intersecting(Ls, PlayField, RadRange, Ships,
-				[NewPlanet|Planets0], Planets, Rnd3, Rnd)
+		create_intersecting(Ls, PlayField, PlayerPlanetSep, RadRange, 
+			Ships, [NewPlanet|Planets0], Planets, Rnd3, Rnd)
 	).
 
-:- pred create_planets(int, playfield, radrange, list(ship),
+:- pred create_planets(int, playfield, float, radrange, list(ship),
 		list(planet), list(planet), random__supply, random__supply).
-:- mode create_planets(in, in, in, in, in, out, mdi, muo) is det.
+:- mode create_planets(in, in, in, in, in, in, out, mdi, muo) is det.
 
-create_planets(N, PlayField, RadRange, Ships, Ps0, Ps, Rnd0, Rnd) :-
+create_planets(N, PlayField, PlayerPlanetSep, RadRange, Ships, Ps0, Ps, 
+		Rnd0, Rnd) :-
 	(
 		N =< 0
 	->
@@ -175,16 +177,17 @@
 					list__member(S, Ships),
 					S = ship(X1, Y1, R1, _),
 					Dist = sqrt(sqr(X - X1) + sqr(Y - Y1)),
-					Dist < R + R1*1.1
+					Dist < R + R1 + PlayerPlanetSep
 				)
 			)
 		->
-			create_planets(N, PlayField, RadRange, Ships,
-				Ps0, Ps, Rnd3, Rnd)
+			create_planets(N, PlayField, PlayerPlanetSep,
+				RadRange, Ships, Ps0, Ps, Rnd3, Rnd)
 		;
 			NewPlanet = planet(X, Y, R),
-			create_planets(N-1, PlayField, RadRange, Ships,
-					[NewPlanet|Ps0], Ps, Rnd3, Rnd)
+			create_planets(N-1, PlayField, PlayerPlanetSep, 
+				RadRange, Ships, [NewPlanet|Ps0], Ps, 
+				Rnd3, Rnd)
 		)
 	).
 
@@ -197,19 +200,21 @@
 	get_global("PlayField", PlayField),
 	get_global("PlayerRad", PlayerRad),
 	get_global("PlayerSeparation", PlayerSeparation),
+	get_global("MinPlayerSeparation", MinPlayerSeparation),
 	get_global("Rnd", Rnd0),
 	{ copy(Rnd0, Rnd1) },
-	{ create_ships(Players, PlayField, PlayerRad, PlayerSeparation,
-		[], Ships, Rnd1, Rnd) },
+	{ create_ships(Players, PlayField, PlayerRad, PlayerSeparation, 
+		MinPlayerSeparation, [], Ships, Rnd1, Rnd) },
 	set_global("Rnd", Rnd),
 	set_global("Ships", Ships).
 
-:- pred create_ships(list(player), playfield, float, float,
+:- pred create_ships(list(player), playfield, float, float, float, 
 		list(ship), list(ship), random__supply, random__supply).
-:- mode create_ships(in, in, in, in, in, out, mdi, muo) is det.
+:- mode create_ships(in, in, in, in, in, in, out, mdi, muo) is det.
 
-create_ships([], _PlayField, _Radius, _Sep, Ps, Ps, Rnd, Rnd).
-create_ships([Player|Players], PlayField, Radius, Sep, Ps0, Ps, Rnd0, Rnd) :-
+create_ships([], _PlayField, _Radius, _Sep, _MinSep, Ps, Ps, Rnd, Rnd).
+create_ships([Player|Players], PlayField, Radius, Sep, MinSep, Ps0, Ps, Rnd0, 
+		Rnd) :-
 	rnd(X0, Rnd0, Rnd1),
 	rnd(Y0, Rnd1, Rnd2),
 	PlayField = playfield(Xmin, Xmax, Ymin, Ymax),
@@ -224,11 +229,16 @@
 			)
 		)
 	->
-		create_ships([Player|Players], PlayField, Radius, Sep,
+		( Sep < MinSep ->
+			Sep1 = Sep
+		;
+			Sep1 = Sep - 0.1
+		),
+		create_ships([Player|Players], PlayField, Radius, Sep1, MinSep,
 			Ps0, Ps, Rnd2, Rnd)
 	;
 		NewShip = ship(X, Y, Radius, Player),
-		create_ships(Players, PlayField, Radius, Sep,
+		create_ships(Players, PlayField, Radius, Sep, MinSep,
 				[NewShip|Ps0], Ps, Rnd2, Rnd)
 	).
 



More information about the developers mailing list