[four-in-a-row] Do not use gotos to emulate return statements



commit 2dc98d70458389660df50af758553fd4d209b91f
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Tue Feb 4 21:32:19 2014 -0600

    Do not use gotos to emulate return statements
    
    Ahhh, the 90s

 src/ia_main.c |   19 +++++++++----------
 1 files changed, 9 insertions(+), 10 deletions(-)
---
diff --git a/src/ia_main.c b/src/ia_main.c
index fe1ee1a..a42084d 100644
--- a/src/ia_main.c
+++ b/src/ia_main.c
@@ -1035,7 +1035,7 @@ ia_compute_move (struct board *board)
 
   if (board->filled == 0) {
     move = 3;
-    goto IA_RETURN_MOVE;
+    return move;
   }
 
   if (board->filled == 1) {
@@ -1044,14 +1044,14 @@ ia_compute_move (struct board *board)
       move = 2;
     else if (board->moves[0] == 5)
       move = 4;
-    goto IA_RETURN_MOVE;
+    return move;
   }
 
   if (board->filled == MAXMEN - 1) {
     for (x = 0; x < BOARDX; x++) {
       if (board->stack[x] < BOARDY) {
        move = x;
-       goto IA_RETURN_MOVE;
+       return move;
       }
     }
     fatal_error ("I shouldn't have come here...");
@@ -1059,16 +1059,16 @@ ia_compute_move (struct board *board)
 
   move = try_to_win (board);
   if (move >= 0)
-    goto IA_RETURN_MOVE;
+    return move;
 
   move = avoid_immediate_loss (board);
   if (move >= 0)
-    goto IA_RETURN_MOVE;
+    return move;
 
   if (board->turn == BLACK && board->black_lev == 3) {
     move = get_black_best_move (board);
     if (move >= 0)
-      goto IA_RETURN_MOVE;
+      return move;
   }
 
   else if (board->filled == 1 && board->stack[3] == 1) {
@@ -1095,7 +1095,7 @@ ia_compute_move (struct board *board)
     } else
       move = 3;
 
-    goto IA_RETURN_MOVE;
+    return move;
   }
 
   /* Let's look in the opening book */
@@ -1120,7 +1120,7 @@ ia_compute_move (struct board *board)
   }
 
   if (move >= 0)
-    goto IA_RETURN_MOVE;
+    return move;
 
   fight (NO);
   move = heuristic_play_best (board, 2800L);
@@ -1142,11 +1142,10 @@ ia_compute_move (struct board *board)
   }
 
   if (move >= 0)
-    goto IA_RETURN_MOVE;
+    return move;
 
   move = look_ahed (board);
 
-IA_RETURN_MOVE:
   return move;
 }
 


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