Vanilla Development Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CVS update: Vanilla/robots



Date:	Wednesday June 7, 2000 @ 15:41
Author:	ahn

Update of /home/netrek/cvsroot/Vanilla/robots
In directory swashbuckler.fortress.real-time.com:/var/tmp/cvs-serv14928

Modified Files:
	inl.c inlcmds.c inlcomm.c inldefs.h 
Log Message:
Changes by Dave Ahn.


****************************************

Index: Vanilla/robots/inl.c
diff -u Vanilla/robots/inl.c:1.30 Vanilla/robots/inl.c:1.31
--- Vanilla/robots/inl.c:1.30	Mon May 15 16:39:25 2000
+++ Vanilla/robots/inl.c	Wed Jun  7 15:41:17 2000
@@ -1,7 +1,7 @@
-/* 	$Id: inl.c,v 1.30 2000/05/15 21:39:25 ahn Exp $	 */
+/* 	$Id: inl.c,v 1.31 2000/06/07 20:41:17 ahn Exp $	 */
 
 #ifndef lint
-static char vcid[] = "$Id: inl.c,v 1.30 2000/05/15 21:39:25 ahn Exp $";
+static char vcid[] = "$Id: inl.c,v 1.31 2000/06/07 20:41:17 ahn Exp $";
 #endif /* lint */
 
 /*
@@ -114,6 +114,8 @@
   0,			/* tmout_ticks */
   0,			/* time */
   0,			/* overtime */
+  0,			/* score_mode */
+  0.0			/* weighted_divisor */
 };
 
 Inl_countdown inl_countdown =
@@ -597,7 +599,27 @@
 void update_scores() {
 
   int p, t;
+  double weight = (double) inl_stat.game_ticks / (double) inl_stat.time;
 
+  if (weight < 0.0)
+    weight = 0.0;
+  else if (weight > 1.0)
+    weight = 1.0;
+
+  /* weight = linear range between 0.0 and 1.0 during regulation.
+   * map this to 0.75 <-> 1.5 range
+   * -da */
+
+  weight = 0.75 + (0.75 * weight);
+
+  /* sanity check */
+  if (weight < 0.75)
+    weight = 0.75;
+  else if (weight > 1.5)
+    weight = 1.5;
+
+  inl_stat.weighted_divisor += (weight * 4.0);
+
   for (p=0; p<MAXPLANETS; p++) {
 
     for(t=0; t<INLTEAM; t++) {
@@ -616,13 +638,13 @@
         inl_teams[t].abs_score += points;
 
         /* semi-continuous score is just the cumulative point total with
-           a 5 minute interval */
-        if ((inl_stat.game_ticks % (5 * PERMIN)) == 0)
+           a 1 minute interval */
+        if ((inl_stat.game_ticks % PERMIN) == 0)
           inl_teams[t].semi_score += points;
 
         /* weighted continuous score is a cumulative total of points
            measured in a linearly decreasing interval */
-        /* inl_teams[t].weighted_score += ;*/
+        inl_teams[t].weighted_score += (weight * (double) points);
 
       }
 
@@ -630,9 +652,9 @@
 
   }
 
-  /* announce updated scores every 15 minutes */
+  /* announce updated scores every 5 minutes */
 
-  if ((inl_stat.game_ticks % (15 * PERMIN)) == 0)
+  if ((inl_stat.game_ticks % (5 * PERMIN)) == 0)
     announce_scores(0, MALL);
 
 }
@@ -711,20 +733,88 @@
 }
 #endif
 
