Skip to content
Snippets Groups Projects
Select Git revision
  • 481b846d7d38f9640c843fb079d50583bfa6893d
  • main default protected
2 results

CardMechanic.cs

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    CardMechanic.cs 2.42 KiB
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace Levenshtein
    {
        public class CardMechanic
        {
            const string pathScrambled = "../../../textdocs/scrambled.txt";
            const string pathReference = "../../../textdocs/reference.txt";
            const string pathFixed = "../../../textdocs/fixed.txt";
            
            private List<Cards> _cards = new List<Cards>();
            private List<string> _references = new List<string>();
            public void ReadFromScrambled()
                
            {
                var read = System.IO.File.ReadLines(pathScrambled);
                foreach (string line in read)
                {
    
                    var part = line.Split('|');
                    var card = new Cards()
                    {
                        Name = part[0],
                        Mana = part[1],
                        Cmc = double.Parse(part[2]),
                        Type = part[3],
                        Count = double.Parse(part[4]),
                    };
                    _cards.Add(card);
                    
                }
                
    
            }
    
            public void CardsToFile()
            {
                using (StreamWriter writer = new StreamWriter(pathFixed))
                {
                    foreach (Cards card in _cards)
                    {
                        writer.WriteLine(card.Name + "|" + card.Mana + "|" + card.Cmc + "|" + card.Type + "|" + card.Count);
                    }
                }
            }
    
            public void ReadFromReference()
            {
                var read = System.IO.File.ReadLines(pathReference);
                foreach (string line in read)
                {
                    _references.Add(line);
                }
            }
    
            public void RestoreCards()
            {
                //int counter = 0;
                foreach (Cards card in _cards)
                {
                    foreach (string reference in _references)
                    {
                        Levenshtein l = new Levenshtein(card.Name, reference);
                        if ((l.LevenshteinDistance() < (reference.Length * 0.2675)))
                        {
                            card.Name = reference;
                            //System.Console.WriteLine(card.Name);
                            //System.Console.WriteLine(reference);
                            //counter++;
                        }
                    }
                    
                }
                //System.Console.WriteLine(counter);
                CardsToFile();
            }
        }
        
    }