示例#1
0
        public static string GenerateBook(string[] strippedInputs)
        {
            var moveStrings = strippedInputs;

            int i        = 0;
            var splitter = new char[] { ' ' };
            var sb       = new StringBuilder();

            var board = new Chess.Base.Board(true);

            foreach (var m in moveStrings)
            {
                try
                {
                    Console.WriteLine("Writing game #" + i);
                    //var sb = new StringBuilder();

                    board.InitBoard();
                    var moves   = ABN.ABNToMoves(board, m);
                    var winLose = m.Split(splitter, StringSplitOptions.RemoveEmptyEntries).Last();

                    if (winLose.Contains('1') && winLose.Contains('2'))
                    {
                        sb.Append("D ");
                    }
                    else if (winLose.Trim() == "1-0")
                    {
                        sb.Append("W ");
                    }
                    else if (winLose.Trim() == "0-1")
                    {
                        sb.Append("B ");
                    }
                    else
                    {
                        throw new Exception("No end result found");
                    }

                    for (int j = 0; j < 20 && j < moves.Count; j++)
                    {
                        sb.Append(Notation.TileToText(moves[j].From) + Notation.TileToText(moves[j].To));
                        sb.Append(" ");
                    }

                    sb.Append("\n");
                }
                catch (Exception)
                {
                    Console.WriteLine("Exception writing game #" + i);
                }
                i++;
            }

            return(sb.ToString());
        }
示例#2
0
        public static string GenerateBook(string[] strippedInputs)
        {
            var moveStrings = strippedInputs;

            int i = 0;
            var splitter = new char[] { ' ' };
            var sb = new StringBuilder();

            var board = new Chess.Base.Board(true);

            foreach(var m in moveStrings)
            {
                try
                {
                    Console.WriteLine("Writing game #" + i);
                    //var sb = new StringBuilder();

                    board.InitBoard();
                    var moves = ABN.ABNToMoves(board, m);
                    var winLose = m.Split(splitter, StringSplitOptions.RemoveEmptyEntries).Last();

                    if (winLose.Contains('1') && winLose.Contains('2'))
                        sb.Append("D ");
                    else if (winLose.Trim() == "1-0")
                        sb.Append("W ");
                    else if (winLose.Trim() == "0-1")
                        sb.Append("B ");
                    else
                        throw new Exception("No end result found");

                    for (int j = 0; j < 20 && j < moves.Count; j++)
                    {
                        sb.Append(Notation.TileToText(moves[j].From) + Notation.TileToText(moves[j].To));
                        sb.Append(" ");
                    }

                    sb.Append("\n");
                }
                catch (Exception)
                {
                    Console.WriteLine("Exception writing game #" + i);
                }
                i++;
            }

            return sb.ToString();
        }