Beispiel #1
0
        private bool TryGetValueAt(int row, int column, out int?value, out string error)
        {
            AccessibleBoard board = new AccessibleBoard
            {
                AccessibleTiles = new List <Tile>()
                {
                    new Tile(0), new Tile(1), new Tile(2), new Tile(null)
                },
                AccessibleBlankIndex          = 3,
                AccessibleSize                = 2,
                AccessibleIsSolved            = true,
                AccessibleTotalMisplacedTiles = 0
            };
            BoardValueFetcher boardValueFetcher = new BoardValueFetcher();
            bool found = boardValueFetcher.TryGetValueAt(board, row, column, out value, out error);

            return(found);
        }
Beispiel #2
0
        public virtual string Render(Board board)
        {
            StringBuilder     sb      = new StringBuilder();
            IEnumerable <int> indices = Enumerable.Range(0, board.Size);

            sb.AppendLine($"Number Of Misplaced Tiles: {board.TotalMisplacedTiles}");
            indices.ToList().ForEach(row =>
            {
                IEnumerable <string> rowValues = indices.Select(col =>
                {
                    if (!boardValueFetcher.TryGetValueAt(board, row, col, out int?value, out string error))
                    {
                        throw new System.Exception($"Something is wrong - can't get value at {row}/{col}: {error}");
                    }
                    else
                    {
                        return(value.HasValue ? $"{value.Value}" : "");
                    }
                });
                sb.AppendJoin("\t", rowValues);
                sb.Append(Environment.NewLine);
            });
            return(sb.ToString());
        }