Esempio n. 1
0
        private void selectGameFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var openFileDialog = new OpenFileDialog()
            {
                Multiselect      = false,
                FileName         = Properties.Settings.Default.InitialGameFileName,
                InitialDirectory = Properties.Settings.Default.InitialGameFileLocationDirectory,
                RestoreDirectory = true,
                Filter           = "GDL files (*.kif;*.gdl)|*.kif;*.gdl|All files (*.*)|*.*",
                FilterIndex      = 0
            };

            var dlgResult = openFileDialog.ShowDialog(this);

            if (dlgResult == DialogResult.Cancel)
            {
                return;
            }

            OpenKIFFile(openFileDialog.FileName);
            DebugAndTraceHelper.WriteTraceLine("Game file loaded, please select Start Game to continue...", DebugAndTraceHelper.StatusStripChannelId);
            managerOutputForm.Text = GeneralGameManager.TheGeneralGame.Name;

            if (autoStartToolStripMenuItem.Checked)
            {
                startGameToolStripMenuItem_Click(null, null);
            }
        }
        public override string PlayAsync(string id, string moves)
        {
            DebugAndTraceHelper.WriteTraceLine("\n\n\n*************************** moves ", Role);
            DebugAndTraceHelper.WriteTraceLine(moves, Role);

            var nextState = TheGeneralGame.ApplyMoves(moves, false, role: Role);

            DebugAndTraceHelper.WriteTraceLine(String.Format("({0}) Next state is {1}", Role, nextState), Role);

            //DebugAndTraceHelper.WriteTraceLine("*************************** after moves applied ", Role);
            //string clauseDump = this.GetPrologEngine().ListAllFacts();
            //DebugAndTraceHelper.WriteTraceLine(clauseDump, Role);

            var nextMove = TheGeneralGame.FindRandomLegal(Role);

            if (nextMove != null)
            {
                DebugAndTraceHelper.WriteTraceLine(String.Format("({0}) Next move is {1}", Role, nextMove), Role);
                return(nextMove.TheMove);
            }
            else
            {
                return(String.Empty);
            }
        }
Esempio n. 3
0
        private void recentFileGotClicked(object obj, EventArgs e)
        {
            OpenKIFFile((obj as ToolStripMenuItem).Text);
            DebugAndTraceHelper.WriteTraceLine("Game file loaded, please select Start Game to continue...", DebugAndTraceHelper.StatusStripChannelId);
            managerOutputForm.Text = GeneralGameManager.TheGeneralGame.Name;

            if (autoStartToolStripMenuItem.Checked)
            {
                startGameToolStripMenuItem_Click(null, null);
            }
        }
