[gnome-games] Removed old worm.c|h & some trivial code refactoring



commit f77557ac970726b59c6156624702769de8441359
Author: Guillaume Beland <guillaume beland gmail com>
Date:   Wed Aug 12 19:13:46 2009 -0400

    Removed old worm.c|h & some trivial code refactoring

 gnibbles/gnibbles.c     |    3 -
 gnibbles/worm-clutter.c |  109 +++----
 gnibbles/worm.c         |  920 -----------------------------------------------
 gnibbles/worm.h         |   87 -----
 4 files changed, 47 insertions(+), 1072 deletions(-)
---
diff --git a/gnibbles/gnibbles.c b/gnibbles/gnibbles.c
index 5002c99..47a3e22 100644
--- a/gnibbles/gnibbles.c
+++ b/gnibbles/gnibbles.c
@@ -263,9 +263,6 @@ gnibbles_move_worms (void)
     }
   }
 
-  printf ("head: (%d,%d), tail (%d,%d)\n", 
-          worms[0]->xhead, worms[0]->yhead, 
-          worms[0]->xtail, worms[0]->ytail);
   for (i = 0; i < properties->numworms; i++) {
     dead[i] = !gnibbles_worm_test_move_head (worms[i]);
     status &= !dead[i];
diff --git a/gnibbles/worm-clutter.c b/gnibbles/worm-clutter.c
index 44e1e64..bf2899c 100644
--- a/gnibbles/worm-clutter.c
+++ b/gnibbles/worm-clutter.c
@@ -477,9 +477,8 @@ gnibbles_worm_reset (ClutterAnimation *anim, GnibblesWorm *worm)
 {
   gint j;
 
-  for (j = 0; j < g_list_length(worm->list); j++) {
+  for (j = 0; j < g_list_length(worm->list); j++)
     gnibbles_worm_move_tail_pointer (worm);
-  }
 
   worm->xhead = worm->xstart;
   worm->yhead = worm->ystart;
@@ -492,21 +491,6 @@ gnibbles_worm_reset (ClutterAnimation *anim, GnibblesWorm *worm)
     worm->change = SLENGTH - 1;
     gnibbles_worm_show (worm);
   }
-  /* DEBUG *//*
-  gint i;
-  FILE *fo;
-  fo = fopen ("output.txt", "w" );
-  for (i = 0; i < BOARDHEIGHT; i++) {
-    for (j = 0; j < BOARDWIDTH; j++) {
-      if (board->walls[j][i] == 'a')
-        fprintf(fo, "%c", ' ');
-      else
-        fprintf (fo , "%c", board->walls[j][i]);
-    }
-    fprintf (fo, "\n");
-  }
-  fclose (fo); 
-  */
 }
 
 GnibblesWorm*
@@ -556,11 +540,6 @@ gnibbles_worm_destroy (GnibblesWorm *worm)
 {
   while (worm->list)
     gnibbles_worm_remove_actor (worm);
-
-  //if (worm->list)
-  //  g_list_free (worm->list);
-
-  //g_free (worm);
 }
 
 void
@@ -832,18 +811,18 @@ gnibbles_worm_ai_deadend (gint x, gint y, gint lengthleft)
     cx = x;
     cy = y;
     switch (cdir) {
-    case WORMUP:
-      cy -= 1;
-      break;
-    case WORMDOWN:
-      cy += 1;
-      break;
-    case WORMLEFT:
-      cx -= 1;
-      break;
-    case WORMRIGHT:
-      cx += 1;
-      break;
+      case WORMUP:
+        cy -= 1;
+        break;
+      case WORMDOWN:
+        cy += 1;
+        break;
+      case WORMLEFT:
+        cx -= 1;
+        break;
+      case WORMRIGHT:
+        cx += 1;
+        break;
     }
 
     if (cx >= BOARDWIDTH)
