[gnome-games] Only use chess engine for new games, loaded games may not have an engine



commit 0b513453dd43d950731a814ecd4fe23be201ab90
Author: Robert Ancell <robert ancell canonical com>
Date:   Tue Jan 18 09:21:16 2011 +1100

    Only use chess engine for new games, loaded games may not have an engine

 glchess/src/glchess.vala |   43 ++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 38 insertions(+), 5 deletions(-)
---
diff --git a/glchess/src/glchess.vala b/glchess/src/glchess.vala
index 957a3fd..8f8e6c2 100644
--- a/glchess/src/glchess.vala
+++ b/glchess/src/glchess.vala
@@ -234,14 +234,32 @@ public class Application
         save_as_menu.sensitive = false;
         update_history_panel ();
 
-        opponent_engine = get_engine (settings.get_string ("opponent"), settings.get_string ("difficulty"));
+        // TODO: Could both be engines
+        var white_engine = pgn_game.tags.lookup ("WhiteAI");
+        var white_level = pgn_game.tags.lookup ("WhiteLevel");
+        if (white_level == null)
+            white_level = "normal";
+
+        var black_engine = pgn_game.tags.lookup ("BlackAI");
+        var black_level = pgn_game.tags.lookup ("BlackLevel");
+        if (black_level == null)
+            black_level = "normal";
+
         opponent = null;
+        opponent_engine = null;
+        if (white_engine != null)
+        {
+            opponent = game.white;
+            opponent_engine = get_engine (white_engine, white_level);
+        }
+        else if (black_engine != null)
+        {
+            opponent = game.black;
+            opponent_engine = get_engine (black_engine, black_level);
+        }
+
         if (opponent_engine != null)
         {
-            if (settings.get_boolean ("play-as-white"))
-                opponent = game.black;
-            else
-                opponent = game.white;
             opponent_engine.ready_changed.connect (engine_ready_cb);
             opponent_engine.moved.connect (engine_move_cb);
             opponent_engine.start ();
@@ -1270,6 +1288,21 @@ public class Application
         var duration = settings.get_int ("duration");
         if (duration > 0)
             pgn_game.time_control = "%d".printf (duration);
+        var engine_name = settings.get_string ("opponent");
+        var engine_level = settings.get_string ("difficulty");
+        if (engine_name != null && engine_name != "human")
+        {
+            if (settings.get_boolean ("play-as-white"))
+            {
+                pgn_game.tags.insert ("BlackAI", engine_name);
+                pgn_game.tags.insert ("BlackLevel", engine_level);
+            }
+            else
+            {
+                pgn_game.tags.insert ("WhiteAI", engine_name);
+                pgn_game.tags.insert ("WhiteLevel", engine_level);
+            }
+        }
         start_game ();
     }
 



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