Esempio n. 1
0
        public GTPEngine(GTPGoBoard gtpGoBoard, GTPCommBase outComm)
        {
            GTPGoBoard = gtpGoBoard;
            Out = outComm;

            InputBuffer = new StringBuilder(250);
            outComm.SetGTPEngine(this);
        }
Esempio n. 2
0
        public static int ConnectToCGOS(string name, string pPwd, int pNbr)
        {
            GoBoard lGoBoard = new GoBoard(9);
            GTPGoBoard lGTPGoBoard = new GTPGoBoard(lGoBoard);
            GTPCommCGOS lGTPCommCGOS = new GTPCommCGOS("cgos.boardspace.net", 6867, name, pPwd, pNbr, true);
            GTPEngine lGTPEngine = new GTPEngine(lGTPGoBoard, lGTPCommCGOS);

            lGTPCommCGOS.Run();

            return 0;
        }
Esempio n. 3
0
        public static int ConsoleGTP(MemFile file, bool loadSilent)
        {
            GoBoard lGoBoard = new GoBoard(9);
            GTPGoBoard lGTPGoBoard = new GTPGoBoard(lGoBoard);
            GTPCommConsole lGTPCommConsole = new GTPCommConsole();
            GTPEngine lGTPEngine = new GTPEngine(lGTPGoBoard, lGTPCommConsole);

            lGTPCommConsole.Silent = loadSilent;

            if (file != null)
                while (!file.EOF)
                {
                    string lLine = file.ReadLine();
                    Console.Error.WriteLine(lLine.Trim('\n'));
                    lGTPCommConsole.SendToEngine(lLine + '\n');
                }

            lGTPCommConsole.Silent = false;

            lGTPCommConsole.Listen();

            return 0;
        }
Esempio n. 4
0
 public static GTPInternalResponse GTPStopThinking(GTPGoBoard gtpGoBoard, GTPCommand gtpCommand)
 {
     gtpGoBoard.SearchEngine.StopSearch();
     return new GTPInternalResponse(true);
 }
Esempio n. 5
0
        public static GTPInternalResponse GTPTest(GTPGoBoard gtpGoBoard, GTPCommand gtpCommand)
        {
            PatternCollection lPatternCollection = new PatternCollection(@"patterns\test.db");
            gtpGoBoard.SearchEngine.SearchOptions.PatternDetector.Add(lPatternCollection);

            gtpGoBoard.SearchEngine.SearchOptions.MaxPly = 3;

            return GTPTopMoves(gtpGoBoard, Color.Black);
        }
Esempio n. 6
0
        public static GTPInternalResponse GTPProtectedLiberties(GTPGoBoard gtpGoBoard, GTPCommand gtpCommand)
        {
            if (gtpCommand.GetParameterCount() < 1)
                return MissingParametersResponse();

            Color lColor = new Color();

            if (!gtpCommand.GetParameter(0, ref lColor))
                return InvalidParameterResponse();

            StringBuilder s = new StringBuilder(512);

            for (int x = 0; x < gtpGoBoard.Board.BoardSize; x++)
                for (int y = 0; y < gtpGoBoard.Board.BoardSize; y++)
                    if (gtpGoBoard.Board.IsProtectedLiberty((gtpGoBoard.At(x, y)), lColor))
                    {
                        if (s.Length != 0)
                            s.Append(' ');

                        s.Append(gtpGoBoard.ToString(x, y));
                    }

            return new GTPInternalResponse(true, s.ToString());
        }
Esempio n. 7
0
        public static GTPInternalResponse GTPPlay(GTPGoBoard gtpGoBoard, GTPCommand gtpCommand)
        {
            if (gtpCommand.GetParameterCount() < 2)
                return MissingParametersResponse();

            Color lColor = new Color();

            if (!gtpCommand.GetParameter(0, ref lColor))
                return InvalidParameterResponse();

            string lPoint = gtpCommand.GetParameter(1);

            if (gtpGoBoard.Board.PlayStone((gtpGoBoard.At(lPoint)), lColor, true))
                return new GTPInternalResponse();
            else
                return new GTPInternalResponse(false, "invalid move");
        }
Esempio n. 8
0
 public static GTPInternalResponse GTPTopMovesBlack(GTPGoBoard gtpGoBoard, GTPCommand gtpCommand)
 {
     return GTPTopMoves(gtpGoBoard, Color.Black);
 }