@@ -897,28 +876,32 @@ gnibbles_worm_ai_deadend_after (gint x, gint y, gint dir, gint length)
     cx = worms[i]->xhead;
     cy = worms[i]->yhead;
     if(cx != x || cy != y) {
-      if(cx > 0) deadendboard[cx-1][cy] = deadend_runnumber;
-      if(cy > 0) deadendboard[cx][cy-1] = deadend_runnumber;
-      if(cx < BOARDWIDTH-1) deadendboard[cx+1][cy] = deadend_runnumber;
-      if(cy < BOARDHEIGHT-1) deadendboard[cx][cy+1] = deadend_runnumber;
+      if(cx > 0) 
+        deadendboard[cx-1][cy] = deadend_runnumber;
+      if(cy > 0) 
+        deadendboard[cx][cy-1] = deadend_runnumber;
+      if(cx < BOARDWIDTH-1) 
+        deadendboard[cx+1][cy] = deadend_runnumber;
+      if(cy < BOARDHEIGHT-1) 
+        deadendboard[cx][cy+1] = deadend_runnumber;
     }
   }
 
   cx = x;
   cy = y;
   switch (dir) {
-  case WORMUP:
-    cy -= 1;
-    break;
-  case WORMDOWN:
-    cy += 1;
-    break;
-  case WORMLEFT:
-    cx -= 1;
-    break;
-  case WORMRIGHT:
-    cx += 1;
-    break;
+    case WORMUP:
+      cy -= 1;
+      break;
+    case WORMDOWN:
+      cy += 1;
+      break;
+    case WORMLEFT:
+      cx -= 1;
+      break;
+    case WORMRIGHT:
+      cx += 1;
+      break;
   }
 
   if (cx >= BOARDWIDTH)
@@ -1017,7 +1000,8 @@ gnibbles_worm_ai_wander (gint x, gint y, gint dir, gint ox, gint oy)
       return 0;
       break;
     default: 
-      if (board->walls[x][y] > EMPTYCHAR && board->walls[x][y] < 'z' + properties->numworms) {
+      if (board->walls[x][y] > EMPTYCHAR 
+          && board->walls[x][y] < 'z' + properties->numworms) {
         return 0;
       } else {
         if (ox == x && oy == y)
@@ -1037,12 +1021,14 @@ gnibbles_worm_ai_move (GnibblesWorm * worm)
 
   opposite = (worm->direction + 1) % 4 + 1;
 
-  front = gnibbles_worm_ai_wander
-    (worm->xhead, worm->yhead, worm->direction, worm->xhead, worm->yhead);
-  left = gnibbles_worm_ai_wander
-    (worm->xhead, worm->yhead, worm->direction - 1, worm->xhead, worm->yhead);
-  right = gnibbles_worm_ai_wander
-    (worm->xhead, worm->yhead, worm->direction + 1, worm->xhead, worm->yhead);
+  front = gnibbles_worm_ai_wander (worm->xhead, worm->yhead,
+                                   worm->direction, worm->xhead, worm->yhead);
+  left = gnibbles_worm_ai_wander (worm->xhead, worm->yhead, 
+                                  worm->direction - 1, 
+                                  worm->xhead, worm->yhead);
+  right = gnibbles_worm_ai_wander (worm->xhead, worm->yhead, 
+                                   worm->direction + 1, 
+                                   worm->xhead, worm->yhead);
 
   if (!front) {
     if (left) {
@@ -1103,8 +1089,8 @@ gnibbles_worm_ai_move (GnibblesWorm * worm)
     if(!gnibbles_worm_is_move_safe (worm))
       thislen += 4;
 
-    thislen += gnibbles_worm_ai_deadend_after
-      (worm->xhead, worm->yhead, dir, worm->length + worm->change);
+    thislen += gnibbles_worm_ai_deadend_after (worm->xhead, worm->yhead, dir,
+                                               worm->length + worm->change);
 
     if (dir == olddir && !thislen)
       thislen -= 100;
@@ -1130,10 +1116,9 @@ gnibbles_worm_ai_move (GnibblesWorm * worm)
   for (dir = 1; dir <= 4; dir++) {
     if (dir == opposite) 
       continue;
-    if (!gnibbles_worm_test_move_head (worm)) {
+    if (!gnibbles_worm_test_move_head (worm))
       worm->direction = dir;
-    } else {
+    else
       continue;
-    }
   }
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]