Esempio n. 4
0
        public override string PlayAsync(string id, string moves)
        {
            DebugAndTraceHelper.WriteTraceLine("\n\n\n*************************** moves ", Role);
            DebugAndTraceHelper.WriteTraceLine(moves, Role);

            var nextState = TheGeneralGame.ApplyMoves(moves, false, role: Role);

            DebugAndTraceHelper.WriteTraceLine(String.Format("({0}) Next state is {1}", Role, nextState), Role);

            //DebugAndTraceHelper.WriteTraceLine("*************************** after moves applied ", Role);
            //string clauseDump = this.GetPrologEngine().ListAllFacts();
            //DebugAndTraceHelper.WriteTraceLine(clauseDump, Role);

            Move nextMove           = null;
            var  legalMovesWithEval = TheGeneralGame.FindLegalsWithEval(Role);
            int? maxEval            = legalMovesWithEval.Max(n => n.Tag as int?);
            int? minEval            = legalMovesWithEval.Min(n => n.Tag as int?);

            if (legalMovesWithEval.Any())
            {
                if (maxEval != minEval)
                {
                    nextMove = legalMovesWithEval.Where(n => n.Tag as int? == maxEval.Value).First();
                }
                else
                {
                    nextMove = TheGeneralGame.FindRandomLegal(Role);
                }
            }

            if (nextMove != null)
            {
                DebugAndTraceHelper.WriteTraceLine(String.Format("({0}) Next move is {1} with eval {2}", Role, nextMove, maxEval.Value), Role);
                return(nextMove.TheMove);
            }
            else
            {
                return(String.Empty);
            }
        }
        public GeneralGameManager(string gameDescriptionFileName, int startClock, int playClock, string wcfSvcHostExePath = null, string tempFilePath = null)
        {
            string error;

            AllMoves = new List <Move>();

            MilliSecondsBetweenFreeRunningMoves      = 0;
            AllowFreeRunningOfTurnsWithNoPlayerMoves = true;

            TheGeneralGame = new GeneralGame(wcfSvcHostExePath)
            {
                TempFilePath = tempFilePath
            };

            DebugAndTraceHelper.WriteTraceLine("Loading and parsing game description...", DebugAndTraceHelper.StatusStripChannelId);
            DebugAndTraceHelper.WriteTraceLine(String.Format("Started loading and parsing game description at {0}", DateTime.Now.ToLongTimeString()), DebugAndTraceHelper.ManagerChannelId);
            TheGeneralGame.LoadDescriptionFromKIFFile(gameDescriptionFileName);
            DebugAndTraceHelper.WriteTraceLine(String.Format("Finished loading and parsing game description at {0}", DateTime.Now.ToLongTimeString()), DebugAndTraceHelper.ManagerChannelId);

            DebugAndTraceHelper.WriteTraceLine("Initializing game...", DebugAndTraceHelper.StatusStripChannelId);
            DebugAndTraceHelper.WriteTraceLine(String.Format("Started initializing game at {0}", DateTime.Now.ToLongTimeString()), DebugAndTraceHelper.ManagerChannelId);
            TheGeneralGame.InitializeGame(out error);
            DebugAndTraceHelper.WriteTraceLine(String.Format("Finished initializing game at {0}", DateTime.Now.ToLongTimeString()), DebugAndTraceHelper.ManagerChannelId);

            StartClock = startClock;
            PlayClock  = playClock;

            MatchId = DateTime.Now.ToString() + TheGeneralGame.Name;

            DebugAndTraceHelper.AddLogFileListener(DebugAndTraceHelper.ManagerChannelId);

            DebugAndTraceHelper.WriteTraceLine("Creating players...", DebugAndTraceHelper.StatusStripChannelId);
            Players = new List <IGeneralGamePlayer>();
            var roles = TheGeneralGame.FindRoles().ToArray();

            if (TheGeneralGame.Name == "DarkChess")
            {
                for (int i = 0; i < roles.Count(); i++)
                {
                    if (roles[i] != "random")
                    {
                        var newPlayer = new FirstDarkChessPlayer(roles[i], wcfSvcHostExePath, tempFilePath);
                        DebugAndTraceHelper.AddLogFileListener(roles[i]);
                        Players.Add(newPlayer);
                    }
                    else
                    {
                        var newPlayer = new FirstGeneralGamePlayer(roles[i], wcfSvcHostExePath, tempFilePath);
                        DebugAndTraceHelper.AddLogFileListener(roles[i]);
                        Players.Add(newPlayer);
                    }
                }
            }
            else
            {
                for (int i = 0; i < roles.Count(); i++)
                {
                    var newPlayer = new FirstGeneralGamePlayer(roles[i], wcfSvcHostExePath, tempFilePath);
                    DebugAndTraceHelper.AddLogFileListener(roles[i]);
                    Players.Add(newPlayer);
                }
            }

            foreach (TraceListener traceListener in DebugAndTraceHelper.GetListeners(DebugAndTraceHelper.StateChannelId))
            {
                var ieWebBrowserListener = traceListener as IEWebBrowserListener;
                if (ieWebBrowserListener != null)
                {
                    ieWebBrowserListener.xslFilePath = TheGeneralGame.XMLStyleSheetFilePath;
                }
            }
        }
        public bool Play()
        {
            IEnumerable <HornClause> satisfiedTerminalClauses;

            try
            {
                if (!CheckIfAllPlayersAreUpAndRunning())
                {
                    return(false);
                }

                var traceListener        = DebugAndTraceHelper.GetListeners(DebugAndTraceHelper.StateChannelId).FirstOrDefault();
                var ieWebBrowserListener = traceListener as IEWebBrowserListener;

                // show this in the game manager's web browser
                var initialStateAsXML = TheGeneralGame.GetStateAsCompleteXML();
                DebugAndTraceHelper.WriteTraceLine(initialStateAsXML, DebugAndTraceHelper.StateChannelId);

                TurnRecord initialTurnRecord = new TurnRecord();
                initialTurnRecord.IsInitialState           = true;
                initialTurnRecord.GameState.GameStateAsXML = initialStateAsXML;
                //initialTurnRecord.GameState.GameStateAsHTML = ieWebBrowserListener == null ? "" : ieWebBrowserListener.ieWebBrowser.DocumentText;
                TurnRecords.Add(initialTurnRecord);

                IFormatter formatter       = new BinaryFormatter();
                var        historyFileName = DebugAndTraceHelper.CustomLocation + DebugAndTraceHelper.BaseFileName + "_" +
                                             (DateTime.Now.ToShortDateString() + "_" + DateTime.Now.ToLongTimeString()).Replace(" ", "_").Replace(@"/", "-").Replace(":", "-") + ".his";

                DebugAndTraceHelper.WriteTraceLine("Starting Players...", DebugAndTraceHelper.StatusStripChannelId);
                StartAllPlayers();

                var prevMoves = new List <Move>();
                DebugAndTraceHelper.WriteTraceLine("Checking for game termination...", DebugAndTraceHelper.StatusStripChannelId);
                bool gameHasTerminated = TheGeneralGame.FindTerminal(out satisfiedTerminalClauses);
                Move terminalMove      = null;
                while (!gameHasTerminated)
                {
                    DebugAndTraceHelper.WriteTraceLine("Waiting for next moves...", DebugAndTraceHelper.StatusStripChannelId);
                    var nextMoves = GetNextMoves(prevMoves);
                    RecordMoves(nextMoves);

                    DebugAndTraceHelper.WriteTraceLine("**** moves ****", DebugAndTraceHelper.ManagerChannelId);
                    foreach (Move nextMove in nextMoves)
                    {
                        DebugAndTraceHelper.WriteTraceLine(nextMove.Role + " makes move " + nextMove.TheMove, DebugAndTraceHelper.ManagerChannelId);
                    }

                    // ToDo:
                    DebugAndTraceHelper.WriteTraceLine("Checking for game termination...", DebugAndTraceHelper.StatusStripChannelId);

                    TheGeneralGame.ApplyMoves(nextMoves);
                    if (TheGeneralGame.FindTerminal(out satisfiedTerminalClauses))
                    {
                        gameHasTerminated = true;
                        DebugAndTraceHelper.WriteTraceLine(
                            String.Format("******** Game Ended for reason(s) {0} ********",
                                          String.Join(", ", satisfiedTerminalClauses)), DebugAndTraceHelper.ManagerChannelId);
                        terminalMove = nextMoves.Where(n => !n.IsNoop()).FirstOrDefault();
                    }

                    var stateAsXML = TheGeneralGame.GetStateAsCompleteXML();
                    DebugAndTraceHelper.WriteTraceLine(stateAsXML, DebugAndTraceHelper.StateChannelId);

                    prevMoves = nextMoves;

                    // serialize the history information
                    TurnRecord thisTurnRecord = new TurnRecord();
                    thisTurnRecord.Turn = TheGeneralGame.CurrentTurn;
                    thisTurnRecord.GameState.GameStateAsXML      = stateAsXML;
                    thisTurnRecord.GameState.GameStateFromProlog =
                        TheGeneralGame.PrologEngine.ListAll(sortAlphabetically: false).Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                    thisTurnRecord.Moves = nextMoves;
                    //thisTurnRecord.GameState.GameStateAsHTML = ieWebBrowserListener == null ? "" : ieWebBrowserListener.ieWebBrowser.DocumentText;
                    thisTurnRecord.IsTerminalState = gameHasTerminated;
                    TurnRecords.Add(thisTurnRecord);
                    using (FileStream s = File.Create(historyFileName))
                    {
                        formatter.Serialize(s, TurnRecords);
                    }

                    if (gameHasTerminated)
                    {
                        DebugAndTraceHelper.WriteTraceLine("Game has ended", DebugAndTraceHelper.StatusStripChannelId);
                    }
                    else
                    {
                        if (StartNextMoveEvent != null && (!AllowFreeRunningOfTurnsWithNoPlayerMoves || nextMoves.Where(n => !n.IsTheRandomRole() && !n.IsNoop()).Any()))
                        {
                            DebugAndTraceHelper.WriteTraceLine("Please click next turn button to go to next turn...", DebugAndTraceHelper.StatusStripChannelId);
                            StartNextMoveEvent.WaitOne();
                        }
                        else
                        {
                            if (MilliSecondsBetweenFreeRunningMoves >= 0)
                            {
                                if (AllowFreeRunningOfTurnsWithNoPlayerMoves && !nextMoves.Where(n => !n.IsTheRandomRole() && !n.IsNoop()).Any())
                                {
                                    Thread.Sleep(MilliSecondsBetweenFreeRunningMoves / 4);
                                }
                                else
                                {
                                    Thread.Sleep(MilliSecondsBetweenFreeRunningMoves);
                                }
                            }
                        }
                    }
                }

                var scores = TheGeneralGame.FindScores();
                DebugAndTraceHelper.WriteTraceLine("**** scores ****", DebugAndTraceHelper.ManagerChannelId);
                foreach (Score score in scores)
                {
                    DebugAndTraceHelper.WriteTraceLine(score, DebugAndTraceHelper.ManagerChannelId);
                }

                StopAllPlayers(terminalMove);

                return(true);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public bool PlayFromHistoryFile(string filePath)
        {
            int currentTurnIndex = 0;
            int previousTurnIndex;

            IFormatter formatter = new BinaryFormatter();

            using (FileStream s = File.OpenRead(filePath))
            {
                TurnRecords = (List <TurnRecord>)formatter.Deserialize(s);
            }

            bool?goForward = null;

            while (true)
            {
                if (goForward != null)
                {
                    if (goForward.Value)
                    {
                        foreach (Move move in TurnRecords[currentTurnIndex].Moves)
                        {
                            // output the moves that got us to this new state
                            DebugAndTraceHelper.WriteTraceLine(move.Role + " makes move " + move.TheMove, DebugAndTraceHelper.ManagerChannelId);
                        }
                    }
                    else
                    {
                        foreach (Move move in TurnRecords[currentTurnIndex + 1].Moves)
                        {
                            // output the moves that we are undoing to get to this state
                            DebugAndTraceHelper.WriteTraceLine(move.Role + " makes move " + move.TheMove, DebugAndTraceHelper.ManagerChannelId);
                        }
                    }
                }

                DebugAndTraceHelper.WriteTraceLine(TurnRecords[currentTurnIndex].GameState.GameStateAsXML, DebugAndTraceHelper.StateChannelId);

                if (StartNextMoveEvent != null)
                {
                    DebugAndTraceHelper.WriteTraceLine("Please click prev/next turn button to go to prev/next turn...", DebugAndTraceHelper.StatusStripChannelId);

                    goForward = null;
                    while (goForward == null)
                    {
                        if (StartNextMoveEvent.WaitOne(5))
                        {
                            goForward = true;
                        }
                        else if (PrevMoveEvent.WaitOne(5))
                        {
                            goForward = false;
                        }
                    }
                }
                else
                {
                    if (MilliSecondsBetweenFreeRunningMoves > 0)
                    {
                        Thread.Sleep(MilliSecondsBetweenFreeRunningMoves);
                    }

                    goForward = true;
                }

                previousTurnIndex = currentTurnIndex;
                if (goForward.Value)
                {
                    currentTurnIndex = Math.Min(currentTurnIndex + 1, TurnRecords.Max(n => n.Turn));
                }
                else
                {
                    currentTurnIndex = Math.Max(currentTurnIndex - 1, 0);
                }

                if (currentTurnIndex != previousTurnIndex)
                {
                    TheGeneralGame.PrologEngine.Reset();
                    foreach (string gameStateLine in TurnRecords[currentTurnIndex].GameState.GameStateFromProlog)
                    {
                        var foo = PrologEngine.CleanUpExistingPrologClauseForAsserting(gameStateLine);
                        TheGeneralGame.PrologEngine.Assert(PrologEngine.CleanUpExistingPrologClauseForAsserting(gameStateLine));
                    }
                }
            }

            return(true);
        }
Esempio n. 8
0
        private bool DoParse(bool useParallelTasks = true)
        {
            // put this in for debugging so we aren't running parallel "tasks"
            //sentences.RemoveRange(0, 2);
            //sentences.RemoveRange(1, sentences.Count-1);

            try
            {
                if (useParallelTasks)
                {
                    Parallel.For(0, sentences.Count, new ParallelOptions()
                    {
                        MaxDegreeOfParallelism = -1
                    }, i =>
                    {
                        var goal1     = new Goal(new Symbol("Sentence"), 0, sentences[i].Count);
                        var ruleTree  = new TFTree <Rule>();
                        ruleTree.Root =
                            new TFTreeNode <Rule>(
                                ruleCollection.Rules.ElementAt(0).Value as Rule);
                        var ruleRangeStack    = new Stack <RuleRange>();
                        var goalStack         = new Stack <Goal>();
                        var ruleInputMapStack = new Stack <RuleInputMap>();
                        var parseTreeTopNode  =
                            new TFTreeNode <ParseTreeNodeData>(new ParseTreeNodeData(goal1, null));
                        var parseTree = new TFTree <ParseTreeNodeData>()
                        {
                            Root     = parseTreeTopNode,
                            XSLTFile = @"file:///D:/Temp/XMLPrettyPrint.xsl"
                        };
                        if (goal1.NewProcess(sentences[i], 0, goalStack, ruleRangeStack,
                                             ruleInputMapStack, parseTreeTopNode,
                                             ruleTree.Root,
                                             null, ruleCollection))
                        {
                            parseTrees[i] = parseTree;

#if DEBUG_PARSER
                            textBox1.AppendText(
                                " \n---- rule input map stack ----------------------\n");
                            foreach (RuleInputMap ruleInputMap in ruleInputMapStack)
                            {
                                textBox1.AppendText(ruleInputMap.ToString(sentence) +
                                                    Environment.NewLine);
                            }

                            textBox1.AppendText(
                                " \n---- rule range stack ----------------------\n");
                            foreach (RuleRange ruleRange in ruleRangeStack)
                            {
                                textBox1.AppendText(ruleRange.TheRule + " (" +
                                                    String.Join(", ",
                                                                sentence.GetRange(
                                                                    ruleRange.InputPos,
                                                                    ruleRange.Length)) +
                                                    ")" + Environment.NewLine);
                            }

                            textBox1.AppendText(" \n---- goal stack ----------------------\n");
                            foreach (Goal goal in goalStack)
                            {
                                textBox1.AppendText(goal.Symbol.TheSymbol + " (" +
                                                    String.Join(", ",
                                                                sentence.GetRange(
                                                                    goal.InputPos, goal.Length)) +
                                                    ")" +
                                                    Environment.NewLine);
                            }

                            textBox1.AppendText(" \n--------------------------\n");
                            long endTime = Stopwatch.GetTimestamp();
                            //var numNodes = parseTreeTopNode.GetDepthFirstEnumerable(TreeTraversalDirection.TopDown).Count();
                            //textBox1.AppendText(String.Format("Elapsed Time: {0}ms, # Nodes: {1}", 1000*(endTime-startTime)/Stopwatch.Frequency, numNodes));
                            //textBox1.Text = topNode.ToString(true);
#endif
                        }
                        else
                        {
                            DebugAndTraceHelper.WriteTraceLine(String.Format("Could not parse {0}", String.Join(" ", sentences[i].Select(n => n.Lexeme.ToString()))));
                            DebugAndTraceHelper.WriteTraceLine(String.Format("                {0}", String.Join(" ", sentences[i].Select(n => n.ToString()))));
                        }
                    });
                }
                else  // do a serial parsing
                {
                    int sentenceCount = 0;
                    foreach (List <Token> sentence in sentences)
                    {
                        var goal1    = new Goal(new Symbol("Sentence"), 0, sentences[sentenceCount].Count);
                        var ruleTree = new TFTree <Rule>();
                        ruleTree.Root =
                            new TFTreeNode <Rule>(
                                ruleCollection.Rules.ElementAt(0).Value as Rule);
                        var ruleRangeStack    = new Stack <RuleRange>();
                        var goalStack         = new Stack <Goal>();
                        var ruleInputMapStack = new Stack <RuleInputMap>();
                        var parseTreeTopNode  =
                            new TFTreeNode <ParseTreeNodeData>(new ParseTreeNodeData(goal1, null));
                        var parseTree = new TFTree <ParseTreeNodeData>()
                        {
                            Root     = parseTreeTopNode,
                            XSLTFile = @"file:///D:/Temp/XMLPrettyPrint.xsl"
                        };
                        if (goal1.NewProcess(sentences[sentenceCount], 0, goalStack, ruleRangeStack,
                                             ruleInputMapStack, parseTreeTopNode,
                                             ruleTree.Root,
                                             null, ruleCollection))
                        {
                            parseTrees[sentenceCount] = parseTree;
                        }

                        sentenceCount++;
                    }
                }

                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 9
0
        private void OpenKIFFile(string kifFilePath)
        {
            KIFFilePath = kifFilePath;
            mruManager.AddRecentFile(KIFFilePath);
            GeneralGameManager = new GeneralGameManager(KIFFilePath, 10, 10, Properties.Settings.Default.WcfSvcHostExecutable, Properties.Settings.Default.TempFilePath)
            {
                StartNextMoveEvent = startNextTurnEvent, PrevMoveEvent = prevTurnEvent
            };
            GeneralGame.UseOldWayOfGeneratingAndApplyingMoves =
                useOriginalMoveGenerationAndApplicationToolStripMenuItem.Checked;

            playerToolStripMenuItem.DropDownItems.Clear();
            int playerOutputWindowX    = 0;
            int playerOutputWindowY    = htmlOutputForm.Location.Y + htmlOutputForm.Height;
            int playerOutputFormWidth  = (this.ClientRectangle.Width - 5) / (GeneralGameManager.TheGeneralGame.FindRoles().Count() == 0 ? 1 : GeneralGameManager.TheGeneralGame.FindRoles().Count());
            int playerOutputFormHeight = this.ClientRectangle.Height - 25 - this.statusStrip1.Height - managerOutputForm.Height - htmlOutputForm.Height - (2 * SystemInformation.HorizontalScrollBarHeight);
            int playerFormCount        = 0;

            foreach (string role in GeneralGameManager.TheGeneralGame.FindRoles())
            {
                var playerOutputForm = new Form()
                {
                    MdiParent     = this,
                    Text          = role,
                    StartPosition = FormStartPosition.Manual,
                    Location      = new Point(playerOutputWindowX, playerOutputWindowY),
                    Width         = playerOutputFormWidth,
                    Height        = playerOutputFormHeight,
                    Tag           = PlayerWindowConfigStringPrefix + playerFormCount
                };
                var playerOutputTextBox = new TextBox()
                {
                    Dock = DockStyle.Fill, Multiline = true, ScrollBars = ScrollBars.Both
                };
                playerOutputForm.Controls.Add(playerOutputTextBox);
                DebugAndTraceHelper.AddListener(new TextboxTraceListener(playerOutputTextBox), role);
                playerOutputWindowX += playerOutputForm.Bounds.Width;
                WindowGeometryPersistence.SetFormsGeometry(Properties.Settings.Default.WindowGeometry, playerOutputForm);
                playerOutputForm.Show();
                outputForms.Add(playerOutputForm);

                var mi = new ToolStripMenuItem(role);
                playerToolStripMenuItem.DropDownItems.Add(mi);

                var submi = new ToolStripMenuItem("Query Player Prolog Engine");
                mi.DropDownItems.Add(submi);
                submi.Click += (o, k) =>
                {
                    var dialog = new PrologQuery(GeneralGameManager.Players.Where(n => n.Role == role).First().GetPrologEngine());
                    dialog.Show(this);
                };

                playerFormCount++;
            }

            startGameToolStripMenuItem.Enabled = true;

            saveCollapsedParseTreesToolStripMenuItem.Enabled = true;
            saveParseTreesToolStripMenuItem.Enabled          = true;
            saveHornClausesToolStripMenuItem.Enabled         = true;

            queryGamePrologEngineToolStripMenuItem.Enabled       = true;
            dumpPrologEngineUserClausesToolStripMenuItem.Enabled = true;
        }
Esempio n. 10
0
        protected override void OnLoad(EventArgs e)
        {
            DebugAndTraceHelper.CustomLocation = Properties.Settings.Default.TempFilePath;

            mruManager = new MRUManager(selectRecentGameFileToolStripMenuItem, Application.ProductName,
                                        recentFileGotClicked, null);

            freeRunningToolStripMenuItem.Enabled = false;

            tsb_NextTurn.Enabled = false;
            tsb_PrevTurn.Enabled = false;

            startGameToolStripMenuItem.Enabled = false;

            saveCollapsedParseTreesToolStripMenuItem.Enabled = false;
            saveParseTreesToolStripMenuItem.Enabled          = false;
            saveHornClausesToolStripMenuItem.Enabled         = false;

            queryGamePrologEngineToolStripMenuItem.Enabled       = false;
            dumpPrologEngineUserClausesToolStripMenuItem.Enabled = false;

            var dc = new DecoupledConsole();

            DebugAndTraceHelper.AddListener(new DecoupledConsoleTraceListener(dc));

            DebugAndTraceHelper.AddListener(new ToolStripStatusLabelListener(this.toolStripStatusLabel1), DebugAndTraceHelper.StatusStripChannelId);

            managerOutputForm = new Form()
            {
                MdiParent     = this,
                Text          = DebugAndTraceHelper.ManagerChannelId,
                StartPosition = FormStartPosition.Manual,
                Location      = new Point(0, 0),
                Width         = this.ClientRectangle.Width - 5,
                Tag           = GameManagerWindowConfigStringPrefix
            };
            var managerOutputTextBox = new TextBox()
            {
                Dock = DockStyle.Fill, Multiline = true, ScrollBars = ScrollBars.Both
            };

            managerOutputForm.Controls.Add(managerOutputTextBox);
            DebugAndTraceHelper.AddListener(new TextboxTraceListener(managerOutputTextBox), DebugAndTraceHelper.ManagerChannelId);
            try
            {
                WindowGeometryPersistence.SetFormsGeometry(Properties.Settings.Default.WindowGeometry, managerOutputForm);
            }
            catch (Exception)
            {
                ;
            }
            managerOutputForm.Show();
            outputForms.Add(managerOutputForm);

            htmlOutputForm = new Form()
            {
                MdiParent     = this,
                StartPosition = FormStartPosition.Manual,
                Location      = new Point(0, managerOutputForm.Height),
                Width         = this.ClientRectangle.Width - 5,
                Tag           = GameStateWindowConfigString
            };
            var webBrowser = new System.Windows.Forms.WebBrowser()
            {
                Dock = DockStyle.Fill, ScrollBarsEnabled = true
            };

            htmlOutputForm.Controls.Add(webBrowser);
            DebugAndTraceHelper.WriteTraceLine("WebBrowser version: " + webBrowser.Version, DebugAndTraceHelper.ManagerChannelId);
            htmlOutputFormListener = new IEWebBrowserListener(webBrowser);
            DebugAndTraceHelper.AddListener(htmlOutputFormListener, DebugAndTraceHelper.StateChannelId);
            WindowGeometryPersistence.SetFormsGeometry(Properties.Settings.Default.WindowGeometry, htmlOutputForm);
            htmlOutputForm.Show();
            outputForms.Add(htmlOutputForm);

            GeneralGame.UseOldWayOfGeneratingAndApplyingMoves =
                useOriginalMoveGenerationAndApplicationToolStripMenuItem.Checked;

            if (!System.Diagnostics.Debugger.IsAttached && false)
            {
                Thread t;
                t = new Thread(StartSWIPrologService1);
                t.IsBackground = true;
                t.Start();

                Thread t2;
                t2 = new Thread(StartSWIPrologService2);
                t2.IsBackground = true;
                t2.Start();

                Thread t3;
                t3 = new Thread(StartSWIPrologService3);
                t3.IsBackground = true;
                t3.Start();
            }


#if PrologEngineTest
            PrologEngine.PrologEngine foo = new PrologEngine.PrologEngine();
            foo.Assert("cell(1,1,b)");
            foo.Assert("cell(2,2,x)");
            foreach (List <SWIPrologServiceLibrary.SolutionVariable> solutionVariables in foo.GetSolutionVariables("cell(X,Y,Z)"))
            {
                ;
            }

            PrologEngine.PrologEngine foo2 = new PrologEngine.PrologEngine();
            foo2.Assert("cell(2,2,o)");
            foo2.Assert("cell(3,3,x)");
            foreach (List <SWIPrologServiceLibrary.SolutionVariable> solutionVariables in foo2.GetSolutionVariables("cell(X,Y,Z)"))
            {
                ;
            }

            PrologEngine.PrologEngine foo3 = new PrologEngine.PrologEngine();
            foo3.Assert("cell(1,2,b)");
            foo3.Assert("cell(2,3,o)");
            foreach (List <SWIPrologServiceLibrary.SolutionVariable> solutionVariables in foo3.GetSolutionVariables("cell(X,Y,Z)"))
            {
                ;
            }

            foreach (List <SWIPrologServiceLibrary.SolutionVariable> solutionVariables in foo2.GetSolutionVariables("cell(X,Y,Z)"))
            {
                ;
            }

            foreach (List <SWIPrologServiceLibrary.SolutionVariable> solutionVariables in foo.GetSolutionVariables("cell(X,Y,Z)"))
            {
                ;
            }
#endif
        }