+/* Determine if there is a winner at the end of regulation.
+   returns 0 if game is tied
+   returns 1 if there is a winner by planet count
+   returns 2 if there is a winner by continuous score > 0.5
+   returns 3 if there is a winner by continuous score < 0.5 & planet 11-8-1
+   -da
+ */
+int check_winner() {
+  double divisor = inl_stat.weighted_divisor;
+  double delta;
+
+  /* NORMAL scoring mode; OR, continuous scoring and in OT.
+     Use absolute planet count. */
+  if ((inl_stat.score_mode == 0) || (inl_stat.flags & S_OVERTIME)) {
+    if (inl_teams[HOME].planets > inl_teams[AWAY].planets + 2)
+      return 1;
+    else if (inl_teams[AWAY].planets > inl_teams[HOME].planets + 2)
+      return 1;
+    else
+      return 0;
+  }
+
+  /* CONTINUOUS scoring mode */
+
+  /* sanity check */
+  if (inl_stat.weighted_divisor < 1.0)
+    return 0;
+
+  if (inl_stat.game_ticks < 100)
+    return 0;
+
+  delta = inl_teams[0].weighted_score / divisor -
+          inl_teams[1].weighted_score / divisor;
+
+  /* multiply by -1 instead of fabs() */
+  if (delta < 0.0)
+    delta *= -1.0;
+
+  /* if continuous score delta is >= 0.5, we have winner */
+  if (delta >= 0.5)
+    return 2;
+
+  /* if continuous score detla is < 0.5, but a team has > 11-8-1,
+     we have a winner */
+  else if ((inl_teams[HOME].planets > inl_teams[AWAY].planets + 2) ||
+           (inl_teams[AWAY].planets > inl_teams[HOME].planets + 2))
+    return 3;
+
+  /* otherwise, game is a tie */
+  return 0;
+}
+
 int
 end_tourney()
 {
   int game_over = 0;
+  int win_cond;
 
   countplanets();
-  if ((inl_teams[HOME].planets > inl_teams[AWAY].planets+2)
-      || (inl_teams[AWAY].planets > inl_teams[HOME].planets+2))
+  if ((win_cond = check_winner()) != 0)
     {
       pmessage(0, MALL, inl_from, "---------- Game Over ----------");
       pmessage(0, MALL, inl_from, "Result: %i - %i - %i",
 	       inl_teams[HOME].planets, inl_teams[AWAY].planets,
 	       (20 - inl_teams[HOME].planets - inl_teams[AWAY].planets));
       announce_scores(0, MALL);
+
+      switch(win_cond) {
+        case 1:
+          pmessage(0, MALL, inl_from, "Winning condition: planet count");
+          break;
+        case 2:
+          pmessage(0, MALL, inl_from, "Winning condition: continuous score >= 0.5");
+          break;
+        case 3:
+          pmessage(0, MALL, inl_from, "Winning condition: score < 0.5, planet count");
+          break;
+        default:
+          pmessage(0, MALL, inl_from, "Winning condition: UNKNOWN");
+          break;
+      }
+ 
       game_over = 1;
     }
 
@@ -773,6 +863,10 @@
 
     status->tourn = 0;
 
+    /* Tourn off t-mode */
+    status->gameup |= (GU_CHAOS | GU_PRACTICE);
+    status->gameup &= ~(GU_PAUSED);
+
     gettimeofday(&tv, (struct timezone *) 0);
     fprintf(inl_log, "TIME: Game ending at %d seconds\n", tv.tv_sec);
     fclose(inl_log);
@@ -893,6 +987,8 @@
   inl_stat.tmout_ticks = 0;
   inl_stat.time = 90 * PERMIN;
   inl_stat.overtime = 30 * PERMIN;
+  inl_stat.score_mode = 0;
+  inl_stat.weighted_divisor = 0.0;
 
   inl_teams[HOME].team = HOME;
   inl_teams[HOME].name = "home";
@@ -906,9 +1002,10 @@
   inl_teams[HOME].flags = 0;
   inl_teams[HOME].tmout = 1;
   inl_teams[HOME].planets = 10;
+  inl_teams[HOME].score_mode = 0;
   inl_teams[HOME].abs_score = 0;
   inl_teams[HOME].semi_score = 0;
-  inl_teams[HOME].weighted_score = 0;
+  inl_teams[HOME].weighted_score = 0.0;
 
   inl_teams[AWAY].team = AWAY;
   inl_teams[AWAY].name = "away";
@@ -922,9 +1019,10 @@
   inl_teams[AWAY].flags = 0;
   inl_teams[AWAY].tmout = 1;
   inl_teams[AWAY].planets = 10;
+  inl_teams[AWAY].score_mode = 0;
   inl_teams[AWAY].abs_score = 0;
   inl_teams[AWAY].semi_score = 0;
-  inl_teams[AWAY].weighted_score = 0;
+  inl_teams[AWAY].weighted_score = 0.0;
 
   /* Set player queues back to standard starting teams */
   if (is_end_tourney) {
@@ -1196,6 +1294,9 @@
   *(tmp + 15) = '\0';
   pmessage (0, MALL, inl_from, "%s is the starting time of t-mode play.",
 	    tmp);
+
+  if (inl_stat.score_mode)
+    pmessage(0, MALL, inl_from, "Continuous scoring enabled.");
 
   doResources(0);
 
Index: Vanilla/robots/inlcmds.c
diff -u Vanilla/robots/inlcmds.c:1.6 Vanilla/robots/inlcmds.c:1.7
--- Vanilla/robots/inlcmds.c:1.6	Mon May 15 19:57:37 2000
+++ Vanilla/robots/inlcmds.c	Wed Jun  7 15:41:17 2000
@@ -42,6 +42,7 @@
 extern int do_timeout();
 extern int do_confine();
 extern int do_cscore();
+extern int do_scoremode();
 
 extern int cleanup();
 
@@ -165,6 +166,10 @@
     C_PR_INGAME,
     "Shows the INL continuous score.",
     do_cscore },			/* SCORE */
+  { "SCOREMODE",
+    C_PR_CAPTAIN | C_PR_PREGAME,
+    "Switch scoring mode for winning condition.",
+    do_scoremode },
 #if defined(AUTO_INL)
   { "The following votes can be used:	 (M=Majority, T=Team vote)", C_DESC },
   { "EXIT",
Index: Vanilla/robots/inlcomm.c
diff -u Vanilla/robots/inlcomm.c:1.15 Vanilla/robots/inlcomm.c:1.16
--- Vanilla/robots/inlcomm.c:1.15	Mon May 15 19:57:37 2000
+++ Vanilla/robots/inlcomm.c	Wed Jun  7 15:41:17 2000
@@ -38,6 +38,7 @@
 extern char	*addr_mess(int who, int type);
 extern int	doResources();
 extern void	inl_freeze();
+extern int	check_winner();
 
 int
 check_player(who, captain)
@@ -1031,34 +1032,72 @@
 }
 
 void announce_scores(int who, int flag) {
+  int win_cond;
 
   float divisor  = (float) (inl_stat.game_ticks * 4);
 
   if (inl_stat.game_ticks < 1)
     return;
 
+  if (inl_stat.weighted_divisor < 1.0)
+    return;
+
+  pmessage(who, flag, addr_mess(who, flag),
+           "Score: %s vs %s  %.2f - %.2f (weighted)",
+           sides[inl_teams[0].side_index].name,
+           sides[inl_teams[1].side_index].name,
+           (float) inl_teams[0].weighted_score / inl_stat.weighted_divisor,
+           (float) inl_teams[1].weighted_score / inl_stat.weighted_divisor);
+
+
   if (divisor < 1.0f)
     divisor = 1.0f;
 
   pmessage(who, flag, addr_mess(who, flag),
-           "Score: %s vs %s  %.2f - %.2f (continuous)",
+           "Debug: %s vs %s  %.2f - %.2f (continuous)",
            sides[inl_teams[0].side_index].name,
            sides[inl_teams[1].side_index].name,
            (float) inl_teams[0].abs_score / divisor,
            (float) inl_teams[1].abs_score / divisor);
 
-  divisor = (float) ((inl_stat.game_ticks / (5 * PERMIN)) * 4);
+  divisor = (float) ((inl_stat.game_ticks / PERMIN) * 4);
 
   if (divisor <= 1.0f)
     divisor = 1.0f;
 
   pmessage(who, flag, addr_mess(who, flag),
-           "Score: %s vs %s  %.2f - %.2f (semi-continuous)",
+           "Debug: %s vs %s  %.2f - %.2f (semi-continuous)",
            sides[inl_teams[0].side_index].name,
            sides[inl_teams[1].side_index].name,
            (float) inl_teams[0].semi_score / divisor,
            (float) inl_teams[1].semi_score / divisor);
 
+
+  if ((win_cond = check_winner()) != 0) {
+
+    char *side;
+
+    side = (inl_teams[0].weighted_score > inl_teams[1].weighted_score)?
+            sides[inl_teams[0].side_index].name:
+            sides[inl_teams[1].side_index].name;
+
+    switch(win_cond) {
+      case 1:
+        /* ignore NORMAL scoring mode */
+        break;
+      case 2:
+        pmessage(who, flag, addr_mess(who, flag),
+          "%s is winning by score >= 0.5", side);
+        break;
+      case 3:
+        pmessage(who, flag, addr_mess(who, flag),
+          "%s is winning by score < 0.5 but planet > 11-8-1 ", side);
+        break;
+    }
+  }
+  else
+    pmessage(who, flag, addr_mess(who, flag), "Game is tied.");
+
 }
 
 int do_cscore(char *comm, struct message *mess) {
@@ -1066,5 +1105,36 @@
   announce_scores(mess->m_from, MINDIV);
 
   return 1;
+}
+
+int do_scoremode(char *comm, struct message *mess) {
+
+  int who, team;
+  char *mode;
+
+  who = mess->m_from;
+
+  if (!inl_stat.change) {
+    pmessage(who, MINDIV, addr_mess(who, MINDIV),
+             "Can't switch scoring modes.  The game has started.");
+    return 0;
+  }
+
+  team = check_player(who, 1);
+
+  if (inl_teams[team].score_mode)
+    inl_teams[team].score_mode = 0;
+  else
+    inl_teams[team].score_mode = 1;
+
+  mode = (inl_teams[team].score_mode? "CONTINUOUS": "NORMAL");
+
+  pmessage(0, MALL, inl_from, "%s requests %s scoring mode.",
+           players[who].p_mapchars, mode);
+
+  if (inl_teams[HOME].score_mode == inl_teams[AWAY].score_mode) {
+    pmessage(0, MALL, inl_from, "%s scoring mode approved.  See MOTD.", mode);
+    inl_stat.score_mode = inl_teams[HOME].score_mode;
+  }
 }
 
Index: Vanilla/robots/inldefs.h
diff -u Vanilla/robots/inldefs.h:1.3 Vanilla/robots/inldefs.h:1.4
--- Vanilla/robots/inldefs.h:1.3	Mon May 15 16:39:26 2000
+++ Vanilla/robots/inldefs.h	Wed Jun  7 15:41:17 2000
@@ -92,9 +92,10 @@
 	int	planets;		/* number of planets owned */
 					/* see README.scores for details
 					   on continuous scoring.  -da */
+	char	score_mode;		/* scoring mode */
 	int	abs_score;		/* absolute continuous score */
 	int	semi_score;		/* semi-continuous score */
-	int	weighted_score;		/* weighted continuous score */
+	double	weighted_score;		/* weighted continuous score */
 } Team;
 
 typedef struct _inl_stat {
@@ -105,6 +106,8 @@
 	int     game_ticks;             /* ticks in official game */
 	int     tmout_ticks;
 	int	time, overtime;
+	int	score_mode;
+	double	weighted_divisor;
 } Inl_stats;