Esempio n. 9
0
        public static GTPInternalResponse GTPUnconditionalStatus(GTPGoBoard gtpGoBoard, GTPCommand gtpCommand)
        {
            if (gtpCommand.GetParameterCount() < 1)
                return MissingParametersResponse();

            string lPoint = gtpCommand.GetParameter(0);

            return new GTPInternalResponse(true, gtpGoBoard.Board.GetSafetyStatus((gtpGoBoard.At(lPoint))).GTPString);
        }
Esempio n. 10
0
        public static GTPInternalResponse GTPSearchMethod(GTPGoBoard gtpGoBoard, GTPCommand gtpCommand)
        {
            if (gtpCommand.GetParameterCount() != 1)
                return MissingParametersResponse();

            string lMethod = gtpCommand.GetParameter(0);

            if (SearchMethodFactory.ToType(lMethod) == SearchMethodType.Unassigned)
                return InvalidParameterResponse();

            gtpGoBoard.SearchEngine.SetSearchMethod(SearchMethodFactory.ToType(lMethod));

            return new GTPInternalResponse(true);
        }
Esempio n. 11
0
        public static GTPInternalResponse GTPTimeLeft(GTPGoBoard gtpGoBoard, GTPCommand gtpCommand)
        {
            if (gtpCommand.GetParameterCount() < 2)
                return MissingParametersResponse();

            Color lColor = new Color();

            if (!gtpCommand.GetParameter(0, ref lColor))
                return InvalidParameterResponse();

            double lTimeLeft = 0;

            if (!gtpCommand.GetParameter(1, ref lTimeLeft))
                return InvalidParameterResponse();

            if ((lTimeLeft <= 0))
                return InvalidParameterResponse();

            int lStonesLeft = 0;

            if (gtpCommand.GetParameterCount() >= 3)
                if (!gtpCommand.GetParameter(2, ref lStonesLeft))
                    return InvalidParameterResponse();

            if (lColor.IsBoth)
            {
                gtpGoBoard.SearchEngine.TimeLeft[0] = lTimeLeft;
                gtpGoBoard.SearchEngine.TimeLeft[1] = lTimeLeft;
                gtpGoBoard.SearchEngine.StonesLeft[0] = lStonesLeft;
                gtpGoBoard.SearchEngine.StonesLeft[1] = lStonesLeft;
            }
            else
            {
                gtpGoBoard.SearchEngine.TimeLeft[lColor.ToInteger()] = lTimeLeft;
                gtpGoBoard.SearchEngine.StonesLeft[lColor.ToInteger()] = lStonesLeft;
            }

            return new GTPInternalResponse(true);
        }
Esempio n. 12
0
        public static GTPInternalResponse GTPSafetySolver(GTPGoBoard gtpGoBoard, GTPCommand gtpCommand)
        {
            if (gtpCommand.GetParameterCount() != 1)
                return MissingParametersResponse();

            string lMethod = gtpCommand.GetParameter(0);

            gtpGoBoard.Board.SetSafetySolver(SafetySolverFactory.ToType(lMethod));

            return new GTPInternalResponse(true);
        }
Esempio n. 13
0
        public static GTPInternalResponse GTPScoringSystem(GTPGoBoard gtpGoBoard, GTPCommand gtpCommand)
        {
            if (gtpCommand.GetParameterCount() < 1)
                return MissingParametersResponse();

            string lString = gtpCommand.GetParameter(0);

            if (ScoreFactoryFactory.ToType(lString) == ScoreType.Unassigned)
                return InvalidParameterResponse();

            gtpGoBoard.ScoreInterface = ScoreFactoryFactory.CreateFactory(lString);

            return new GTPInternalResponse(true);
        }
Esempio n. 14
0
        public static GTPInternalResponse GTPRegMove(GTPGoBoard gtpGoBoard, GTPCommand gtpCommand)
        {
            if (gtpCommand.GetParameterCount() < 1)
                return MissingParametersResponse();

            Color lColor = new Color();

            if (!gtpCommand.GetParameter(0, ref lColor))
                return InvalidParameterResponse();

            MoveList lMoveList = gtpGoBoard.SearchEngine.SimpleSearch(lColor);

            int lMove = lMoveList.GetBestMove();

            return new GTPInternalResponse(true, gtpGoBoard.Board.Coord.ToString(lMove));
        }
Esempio n. 15
0
 public static GTPInternalResponse GTPQueryBoardSize(GTPGoBoard gtpGoBoard, GTPCommand gtpCommand)
 {
     return new GTPInternalResponse(true, gtpGoBoard.Board.BoardSize.ToString());
 }
Esempio n. 16
0
 public static GTPInternalResponse GTPProtocolVersion(GTPGoBoard gtpGoBoard, GTPCommand gtpCommand)
 {
     return new GTPInternalResponse(true, "2");
 }
