示例#1
0
        public static Game GetOrCreateGame(Guid id)
        {
            Game game;

            if (_active.TryGetValue(id, out game))
                return game;

            game = new Game(id);
            _active[id] = game;
            return game;
        }
示例#2
0
文件: DeckFinder.cs 项目: Amarinal/S3
        public DeckFinder(Game game, Player originalPlayer, List<Player> testOponents, List<Card> inventory, int repeticiones = 0)
        {
            this.simulator = game;

            this.attacker = originalPlayer;
            this.oponents = testOponents;
            this.cardVault = inventory;

            if (repeticiones > 0) repeatCombat = repeticiones;

            attacker.Init();
            this.baseDeck = attacker.Deck.OrderBy(x=>x.Id).ToList();

            if (inventory != null) this.cardVault = inventory.OrderBy(X => X.Id).ToList();
        }
示例#3
0
文件: TestEngine.cs 项目: Amarinal/S3
        public TestEngine()
        {
            //Set initial Decks
            baseDeck = new List<Card>();
            Card card;
            card = new Card() { Attack = 1, Defense = 10, Delay = 0 }; baseDeck.Add(card);
            card = new Card() { Attack = 2, Defense = 5, Delay = 1 }; baseDeck.Add(card);
            card = new Card() { Attack = 3, Defense = 2, Delay = 2 }; baseDeck.Add(card);

            game = new Game();

            Player player;
            player = new Player() { HitPoints = 10, Name = "A", Id = 1 };
            game.PlayerA = player;
            player = new Player() { HitPoints = 10, Name = "B", Id = 2 };
            game.PlayerB = player;
        }
示例#4
0
文件: DeckFinder.cs 项目: Amarinal/S3
        public Player Search(int maxVariations, int depth, int width)
        {
            int times = -1;
            Player bestPlayer = attacker;
            List<Result> resultados = null;
            Game game = new Game(oponents);
            long elapsed;
            int pos = 0;

            Result result = simulator.FightAll(attacker, repeatCombat);
            this.winRate = result.Wins;

            while (times < width)
            {
                if (winRate > 99.9999) break;

                FindCandidates(maxVariations, depth, pos);

                resultados = new List<Result>();

                foreach(Player attacker in candidates)
                {
                    elapsed = DateTime.Now.Ticks;
                    resultados.Add(game.FightAll(attacker, repeatCombat));
                    Console.WriteLine(string.Format("Tiempo {0}:{1} ms {2:%#0.00}({3:%#0.00})", attacker.Name, (DateTime.Now.Ticks - elapsed) / 10000, resultados[resultados.Count - 1].Wins, resultados.Max(x => x.Wins)));
                }

                resultados = resultados.OrderByDescending(x => x.Wins).ThenByDescending(x => x.Id).ToList();

                if (resultados[0].Attacker.Id != attacker.Id && resultados[0].Wins > winRate)
                {
                    for(int i = 0; i < candidates.Count; i++)
                    {
                        if (resultados[0].Attacker.Id == candidates[i].Id)
                        {
                            pos = i;
                            break;
                        }
                    }

                    attacker = resultados[0].Attacker;
                    winRate = resultados[0].Wins;
                    Console.WriteLine(attacker.ToFullString());
                    times = 0;
                }
                else
                {
                    if (times < 0) times = 0;
                    times++;
                    pos = 0;
                }
            }

            Console.WriteLine(string.Format("Wins: {0:%#0.00}", winRate));
            return attacker;
        }
示例#5
0
文件: Program.cs 项目: Amarinal/S3
        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;
                }
            }
        }