From 188b24573faabd7cfb13ad08534a4b3bde07c105 Mon Sep 17 00:00:00 2001 From: Michael Catanzaro Date: Sun, 21 Jul 2013 12:12:43 -0500 Subject: [PATCH] Substantial, insufficient work on easiness * Allow engine arguments to depend on difficulty * Improve difficulty levels for many engines... but not much * Stockfish and then Phalanx are now preferred over GNUChess Unfortunately, all of these engines are too hard for our needs. Some of these engines seem to be Windows-only; others are proprietary; and others don't want to compile anymore. I've left these alone since there's not much reason to remove them in case you do manage to get one working. But they won't be getting difficulty levels. https://bugzilla.gnome.org/show_bug.cgi?id=475535 --- data/engines.conf | 81 ++++++++++++++++++++------------------ src/ai-profile.vala | 24 +++++------ src/chess-engine-cecp.vala | 2 +- src/chess-engine-uci.vala | 2 +- src/chess-engine.vala | 10 +++-- src/gnome-chess.vala | 9 +++-- 6 files changed, 71 insertions(+), 57 deletions(-) diff --git a/data/engines.conf b/data/engines.conf index f7d169e..590aa33 100644 --- a/data/engines.conf +++ b/data/engines.conf @@ -1,10 +1,31 @@ +[Stockfish] +protocol=uci +binary=stockfish +option-easy-0=name Skill Level value 0 +option-normal-0=name Skill Level value 5 +option-hard-0=name Skill Level value 20 + +[Phalanx] +protocol=cecp +binary=phalanx +arg-easy-0=-e0 +arg-normal-0=-e40 +option-easy-0=easy +option-easy-1=depth 2 +option-normal-0=easy +option-normal-1=depth 3 +option-hard-0=hard + [GNUchess] protocol=cecp binary=gnuchess -args=--xboard +arg-easy-0=--xboard +arg-normal-0=--xboard +arg-hard-0=--xboard option-easy-0=easy option-easy-1=depth 1 -option-normal-0=depth 4 +option-normal-0=easy +option-normal-1=depth 3 option-hard-0=hard [Sjeng] @@ -12,7 +33,8 @@ protocol=cecp binary=sjeng option-easy-0=easy option-easy-1=depth 1 -option-normal-0=depth 4 +option-normal-0=easy +option-normal-1=depth 3 option-hard-0=hard [Amy] @@ -20,7 +42,8 @@ protocol=cecp binary=Amy option-easy-0=easy option-easy-1=depth 1 -option-normal-0=depth 4 +option-normal-0=easy +option-normal-1=depth 3 option-hard-0=hard [Crafty] @@ -28,7 +51,8 @@ protocol=cecp binary=crafty option-easy-0=easy option-easy-1=depth 1 -option-normal-0=depth 4 +option-normal-0=easy +option-normal-1=depth 3 option-hard-0=hard [Faile] @@ -36,16 +60,8 @@ protocol=cecp binary=faile option-easy-0=easy option-easy-1=depth 1 -option-normal-0=depth 4 -option-hard-0=hard - -[Phalanx] -protocol=cecp -binary=phalanx -option-easy-0=easy -option-easy-1=depth 1 -option-easy-2=level 5 -option-normal-0=depth 4 +option-normal-0=easy +option-normal-1=depth 3 option-hard-0=hard [Glaurung] @@ -58,70 +74,59 @@ option-normal-1=name Cowardice value 100 option-hard-0=name Aggressiveness value 200 option-hard-1=name Cowardice value 50 -[Stockfish] -protocol=uci -binary=stockfish -option-easy-0=name Skill Level value 0 -option-easy-1=name Slow Mover value 1000 -option-easy-2=name Minimum Thinking Time value 5000 -option-easy-3=name Threads value 1 -option-normal-0=name Skill Level value 5 -option-normal-1=name Slow Mover value 1000 -option-normal-2=name Minimum Thinking Time value 5000 -option-normal-3=name Threads value 1 -option-hard-0=name Skill Level value 20 - [HoiChess] protocol=cecp binary=hoichess option-easy-0=easy option-easy-1=depth 1 -option-normal-0=depth 4 +option-normal-0=easy +option-normal-1=depth 3 option-hard-0=hard [Diablo] protocol=uci binary=diablo -# FIXME: Add some difficulty levels [BBChess] protocol=uci binary=bbchess -# FIXME: Add some difficulty levels [Fruit] protocol=uci binary=fruit -# FIXME: Add some difficulty levels [Gambit Fruit] protocol=uci binary=gfruit -# FIXME: Add some difficulty levels [Toga II] protocol=uci binary=toga2 -# FIXME: Add some difficulty levels [Amundsen] protocol=cecp binary=amundsen option-easy-0=easy option-easy-1=depth 1 -option-normal-0=depth 4 +option-normal-0=easy +option-normal-1=depth 3 option-hard-0=hard [Boo's Chess Engine] protocol=cecp -binary=bce boochess BACE +binary=bce +option-easy-0=easy +option-easy-1=random +option-normal-0=easy +option-hard-0=hard [Fairy-Max] protocol=cecp binary=fairymax -# FIXME: Add some difficulty levels +option-easy-0=easy +option-normal-0=normal +option-hard-0=hard [Shredder] protocol=uci binary=ShredderClassicLinux -# FIXME: Add some difficulty levels diff --git a/src/ai-profile.vala b/src/ai-profile.vala index f106430..eedb650 100644 --- a/src/ai-profile.vala +++ b/src/ai-profile.vala @@ -14,7 +14,9 @@ public class AIProfile public string protocol; public string binary; public string path; - public string args; + public string[] easy_args; + public string[] normal_args; + public string[] hard_args; public string[] easy_options; public string[] normal_options; public string[] hard_options; @@ -49,13 +51,13 @@ public List load_ai_profiles (string filename) profile.name = name; profile.protocol = file.get_value (name, "protocol"); profile.binary = file.get_value (name, "binary"); - if (file.has_key (name, "args")) - profile.args = file.get_value (name, "args"); - else - profile.args = null; // bgo#696474 - profile.easy_options = load_options (file, name, "easy"); - profile.normal_options = load_options (file, name, "normal"); - profile.hard_options = load_options (file, name, "hard"); + + profile.easy_args = load_array (file, name, "arg", "easy"); + profile.normal_args = load_array (file, name, "arg", "normal"); + profile.hard_args = load_array (file, name, "arg", "hard"); + profile.easy_options = load_array (file, name, "option", "easy"); + profile.normal_options = load_array (file, name, "option", "normal"); + profile.hard_options = load_array (file, name, "option", "hard"); } catch (KeyFileError e) { @@ -73,15 +75,15 @@ public List load_ai_profiles (string filename) return profiles; } -private string[] load_options (KeyFile file, string name, string difficulty) throws KeyFileError +private string[] load_array (KeyFile file, string name, string type, string difficulty) throws KeyFileError { int count = 0; - while (file.has_key (name, "option-%s-%d".printf (difficulty, count))) + while (file.has_key (name, "%s-%s-%d".printf (type, difficulty, count))) count++; string[] options = new string[count]; for (var i = 0; i < count; i++) - options[i] = file.get_value (name, "option-%s-%d".printf (difficulty, i)); + options[i] = file.get_value (name, "%s-%s-%d".printf (type, difficulty, i)); return options; } diff --git a/src/chess-engine-cecp.vala b/src/chess-engine-cecp.vala index be3e868..13acd22 100644 --- a/src/chess-engine-cecp.vala +++ b/src/chess-engine-cecp.vala @@ -14,7 +14,7 @@ public class ChessEngineCECP : ChessEngine private bool moving = false; private string[] options; - public ChessEngineCECP (string binary, string? args, string[] options) + public ChessEngineCECP (string binary, string[] args, string[] options) { base (binary, args); this.options = options; diff --git a/src/chess-engine-uci.vala b/src/chess-engine-uci.vala index 12fdd15..f7a6708 100644 --- a/src/chess-engine-uci.vala +++ b/src/chess-engine-uci.vala @@ -15,7 +15,7 @@ public class ChessEngineUCI : ChessEngine private string[] options; private bool waiting_for_move; - public ChessEngineUCI (string binary, string? args, string[] options) + public ChessEngineUCI (string binary, string[] args, string[] options) { base (binary, args); this.options = options; diff --git a/src/chess-engine.vala b/src/chess-engine.vala index f708c8e..ab14362 100644 --- a/src/chess-engine.vala +++ b/src/chess-engine.vala @@ -11,7 +11,7 @@ public abstract class ChessEngine : Object { private string binary; - private string args; + private string[] args; private Pid pid; private int stdin_fd; @@ -41,7 +41,7 @@ public abstract class ChessEngine : Object } } - public ChessEngine (string binary, string? args) + public ChessEngine (string binary, string[] args) { this.binary = binary; this.args = args; @@ -49,7 +49,11 @@ public abstract class ChessEngine : Object public bool start () { - string[] argv = { binary, args, null }; + string[] argv = {binary}; + foreach (var arg in args) + argv += arg; + argv += null; + int stdout_fd; try { diff --git a/src/gnome-chess.vala b/src/gnome-chess.vala index 23e50b9..9a0ae2a 100644 --- a/src/gnome-chess.vala +++ b/src/gnome-chess.vala @@ -564,25 +564,28 @@ public class Application : Gtk.Application profile = ai_profiles.data; } - string[] options; + string[] options, args; switch (difficulty) { case "easy": options = profile.easy_options; + args = profile.easy_args; break; default: case "normal": options = profile.normal_options; + args = profile.normal_args; break; case "hard": options = profile.hard_options; + args = profile.hard_args; break; } if (profile.protocol == "cecp") - engine = new ChessEngineCECP (profile.binary, profile.args, options); + engine = new ChessEngineCECP (profile.binary, args, options); else if (profile.protocol == "uci") - engine = new ChessEngineUCI (profile.binary, profile.args, options); + engine = new ChessEngineUCI (profile.binary, args, options); else { warning ("Unknown AI protocol %s", profile.protocol);