public MainWindow()
        {
            InitializeComponent();
            CreatePieceBoxes();

            board = new Board();
            board.SetupStandardBoard();

            RenderBoard(board);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            string wholeFile = "";
            List<Tuple<Board, Move>> allData = new List<Tuple<Board, Move>>();

            using(StreamReader fs = new StreamReader(File.OpenRead(".\\Ivanchuk.pgn")))
                wholeFile = fs.ReadToEnd();

            string[] games = Regex.Split(wholeFile, "\\[Event.*\\]\r\n\r\n");

            PgnParser.Parser parser = new PgnParser.Parser();

            for (int i = 0; i < 100; i++)
            {
                Board board = new Board();
                var enu = parser.Parse(games[i]).GetEnumerator();
                board.SetupStandardBoard();

                while (enu.MoveNext())
                {
                    board = board.MakeMove(enu.Current.From, enu.Current.To);
                    allData.Add(new Tuple<Board, Move>(board, enu.Current));
                }
            }

            Board b = allData[263].Item1;
            var mostSimilars = allData.Where(x => x.Item1.WhosMove == b.WhosMove).
                                       OrderBy(x => Similarity.Calculate(x.Item1, b)).ToList();
            Move suggestedMove = new Move(-1, -1);

            for (int i = 0; i < mostSimilars.Count; i++)
            {
                Tuple<Board, Move> tup = mostSimilars[i];
                suggestedMove = tup.Item2;
                if (b.AllMoves.Contains(suggestedMove))
                    break;
            }
        }
Exemple #3
0
        static Parser()
        {
            string wholeFile = "";

            using (StreamReader fs = new StreamReader(File.OpenRead(".\\Ivanchuk.pgn")))
                wholeFile = fs.ReadToEnd();

            string[] games = Regex.Split(wholeFile, "\\[Event.*\\]\r\n\r\n");

            PgnParser.Parser parser = new PgnParser.Parser();

            for (int i = 0; i < 100; i++)
            {
                Board board = new Board();
                var enu = parser.Parse(games[i]).GetEnumerator();
                board.SetupStandardBoard();

                while (enu.MoveNext())
                {
                    allData.Add(new Tuple<Board, Move>(board, enu.Current));
                    board = board.MakeMove(enu.Current.From, enu.Current.To);
                }
            }
        }
Exemple #4
0
        public IEnumerable<Move> Parse(string pgn)
        {
            string tmp = RemoveNonsense(pgn);
            string[] byMoves = SplitIntoMoves(tmp);

            bool whiteMove = true;

            Thursday.Board board = new Thursday.Board();
            board.SetupStandardBoard();

            int curMove = 0;

            foreach (string move in byMoves)
            {
                string[] ms = move.Split(whiteSpaces, StringSplitOptions.RemoveEmptyEntries);

                if (ms.Length == 0)
                {
                    // Boring.  Just continue
                }
                else if (ms.Length == 2)
                {
                    if (IsEndStatement(ms[0])) goto ended;

                    Move move1 = ParseMove(ms[0], board);
                    board = board.MakeMove(move1.From, move1.To);
                    curMove++;

                    PrintDebug(curMove, board);

                    yield return move1;

                    if (IsEndStatement(ms[1])) goto ended;

                    Move move2 = ParseMove(ms[1], board);
                    board = board.MakeMove(move2.From, move2.To);
                    curMove++;

                    PrintDebug(curMove, board);

                    yield return move2;
                }
                else if (ms.Length == 1)
                {
                    if (IsEndStatement(ms[0])) goto ended;

                    Move move1 = ParseMove(ms[0], board);
                    board = board.MakeMove(move1.From, move1.To);
                    curMove++;

                    PrintDebug(curMove, board);

                    yield return move1;
                }
                else if (ms.Length == 3 && IsEndStatement(ms[2]))
                {
                    Move move1 = ParseMove(ms[0], board);
                    board = board.MakeMove(move1.From, move1.To);
                    curMove++;

                    PrintDebug(curMove, board);

                    yield return move1;

                    Move move2 = ParseMove(ms[1], board);
                    board = board.MakeMove(move2.From, move2.To);
                    curMove++;

                    PrintDebug(curMove, board);

                    yield return move2;

                    goto ended;
                }
                else
                {
                    throw new ApplicationException("Not 0 1 or 2 moves found");
                }
            }

            ended:
            ;
        }