Esempio n. 17
0
        public static GTPInternalResponse GTPTestScoreNow(GTPGoBoard gtpGoBoard, GTPCommand gtpCommand)
        {
            int lScore = SimpleBoardEvaluator.EvaulateBoardPosition(gtpGoBoard.Board);

            return new GTPInternalResponse(true, lScore.ToString());
        }
Esempio n. 18
0
        public static GTPInternalResponse GTPSetFreeHandicap(GTPGoBoard gtpGoBoard, GTPCommand gtpCommand)
        {
            gtpGoBoard.Board.ClearBoard();
            gtpGoBoard.SearchEngine.GoalBase = null;

            foreach (string lPoint in gtpCommand.ParameterParts)
                if (!gtpGoBoard.Board.PlayStone(gtpGoBoard.At(lPoint), Color.Black, false))
                    return new GTPInternalResponse(false, "unknown error");

            return new GTPInternalResponse();
        }
Esempio n. 19
0
        public static GTPInternalResponse GTPAnalyzeCommands(GTPGoBoard gtpGoBoard, GTPCommand gtpCommand)
        {
            StringBuilder lCommands = new StringBuilder();

            foreach (AnalyzeCommand lAnalyzeCommand in gtpGoBoard.AnalyzeCommands)
                lCommands.AppendLine(lAnalyzeCommand.Type + "/" + lAnalyzeCommand.Label + "/" + lAnalyzeCommand.Command + " " + lAnalyzeCommand.Parameters);

            return new GTPInternalResponse(true, lCommands.ToString().TrimEnd('\n'));
        }
Esempio n. 20
0
        public static GTPInternalResponse GTPSetStartPly(GTPGoBoard gtpGoBoard, GTPCommand gtpCommand)
        {
            if (gtpCommand.GetParameterCount() < 1)
                return MissingParametersResponse();

            int lStartPly = 0;

            if (!gtpCommand.GetParameter(0, ref lStartPly))
                return InvalidParameterResponse();

            if (lStartPly <= 0)
                return InvalidParameterResponse();

            gtpGoBoard.SearchEngine.SearchOptions.StartPly = lStartPly;

            return new GTPInternalResponse(true);
        }
Esempio n. 21
0
        public static GTPInternalResponse GTPTopMoves(GTPGoBoard gtpGoBoard, GTPCommand gtpCommand)
        {
            if (gtpCommand.GetParameterCount() < 1)
                return MissingParametersResponse();

            Color lColor = new Color();

            if (!gtpCommand.GetParameter(0, ref lColor))
                return InvalidParameterResponse();

            return GTPTopMoves(gtpGoBoard, lColor);
        }
Esempio n. 22
0
        public static int Debug()
        {
            GoBoard lGoBoard = new GoBoard(9);
            GTPGoBoard lGTPGoBoard = new GTPGoBoard(lGoBoard);
            GTPCommConsole lGTPCommConsole = new GTPCommConsole();
            GTPEngine lGTPEngine = new GTPEngine(lGTPGoBoard, lGTPCommConsole);

            lGTPEngine.Receive("boardsize 9\n");
            lGTPEngine.Receive("gogui-play_sequence b A3 b A5 b A6 b A7 b A8 b A9 b B3 b B5 b B9 b C2 b C3 b C4 b C5 b C6 b C7 b D1 b D2 b D4 b D6 b D7 b E5 b E6 b F6 b G3 b G4 b G5 b G6 b G7 b H3 b H5 b H7 b H9 b J5 b J6 b J7 w A1 w A2 w B1 w B2 w B6 w B7 w B8 w C8 w C9 w D3 w D8 w E1 w E2 w E3 w E4 w E7 w E8 w F1 w F3 w F4 w F7 w F8 w F9 w G2 w G8 w G9 w H2 w H4 w H8 w J1 w J2 w J3 w J4 w J8\n");
            lGTPEngine.Receive("play b PASS\n");
            lGTPEngine.Receive("showboard\n");
            lGTPEngine.Receive("top_moves white\n");

            //			lGTPCommConsole.Listen();

            return 0;
        }
Esempio n. 23
0
 public static GTPInternalResponse GTPTopMovesWhite(GTPGoBoard gtpGoBoard, GTPCommand gtpCommand)
 {
     return GTPTopMoves(gtpGoBoard, Color.White);
 }
