예제 #1
0
        static void Main(string[] args)
        {
            // Instanciation des deux joueurs
            var op1 = new DreadnoughtBasic();
            var op2 = new DreadnoughtImproved();

            // Instanciation de la compétition
            BattleshipCompetition bc = new BattleshipCompetition(
                op1,                     // Joueur 1
                op2,                     // Joueur 2
                new TimeSpan(0, 0, 1),   // Durée maximale d'une partie
                500,                     // Nombre de parties gagnantes nécessaires
                false,                   // Jouer tous les matchs ?
                new Size(10, 10),        // Taille de la grille
                2, 3, 3, 4, 5            // Liste des tailles des bateaux
                );

            // Lancement de la compétition
            var scores = bc.RunCompetition();

            // Affichage des scores
            foreach (var key in scores.Keys.OrderByDescending(k => scores[k]))
            {
                Console.WriteLine("{0} {1}:\t{2}", key.Name, key.Version, scores [key]);
            }

            Console.ReadKey(true);
        }
예제 #2
0
        static void Main(string[] args)
        {
            var op1 = new SmartAI();
            var op2 = new RandomOpponent();

            BattleshipCompetition bc = new BattleshipCompetition(
                op1,
                op2,
                new Size(10, 10),       // Board Size
                2, 3, 3, 4, 5           // Ship Sizes
            );

            var winner = bc.RunCompetition();

            Console.WriteLine("{0} won the match!", winner.Name);

            Console.ReadKey(true);
        }
예제 #3
0
        static void Main(string[] args)
        {
            IBattleshipOpponent[] opponents;
            try
            {
                var loader = new OpponentLoader();
                opponents = loader.LoadFrom(args);
            }
            catch (Exception e)
            {
                DisplayUsage(e.Message);
                return;
            }

            BattleshipCompetition bc = new BattleshipCompetition(
                opponents[0],
                opponents[1],
                new TimeSpan(0, 0, 4),  // Time per game
                501,                    // Wins per match
                true,                   // Play out?
                new Size(10, 10),       // Board Size
                2, 3, 3, 4, 5           // Ship Sizes
            );

            Console.WriteLine("Battleship AI");
            Console.WriteLine("{0} v{1} vs. {2} v{3}",
                opponents[0].Name, opponents[0].Version,
                opponents[1].Name, opponents[1].Version
            );

            var scores = bc.RunCompetition();

            var lengthOfLongestName = scores.Keys
                .Select(k => string.Format("{0} v{1}", k.Name, k.Version))
                .Max(n => n.Length);
            var scoreFormat = string.Format("{{0,-{0}}}: {{1}}", lengthOfLongestName);

            foreach (var key in scores.Keys.OrderByDescending(k => scores[k]))
            {
                Console.WriteLine(scoreFormat, string.Format("{0} v{1}", key.Name, key.Version), scores[key]);
            }
            Console.WriteLine("Press any key to quit.");
            Console.ReadKey(true);
        }
예제 #4
0
        static void Main(string[] args)
        {
            var op1 = new RandomOpponent();
            var op2 = new RandomOpponent();

            BattleshipCompetition bc = new BattleshipCompetition(
                op1,
                op2,
                new TimeSpan(0, 0, 1),  // Time per game
                51,                     // Wins per match
                true,                   // Play out?
                new Size(10, 10),       // Board Size
                2, 3, 3, 4, 5           // Ship Sizes
            );

            var scores = bc.RunCompetition();

            foreach (var key in scores.Keys.OrderByDescending(k => scores[k]))
            {
                Console.WriteLine("{0} {1}:\t{2}", key.Name, key.Version, scores[key]);
            }

            Console.ReadKey(true);
        }