public void PrintBoard()
 {
     for (int i = 0; i < Size; i++)
     {
         Console.WriteLine(BoardString.Substring(i * Size, Size));
     }
 }
Esempio n. 2
0
        public string BoardAsString()
        {
            string result = "";

            for (int i = 0; i < Size; i++)
            {
                result += BoardString.Substring(i * Size, Size);
                result += "\n";
            }
            return(result);
        }
Esempio n. 3
0
        public void PrintBoardToFile(string filename)
        {
            List <string> ls = new List <string>();

            for (int i = 0; i < Size; i++)
            {
                ls.Add(BoardString.Substring(i * Size, Size));
            }

            File.AppendAllLines(filename, ls, Encoding.Default);
        }
Esempio n. 4
0
            public void BoardStringToPieces()
            {
                List <Piece> newPieces = new List <Piece>();

                // TODO: verify BoardString is not null or empty
                // Update the list of Pieces given the boardstring

                // need to traverse the string backwards - or reorganize the data so it doesn't need to be backwards
                string[] rows = BoardString.Split('\n');
                for (int i = 0; i < rows.Length; i++)
                {
                    string row = rows[i];
                    for (int j = 0; j < row.Length; j++)
                    {
                        if (row[j] != '.')
                        {
                            Piece p = new Piece();  // TODO:  this prevents pawns from registering that they have moved
                            p.moved = true;
                            if (UnmovedPoints != null)
                            {
                                if (UnmovedPoints.Any(pt => pt.X == j + 1 && pt.Y == i + 1))
                                {
                                    p.moved = false;  // TODO:  this has to be tracked downstream
                                }
                            }
                            // set position
                            p.x = (j + 1).ToString()[0];
                            p.y = (i + 1).ToString()[0];
                            p.AlgebraicCoordinate = PointToAlgebraic(new Point(j, i));
                            // set color
                            if (char.IsUpper(row[j].ToString()[0]))
                            {
                                p.color = "w";
                            }
                            else
                            {
                                p.color = "b";  // TODO: extend this beyond upper/lower
                            }
                            // set type
                            p.type = row[j].ToString()[0].ToString(); // TODO:  rethink this - probably want more than the first character at some point
                            newPieces.Add(p);                         // TODO: rethink the upper/lower scenario above as now the UI is built on it
                        }
                    }
                }
                Pieces = newPieces;
            }
Esempio n. 5
0
        public async Task InitialiseState()
        {
            if (string.IsNullOrEmpty(BoardString))
            {
                _lastResult = await ApiClient.ChessGameAsync();
            }
            else
            {
                // NOTE: Blazor default routing gets confused by using '.' in the url and I couldn't work out how to fix it so...
                _lastResult = await ApiClient.ChessGameAsync(BoardString.Replace("_", "."));
            }

            if (_firstResult == null)
            {
                _firstResult = _lastResult;
            }

            Guard.NotNull(_lastResult, "Unable to initialise board");

            _moveCount = 0;
        }