Esempio n. 24
0
        public static GTPInternalResponse GTPPlaySequence(GTPGoBoard gtpGoBoard, GTPCommand gtpCommand)
        {
            if (gtpCommand.GetParameterCount() % 2 != 0)
                return MissingParametersResponse();

            for (int i = 0; i < gtpCommand.GetParameterCount() / 2; i++)
            {
                Color lColor = new Color();

                if (!gtpCommand.GetParameter(i * 2, ref lColor))
                    return InvalidParameterResponse();

                string lPoint = gtpCommand.GetParameter((i * 2) + 1);

                if (!gtpGoBoard.Board.PlayStone((gtpGoBoard.At(lPoint)), lColor, true))
                    return new GTPInternalResponse(false, "invalid move - " + lPoint);
            }

            return new GTPInternalResponse();
        }
Esempio n. 25
0
        public static GTPInternalResponse GTPSetTranspositionTableSize(GTPGoBoard gtpGoBoard, GTPCommand gtpCommand)
        {
            if (gtpCommand.GetParameterCount() < 1)
                return MissingParametersResponse();

            int lTranspositionTableSize = 0;

            if (!gtpCommand.GetParameter(0, ref lTranspositionTableSize))
                return InvalidParameterResponse();

            if (lTranspositionTableSize <= 0)
                return InvalidParameterResponse();

            gtpGoBoard.SearchEngine.SearchOptions.TranspositionTableSize = lTranspositionTableSize;

            return new GTPInternalResponse(true);
        }
Esempio n. 26
0
        public static GTPInternalResponse GTPPonderOption(GTPGoBoard gtpGoBoard, GTPCommand gtpCommand)
        {
            bool lPonder = false;

            if (gtpCommand.GetParameterCount() < 1)
                lPonder = true;
            else
                if (!gtpCommand.GetParameter(0, ref lPonder))
                    return InvalidParameterResponse();

            gtpGoBoard.SearchEngine.SearchOptions.PonderOnOpponentsTime = lPonder;

            if (!lPonder)
                gtpGoBoard.SearchEngine.StopSearch();

            return new GTPInternalResponse(true);
        }
Esempio n. 27
0
        public static int SelfPlay()
        {
            GoBoard lGoBoard = new GoBoard(19);
            GTPGoBoard lGTPGoBoard = new GTPGoBoard(lGoBoard);
            GTPCommConsole lGTPCommConsole = new GTPCommConsole();
            GTPEngine lGTPEngine = new GTPEngine(lGTPGoBoard, lGTPCommConsole);

            lGTPEngine.Receive("boardsize 9\n");

            while (!lGoBoard.GameOver)
            {
                lGTPCommConsole.SendToEngine("genmove b\n");
                lGTPCommConsole.SendToEngine("showboard\n");
                lGTPCommConsole.SendToEngine("genmove w\n");
                lGTPCommConsole.SendToEngine("showboard\n");
            }

            return 0;
        }
Esempio n. 28
0
 public static GTPInternalResponse GTPShowBoard(GTPGoBoard gtpGoBoard, GTPCommand gtpCommand)
 {
     return new GTPInternalResponse(true, "Board:\n" + gtpGoBoard.Board.ToString().TrimEnd('\n'));
 }
Esempio n. 29
0
        public static GTPInternalResponse GTPSleep(GTPGoBoard gtpGoBoard, GTPCommand gtpCommand)
        {
            if (gtpCommand.GetParameterCount() < 1)
                return MissingParametersResponse();

            int lSleepTime = 0;

            if (!gtpCommand.GetParameter(0, ref lSleepTime))
                return InvalidParameterResponse();

            Thread.Sleep(new TimeSpan(0,0,lSleepTime));

            return new GTPInternalResponse(true);
        }
Esempio n. 30
0
        public static GTPInternalResponse GTPPatternValues(GTPGoBoard gtpGoBoard, GTPCommand gtpCommand)
        {
            if (gtpCommand.GetParameterCount() < 1)
                return MissingParametersResponse();

            Color lColor = new Color();

            if (!gtpCommand.GetParameter(0, ref lColor))
                return InvalidParameterResponse();

            PatternMap lPatternMap = gtpGoBoard.SearchEngine.SearchOptions.PatternDetector.FindPatterns(gtpGoBoard.Board, lColor);

            StringBuilder s = new StringBuilder(512);

            for (int lPosition = 0; lPosition < gtpGoBoard.Board.Coord.BoardArea; lPosition++)
            {
                int lValue = lPatternMap.GetValue(lPosition);

                if (lValue != 0)
                    s.Append(gtpGoBoard.Board.Coord.ToString(lPosition) + " " + (lValue).ToString() + " ");

            }

            return new GTPInternalResponse(true, s.ToString());
        }