public void LoadFromFiles(String cardPath = null, String playersPath = null) { if (cardPath == null) { cardPath = @"Cartas.csv"; } if (playersPath == null) { playersPath = @"Players.csv"; } cards = new CardCollection(); cards.ReadFromFile(cardPath); HelperCsv fichero = new HelperCsv(playersPath); Player player; oponentes = new List <Player>(); for (int i = 0; i < fichero.Count; i++) { player = new Player(); player.LoadFromCsv(fichero, i, this.cards); oponentes.Add(player); } }
public void LoadFromCsv(HelperCsv csv, int line, CardCollection cards) { this.deckOriginal = new List <Card>(); this.Id = line; this.Name = csv[line, "Name"]; //this.HitPoints = Convert.ToInt32(csv[line, "Hitpoints"]); Card card = null; string[] carta; for (int i = 1; i < 16; i++) { carta = csv[line, "Card" + i.ToString()].Split(';'); int level = 0; if (carta.Length > 1) { level = Convert.ToInt32(carta[1]); } card = cards.GetCard(carta[0], level); if (card != null) { this.deckOriginal.Add(card); } } this.deckOriginal = deckOriginal.OrderBy(x => x.Id).ToList(); string hero = csv[line, "Hero"]; SetHero(hero); }
public void ReadFromFile(String path =@".\cartas.csv") { this.cards = new List<Card>(); HelperCsv fichero = new HelperCsv(path); Card card; for (int i = 0; i < fichero.Count; i++) { card = new Card(); //Id;Name;Rarity;Fuse;Level;Attack;Defense;Delay;Faction1;Faction2;Faction3;Skill1;Skill2;Skill3;Skill4;Skill5 card.Id = Convert.ToInt32(fichero[i, "Id"]); card.Name = fichero[i, "Name"]; card.Rarity = fichero[i, "Rarity"]; card.Fuse = fichero[i, "Fuse"]; card.Delay = Convert.ToInt32(fichero[i, "Delay"]); card.Level = Convert.ToInt32(fichero[i, "Level"]); card.Attack = Convert.ToInt32(fichero[i, "Attack"]); card.Defense = Convert.ToInt32(fichero[i, "Defense"]); if (!String.IsNullOrWhiteSpace(fichero[i, "Faction1"])) card.Factions.Add(fichero[i, "Faction1"]); if (!String.IsNullOrWhiteSpace(fichero[i, "Faction2"])) card.Factions.Add(fichero[i, "Faction2"]); if (!String.IsNullOrWhiteSpace(fichero[i, "Faction3"])) card.Factions.Add(fichero[i, "Faction3"]); if (!String.IsNullOrWhiteSpace(fichero[i, "Skill1"])) card.AddSkillFromText(fichero[i, "Skill1"]); if (!String.IsNullOrWhiteSpace(fichero[i, "Skill2"])) card.AddSkillFromText(fichero[i, "Skill2"]); if (!String.IsNullOrWhiteSpace(fichero[i, "Skill3"])) card.AddSkillFromText(fichero[i, "Skill3"]); if (!String.IsNullOrWhiteSpace(fichero[i, "Skill4"])) card.AddSkillFromText(fichero[i, "Skill4"]); if (!String.IsNullOrWhiteSpace(fichero[i, "Skill5"])) card.AddSkillFromText(fichero[i, "Skill5"]); this.cards.Add(card); } }
public void ReadFromFile(String path = @".\cartas.csv") { this.cards = new List <Card>(); HelperCsv fichero = new HelperCsv(path); Card card; for (int i = 0; i < fichero.Count; i++) { card = new Card(); //Id;Name;Rarity;Fuse;Level;Attack;Defense;Delay;Faction1;Faction2;Faction3;Skill1;Skill2;Skill3;Skill4;Skill5 card.Id = Convert.ToInt32(fichero[i, "Id"]); card.Name = fichero[i, "Name"]; card.Rarity = fichero[i, "Rarity"]; card.Fuse = fichero[i, "Fuse"]; card.Delay = Convert.ToInt32(fichero[i, "Delay"]); card.Level = Convert.ToInt32(fichero[i, "Level"]); card.Attack = Convert.ToInt32(fichero[i, "Attack"]); card.Defense = Convert.ToInt32(fichero[i, "Defense"]); if (!String.IsNullOrWhiteSpace(fichero[i, "Faction1"])) { card.Factions.Add(fichero[i, "Faction1"]); } if (!String.IsNullOrWhiteSpace(fichero[i, "Faction2"])) { card.Factions.Add(fichero[i, "Faction2"]); } if (!String.IsNullOrWhiteSpace(fichero[i, "Faction3"])) { card.Factions.Add(fichero[i, "Faction3"]); } if (!String.IsNullOrWhiteSpace(fichero[i, "Skill1"])) { card.AddSkillFromText(fichero[i, "Skill1"]); } if (!String.IsNullOrWhiteSpace(fichero[i, "Skill2"])) { card.AddSkillFromText(fichero[i, "Skill2"]); } if (!String.IsNullOrWhiteSpace(fichero[i, "Skill3"])) { card.AddSkillFromText(fichero[i, "Skill3"]); } if (!String.IsNullOrWhiteSpace(fichero[i, "Skill4"])) { card.AddSkillFromText(fichero[i, "Skill4"]); } if (!String.IsNullOrWhiteSpace(fichero[i, "Skill5"])) { card.AddSkillFromText(fichero[i, "Skill5"]); } this.cards.Add(card); } }
static void Main(string[] args) { Console.Clear(); Console.Write("Comando>"); String command; Boolean quitNow = false; string[] elementos; long elapsed = 0; int veces = 1; Player player = null; Player defender = null; List<Result> resultados = new List<Result>(); Dictionary<String, String> argumentos; string playersPath = null; String options = null; string attackerName = null; string defenderName = null; Game game = null; while (!quitNow) { string[] comando; string key, value; command = Console.ReadLine(); elementos = command.Split(' '); command = elementos[0]; argumentos = new Dictionary<string, string>(); foreach (String elemento in elementos) { key = value = elemento; if (elemento.StartsWith("-")) { key = elemento.Substring(1); if (elemento.Contains(":")) { comando = elemento.Split(':'); key = comando[0].Substring(1); value = comando[1]; } } argumentos.Add(key, value); } switch (command.ToLower()) { case "clear": game = null; player = null; defender = null; resultados = new List<Result>(); playersPath = null; options = null; attackerName = null; defenderName = null; break; case "c": case "combat": //c -a:Bambori -d:herres47 -o:t,f if (argumentos.Keys.Contains("a")) attackerName = argumentos["a"]; if (argumentos.Keys.Contains("d")) defenderName = argumentos["d"]; if (argumentos.Keys.Contains("o")) options = argumentos["o"]; if (game == null) { game = new Game(); game.LoadFromFiles(null, playersPath); if (!string.IsNullOrWhiteSpace(options)) game.SetOptions(options); player = game.Oponentes.FirstOrDefault(x => x.Name == attackerName); defender = game.Oponentes.FirstOrDefault(x => x.Name == defenderName); game.BeginSteppedCombat(player, defender); } if (game.IsCombatInProgress) game.DoTurn(); Console.WriteLine(game.StateString()); break; case "war": //war -v:5 -o:default elapsed = DateTime.Now.Ticks; bool writeFiles = false; if (argumentos.Keys.Contains("v")) veces = Convert.ToInt32(argumentos["v"]); if (argumentos.Keys.Contains("p")) playersPath = argumentos["p"]; if (argumentos.Keys.Contains("o")) options = argumentos["o"]; if (argumentos.Keys.Contains("out")) writeFiles = true; game = new Game(); game.LoadFromFiles(null, playersPath); if (!string.IsNullOrWhiteSpace(options)) game.SetOptions(options); resultados = game.War(veces); if (writeFiles) { game.Result2CSV(); Console.WriteLine("Done!"); } else { Console.WriteLine(game.ResultString()); } Console.WriteLine(string.Format("Tiempo total:{0} ms", (DateTime.Now.Ticks - elapsed) / 10000)); break; case "sim"://sim -v:50 -dp:16 -w:4 -var:3 elapsed = DateTime.Now.Ticks; int depth = 64; int width = 2; int variations = 3; string inventoryPath = "inventory.csv"; if (argumentos.Keys.Contains("v")) veces = Convert.ToInt32(argumentos["v"]); if (argumentos.Keys.Contains("dp")) depth = Convert.ToInt32(argumentos["dp"]); if (argumentos.Keys.Contains("w")) width = Convert.ToInt32(argumentos["w"]); if (argumentos.Keys.Contains("var")) variations = Convert.ToInt32(argumentos["var"]); if (argumentos.Keys.Contains("p")) playersPath = argumentos["p"]; if (argumentos.Keys.Contains("i")) inventoryPath = argumentos["i"]; if (argumentos.Keys.Contains("a")) attackerName = argumentos["a"]; if (argumentos.Keys.Contains("o")) options = argumentos["o"]; if (argumentos.Keys.Contains("d")) defenderName = argumentos["d"]; List<Card> inventory = new List<Card>(); game = new Game(); game.LoadFromFiles(); HelperCsv file = new HelperCsv(inventoryPath); for(int i = 0; i < file.Count; i++) { inventory.Add(game.Cards.GetCard(file[i, "Name"], 0)); } player = game.Oponentes.FirstOrDefault(x => x.Name == attackerName); defender = game.Oponentes.FirstOrDefault(x => x.Name == defenderName); if (player != null) { game.Oponentes.Remove(player); if (!string.IsNullOrWhiteSpace(options)) game.SetOptions(options); if (defender != null) { game.Oponentes.Clear(); game.Oponentes.Add(defender); } DeckFinder simDeck= new DeckFinder(game, player, game.Oponentes, inventory, veces); player = simDeck.Search(variations, depth, width); Console.WriteLine(player.ToFullString()); } Console.WriteLine(string.Format("Tiempo total:{0} ms", (DateTime.Now.Ticks - elapsed) / 10000)); break; case "f": case "fight"://f -v:2 -a:Bambori -d:herres47 -o:t,f elapsed = DateTime.Now.Ticks; Result result; defender = null; if (argumentos.Keys.Contains("v")) veces = Convert.ToInt32(argumentos["v"]); if (argumentos.Keys.Contains("a")) attackerName = argumentos["a"]; if (argumentos.Keys.Contains("d")) defenderName = argumentos["d"]; if (argumentos.Keys.Contains("o")) options = argumentos["o"]; game = new Game(); game.LoadFromFiles(); player = game.Oponentes.FirstOrDefault(x => x.Name == attackerName); defender = game.Oponentes.FirstOrDefault(x => x.Name == defenderName); if (player != null) { game.Oponentes.Remove(player); if (defender != null) { game.Oponentes.Clear(); game.Oponentes.Add(defender); } if (!string.IsNullOrWhiteSpace(options)) game.SetOptions(options); result = game.FightAll(player, veces); Console.WriteLine(string.Format("WinRatio: {0:%#0.00}. Battles:{1}", result.Wins, result.BattleCount)); } Console.WriteLine(string.Format("Tiempo total:{0} ms", (DateTime.Now.Ticks - elapsed) / 10000)); break; case "quit": quitNow = true; break; default: //Console.WriteLine("Unknown Command " + command); break; } } }
public void LoadFromFiles(String cardPath = null, String playersPath = null) { if (cardPath == null) cardPath = @"Cartas.csv"; if (playersPath == null) playersPath = @"Players.csv"; cards = new CardCollection(); cards.ReadFromFile(cardPath); HelperCsv fichero = new HelperCsv(playersPath); Player player; oponentes = new List<Player>(); for (int i = 0; i < fichero.Count; i++) { player = new Player(); player.LoadFromCsv(fichero, i, this.cards); oponentes.Add(player); } }
public void LoadFromCsv(HelperCsv csv, int line, CardCollection cards) { this.deckOriginal = new List<Card>(); this.Id = line; this.Name = csv[line, "Name"]; //this.HitPoints = Convert.ToInt32(csv[line, "Hitpoints"]); Card card = null; string[] carta; for(int i = 1; i < 16; i++) { carta = csv[line, "Card" + i.ToString()].Split(';'); int level = 0; if (carta.Length > 1) level = Convert.ToInt32(carta[1]); card = cards.GetCard(carta[0], level); if (card != null) this.deckOriginal.Add(card); } this.deckOriginal = deckOriginal.OrderBy(x => x.Id).ToList(); string hero = csv[line, "Hero"]; SetHero(hero); }