[iagno] Disable some asserts.



commit 8a49070be753b4cf8a9652a66becd78c600182b8
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Wed May 15 11:16:35 2019 +0200

    Disable some asserts.

 src/computer-reversi.vala | 34 ++++++++++++++++++----------------
 src/game.vala             | 38 +++++++++++++++++++-------------------
 2 files changed, 37 insertions(+), 35 deletions(-)
---
diff --git a/src/computer-reversi.vala b/src/computer-reversi.vala
index 62b20f7..9681482 100644
--- a/src/computer-reversi.vala
+++ b/src/computer-reversi.vala
@@ -252,16 +252,18 @@ private abstract class ComputerReversi : ComputerPlayer
         SList<PossibleMove?> moves;
         g.get_possible_moves (out moves);
 
-        int32 length = (int32) moves.length ();
-        if (length <= 0)
-            assert_not_reached ();
-
-        int32 i = Random.int_range (0, length);
-        unowned PossibleMove? move = moves.nth_data ((uint) i);
-
-        if (move == null)
-            assert_not_reached ();
-        random_move = (!) move;
+     // int32 length = (int32) moves.length ();
+     // if (length <= 0)
+     //     assert_not_reached ();
+     //
+     // int32 i = Random.int_range (0, length);
+     // unowned PossibleMove? move = moves.nth_data ((uint) i);
+     //
+     // if (move == null)
+     //     assert_not_reached ();
+     // random_move = (!) move;
+
+        random_move = (!) moves.nth_data ((uint) Random.int_range (0, (int32) moves.length ()));
     }
 
     /*\
@@ -269,7 +271,7 @@ private abstract class ComputerReversi : ComputerPlayer
     \*/
 
     protected override void run_search (out PossibleMove best_move)
-        requires (game.current_player_can_move)
+     // requires (game.current_player_can_move)
     {
         /* For the first/first two moves play randomly so the game is not always the same */
         if (game.current_state.n_tiles < game.initial_number_of_tiles + (game.size < 6 ? 2 : 4))
@@ -294,8 +296,8 @@ private abstract class ComputerReversi : ComputerPlayer
         /* Try each move using alpha-beta pruning to optimise finding the best branch */
         foreach (unowned PossibleMove? move in moves)
         {
-            if (move == null)
-                assert_not_reached ();
+         // if (move == null)
+         //     assert_not_reached ();
 
             GameState _g = new GameState.copy_and_move (g, (!) move);
 
@@ -314,7 +316,7 @@ private abstract class ComputerReversi : ComputerPlayer
     }
 
     private int16 search (GameState g, uint8 depth, int16 a, int16 b)
-        requires (a <= b)
+     // requires (a <= b)
     {
         /* End of the game, return a near-infinite evaluation */
         if (g.is_complete)
@@ -334,8 +336,8 @@ private abstract class ComputerReversi : ComputerPlayer
             /* Try each move using alpha-beta pruning to optimise finding the best branch */
             foreach (unowned PossibleMove? move in moves)
             {
-                if (move == null)
-                    assert_not_reached ();
+             // if (move == null)
+             //     assert_not_reached ();
 
                 GameState _g = new GameState.copy_and_move (g, (!) move);
 
diff --git a/src/game.vala b/src/game.vala
index f14918d..7201a83 100644
--- a/src/game.vala
+++ b/src/game.vala
@@ -48,8 +48,8 @@ private class GameState : Object
     private unowned uint8 [,] neighbor_tiles;
 
     internal GameState.copy_and_pass (GameState game)
-        requires (!game.current_player_can_move)
-        requires (!game.is_complete)
+     // requires (!game.current_player_can_move)
+     // requires (!game.is_complete)
     {
         Object (size: game.size, current_color: Player.flip_color (game.current_color));
         neighbor_tiles = game.neighbor_tiles;
@@ -73,11 +73,11 @@ private class GameState : Object
 
         uint8 n_tiles;
         place_tile (move.x, move.y, move_color, /* apply move */ true, out n_tiles);
-        if (n_tiles == 0)
-        {
-            critical ("Computer marked move (%d, %d) as valid, but is invalid when checking.\n%s", move.x, 
move.y, to_string ());
-            assert_not_reached ();
-        }
+     // if (n_tiles == 0)
+     // {
+     //     critical ("Computer marked move (%d, %d) as valid, but is invalid when checking.\n%s", move.x, 
move.y, to_string ());
+     //     assert_not_reached ();
+     // }
 
         update_who_can_move ();
     }
@@ -134,7 +134,7 @@ private class GameState : Object
             _n_light_tiles--;
             _n_dark_tiles++;
         }
-        else assert_not_reached ();
+     // else assert_not_reached ();
     }
 
     /*\
@@ -142,7 +142,7 @@ private class GameState : Object
     \*/
 
     internal Player get_owner (uint8 x, uint8 y)
-        requires (is_valid_location_unsigned (x, y))
+     // requires (is_valid_location_unsigned (x, y))
     {
         return tiles [x, y];
     }
@@ -154,7 +154,7 @@ private class GameState : Object
  // }
 
     internal bool is_current_color (uint8 x, uint8 y)
-        requires (is_valid_location_unsigned (x, y))
+     // requires (is_valid_location_unsigned (x, y))
     {
         return tiles [x, y] == current_color;
     }
@@ -165,10 +165,10 @@ private class GameState : Object
             && y >= 0 && y < size;
     }
 
-    private inline bool is_valid_location_unsigned (uint8 x, uint8 y)
-    {
-        return x < size && y < size;
-    }
+//    private inline bool is_valid_location_unsigned (uint8 x, uint8 y)
+//    {
+//        return x < size && y < size;
+//    }
 
     /*\
     * * ... // completeness
@@ -200,7 +200,7 @@ private class GameState : Object
     }
 
     private void place_tile (uint8 x, uint8 y, Player color, bool apply, out uint8 n_tiles)
-        requires (is_valid_location_unsigned (x, y))
+     // requires (is_valid_location_unsigned (x, y))
     {
         n_tiles = 0;
 
@@ -264,7 +264,7 @@ private class GameState : Object
     }
 
     internal bool can_move (uint8 x, uint8 y)
-        requires (is_valid_location_unsigned (x, y))
+     // requires (is_valid_location_unsigned (x, y))
     {
         return can_place (x, y, current_color);
     }
@@ -648,9 +648,9 @@ private class Game : Object
     internal void get_possible_moves (out SList<PossibleMove?> moves)
     {
         moves = possible_moves.copy_deep ((a) => {
-                if (a == null)
-                    assert_not_reached ();
-                return (PossibleMove) a;
+             // if (a == null)
+             //     assert_not_reached ();
+                return /* (PossibleMove) */ a;
             });
     }
 


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