Exemplo n.º 1
0
        static void Main(string[] args)
        {
            int counfOfGames = 100;

            int rndBotSum  = 0;
            int dblBotSum  = 0;
            int goodBotSum = 0;

            for (int _ = 0; _ < counfOfGames; _++)
            {
                RandomBot     rndBot  = new RandomBot("Rnd2000", 1000);
                DoubleBot     dblBot  = new DoubleBot("dbl2222", 1000);
                GoodBot       goodBot = new GoodBot("NotVeryGoodBot", 1000);
                List <Player> players = new List <Player> {
                    rndBot, dblBot, goodBot
                };
                Game blackJack = new Game(players);
                blackJack.StartGame(40);
                rndBotSum  += rndBot.Balance;
                dblBotSum  += dblBot.Balance;
                goodBotSum += goodBot.Balance;
            }

            ReadKey();

            Clear();

            WriteLine("Random bot: " + rndBotSum / counfOfGames);
            WriteLine("Double bot: " + dblBotSum / counfOfGames);
            WriteLine("HasStrategy bot: " + goodBotSum / counfOfGames);

            ReadKey();
        }
Exemplo n.º 2
0
        public ActionResult Mark(int row, int column, string botName, string state)
        {
            Game game = new Game();

            game.Board.Deserialize(state);

            game.Mark(row, column);

            if (game.IsOver)
            {
                return(this.RedirectToAction("GameOver", new { state = game.Board.Serialize() }));
            }

            IBot bot;

            switch (botName)
            {
            case "RandomBot": bot = new RandomBot(); break;

            case "MinMaxBot": bot = new MinMaxBot(); break;

            default: throw new ArgumentException("Unsupported bot!");
            }

            Tuple <int, int> move = bot.GetMove(game.Copy());

            game.Mark(move.Item1, move.Item2);

            if (game.IsOver)
            {
                return(this.RedirectToAction("GameOver", new { state = game.Board.Serialize() }));
            }

            return(this.RedirectToAction("Play", new { botName = botName, state = game.Board.Serialize() }));
        }
Exemplo n.º 3
0
        public IActionResult Mark(int row, int column)
        {
            Game game = this.SessionGet <Game>(this.SessionGameKey);

            game.Mark(row, column);

            if (!game.IsOver)
            {
                IBot bot;
                switch (this.SessionGet <string>(this.SessionBotKey))
                {
                case "RandomBot": bot = new RandomBot(); break;

                case "MinMaxBot": bot = new MinMaxBot(); break;

                default: throw new ArgumentException("Unsupported bot!");
                }

                Tuple <int, int> move = bot.GetMove(game.Copy());
                game.Mark(move.Item1, move.Item2);
            }

            this.SessionSet(this.SessionGameKey, game);

            return(this.RedirectToAction("Show"));
        }
        public void CorrectBetTest()
        {
            var bot = new RandomBot(900);

            Assert.IsNotNull(bot.MakeBets());

            Assert.Pass();
        }
        public void TakeAllMoneyTest()
        {
            var bot = new RandomBot(900);

            Assert.AreEqual(900, bot.Money);
            Assert.AreEqual(900, bot.TakeMoney(1500));
            Assert.AreEqual(0, bot.Money);

            Assert.Pass();
        }
Exemplo n.º 6
0
        private Player GetTestBot(int id)
        {
            var bot    = new RandomBot(id);
            var player = new Player(bot, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1))
            {
                Name = bot.GetPlayerName()
            };

            return(player);
        }
        public void GiveMoneyTest()
        {
            var bot = new RandomBot(900);

            Assert.AreEqual(900, bot.Money);
            bot.GiveMoney(100);
            Assert.AreEqual(1000, bot.Money);

            Assert.Pass();
        }
Exemplo n.º 8
0
        public void RandomBotShouldEvenlyDistributeThrowsTest()
        {
            // Arrange
            var randomBot = new RandomBot();
            var totalRockThrows = 0;
            var totalPaperThrows = 0;
            var totalScissorsThrows = 0;

            // Act
            for (int i = 0; i < 1000; i++)
            {
                var botMove = randomBot.MakeMove(null, null, null);
                if (botMove == Moves.Rock)
                    totalRockThrows++;
                else if (botMove == Moves.Paper)
                    totalPaperThrows++;
                else if (botMove == Moves.Scissors)
                    totalScissorsThrows++;
            }

            // Assert
            Assert.IsTrue(totalRockThrows / 10 >= 28,
                "Results: " +
                "Rock - " + totalRockThrows + " times. " +
                "Paper - " + totalPaperThrows + " times. " +
                "Scissors - " + totalScissorsThrows + " times.");
            Assert.IsTrue(totalRockThrows /10 <= 38,
                "Results: " +
                "Rock - " + totalRockThrows + " times." +
                "Paper - " + totalPaperThrows + " times." +
                "Scissors - " + totalScissorsThrows + " times.");

            Assert.IsTrue(totalPaperThrows / 10 >= 28,
                "Results: " +
                "Rock - " + totalRockThrows + " times. " +
                "Paper - " + totalPaperThrows + " times. " +
                "Scissors - " + totalScissorsThrows + " times.");
            Assert.IsTrue(totalPaperThrows / 10 <= 38,
                "Results: " +
                "Rock - " + totalRockThrows + " times. " +
                "Paper - " + totalPaperThrows + " times. " +
                "Scissors - " + totalScissorsThrows + " times.");

            Assert.IsTrue(totalScissorsThrows / 10 >= 28,
                "Results: " +
                "Rock - " + totalRockThrows + " times. " +
                "Paper - " + totalPaperThrows + " times. " +
                "Scissors - " + totalScissorsThrows + " times.");
            Assert.IsTrue(totalScissorsThrows / 10 <= 38,
                "Results: " +
                "Rock - " + totalRockThrows + " times. " +
                "Paper - " + totalPaperThrows + " times. " +
                "Scissors - " + totalScissorsThrows + " times.");
        }
        public void CreateTest()
        {
            var bot = new RandomBot(900);

            Assert.AreEqual(900, bot.Money);
            Assert.AreEqual("Random Bot", bot.Name);
            Assert.IsNotNull(bot.Description);

            Assert.IsNotNull(bot.ToString());

            Assert.Pass();
        }
Exemplo n.º 10
0
        public void MyBotShouldWinAgainstRandomBotTest()
        {
            // Arrange
            var me = new TestPlayer();
            var randomPlayer = new TestPlayer();

            var myBot = new MyBot();
            var randomBot = new RandomBot();

            // Act
            var winner = new GameEmulator().PlayMatch(me, myBot, randomPlayer, randomBot);

            // Assert
            Assert.AreSame(me, winner);
        }
Exemplo n.º 11
0
        private static void SelectPlayers(ref Player player1, ref Player player2)
        {
            Console.WriteLine("Select player 1");
            Console.WriteLine("\t H - Human Player; R - Random Bot; S - SmartBot: ");
            var choice1 = Console.ReadLine();

            Console.WriteLine("Select player 2");
            Console.WriteLine("\t H - Human Player; R - Random Bot; S - SmartBot;");
            var choice2 = Console.ReadLine();

            switch (choice1.ToUpper())
            {
            case "H":
                player1 = new HumanPlayer();
                break;

            case "R":
                player1 = new RandomBot();
                break;

            case "S":
                player1 = new SmartBot();
                break;

            default:
                player1 = null;
                break;
            }

            switch (choice2.ToUpper())
            {
            case "H":
                player2 = new HumanPlayer();
                break;

            case "R":
                player2 = new RandomBot();
                break;

            case "S":
                player2 = new SmartBot();
                break;

            default:
                player2 = null;
                break;
            }
        }
        public void DynamiteBeatsScissorsTest()
        {
            // Arrange
            var me = new MyBot();
            var randomBot = new RandomBot();

            var myMove = new BotMove { Player = me, Move = Moves.Dynamite };
            var theirMove = new BotMove { Player = randomBot, Move = Moves.Scissors };

            // Act
            var winner1 = new GameEmulator().DetermineWinner(myMove, theirMove);
            var winner2 = new GameEmulator().DetermineWinner(theirMove, myMove);

            // Assert
            Assert.AreSame(me, winner1);
            Assert.AreSame(me, winner2);
        }
        public void DynamiteTiesDynamiteTest()
        {
            // Arrange
            var me = new MyBot();
            var randomBot = new RandomBot();

            var myMove = new BotMove { Player = me, Move = Moves.Dynamite };
            var theirMove = new BotMove { Player = randomBot, Move = Moves.Dynamite };

            // Act
            var winner1 = new GameEmulator().DetermineWinner(myMove, theirMove);
            var winner2 = new GameEmulator().DetermineWinner(theirMove, myMove);

            // Assert
            Assert.IsNull(winner1);
            Assert.IsNull(winner2);
        }
        public void StopPlayingTest()
        {
            var bot = new RandomBot(900);

            var attempt = 0;

            while (bot.MakeBets().Count != 0 && attempt < maxAttempts)
            {
                attempt++;
            }

            if (bot.MakeBets().Count == 0 && attempt <= 40)
            {
                Assert.Pass();
            }

            Assert.Fail();
        }
Exemplo n.º 15
0
 public static bool Play()
 {
     if (currentPlayer == Piece.Party.white)
     {
         if (whitePlayer == PlayerType.Bot && !GameManager.doesGameFinish && GameManager.gameIsGoing)
         {
             RandomBot randomBot = new RandomBot();
             Piece     piece     = randomBot.GetRandomPieceFromBoard(Board.board);
             if (piece == null)
             {
                 return(false);
             }
             GameManager.lastPiece = piece;
             Game.mySquares[piece.position.GetCorX, piece.position.GetCorY].ToMouseLeftClick();
             Coordinate        moveCoordinate = randomBot.GetRandomMovePiece(Board.board, piece);
             List <Coordinate> coordinates    = new List <Coordinate>();
             coordinates.Add(moveCoordinate);
             GameManager.lastMovableList = coordinates;
             Game.mySquares[moveCoordinate.GetCorX, moveCoordinate.GetCorY].ToMouseRightClick();
         }
     }
     else
     {
         if (blackPlayer == PlayerType.Bot && !GameManager.doesGameFinish && GameManager.gameIsGoing)
         {
             RandomBot randomBot = new RandomBot();
             Piece     piece     = randomBot.GetRandomPieceFromBoard(Board.board);
             if (piece == null)
             {
                 return(false);
             }
             GameManager.lastPiece = piece;
             Game.mySquares[piece.position.GetCorX, piece.position.GetCorY].ToMouseLeftClick();
             Coordinate        moveCoordinate = randomBot.GetRandomMovePiece(Board.board, piece);
             List <Coordinate> coordinates    = new List <Coordinate>();
             coordinates.Add(moveCoordinate);
             GameManager.lastMovableList = coordinates;
             Game.mySquares[moveCoordinate.GetCorX, moveCoordinate.GetCorY].ToMouseRightClick();
         }
     }
     return(true);
 }
Exemplo n.º 16
0
        public void StartGameTest()
        {
            RandomBot randomBot = new RandomBot("RandomBot", 1000);
            Game      game      = new Game(new List <Player> {
                randomBot
            });

            game.StartGame();
            Assert.AreEqual(game.Players.Count, 0);
            Assert.AreEqual(randomBot.Balance, 0);
            GoodBot goodBot = new GoodBot("GoodBot", 1000);

            game = new Game(new List <Player> {
                goodBot
            });
            game.StartGame(40);
            Assert.IsTrue(goodBot.Balance != 1000);

            Assert.Pass();
        }
Exemplo n.º 17
0
        public void StartNewTurnTest()
        {
            GoodBot       goodBot   = new GoodBot("GoodBot", 1000);
            DoubleBot     doubleBot = new DoubleBot("DoubleBot", 1000);
            RandomBot     randomBot = new RandomBot("RandomBot", 1000);
            List <Player> players   = new List <Player> {
                goodBot, doubleBot, randomBot
            };
            Game game = new Game(players);

            game.StartNewTurn();
            foreach (Player player in players)
            {
                Assert.AreEqual(player.Cards.Count, 2);
                Assert.IsTrue(player.Balance < 1000);
                Assert.IsTrue(player.Bet > 0);
            }
            Assert.AreEqual(game.Croupier.Cards.Count, 2);

            Assert.Pass();
        }
Exemplo n.º 18
0
        private List <Player> SetPlayers()
        {
            List <Player> plrs          = new List <Player>();
            bool          chooseAnother = true;

            while (chooseAnother)
            {
                Console.WriteLine("Choose the type of Player you want to add: ");
                switch (Console.ReadLine())
                {
                case "human":
                    Console.Write("Enter the name: ");
                    string name = Console.ReadLine();
                    Console.Write("Choose a letter as Symbol: ");
                    string symbol = Console.ReadLine();
                    Player newGuy = new HumanPlayer(name, symbol);    //name and symbol in constructor of human player or here?
                    plrs.Add(newGuy);
                    break;

                case "rndBot":
                    Player newRnd = new RandomBot();
                    plrs.Add(newGuy);
                    break;

                case "Bot":
                    Player newBot = new SmartBot();
                    plrs.Add(newGuy);
                    break;

                case "s":
                    chooseAnother = false;
                    break;

                default:
                    Console.WriteLine("1 for human Player - 2 for random Bot - 3 for smart Bot  - s to start the Game");
                    break;
                }
            }
            return(plrs);
        }
Exemplo n.º 19
0
        /**
         * @param args args[0] Private key
         * @param args args[1] [training|arena]
         * @param args args[2] Game Id
         */

        private static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Usage: myBot.exe key training|arena gameId|showbrowser");
                Console.WriteLine("gameId is used to show browser in training mode");
                Console.ReadKey();
                return;
            }

            string serverURL    = "http://blitz2016.xyz:8080";
            string apiKey       = args[0];
            bool   trainingMode = args[1] == "training";
            string gameId       = args.Length == 3 && !trainingMode ? args[2] : null;
            bool   showBrowser  = trainingMode && args.Length == 3;

            IBestChoice bestChoice = new EvenBestChoice();
            IPathfinder pathfinder = new Disjkstra();

            ISimpleBot bot;

            if (bestChoice != null && pathfinder != null)
            {
                bot = new BestBot(bestChoice, pathfinder);
            }
            else
            {
                bot = new RandomBot();
            }

            // add a random param to start browser in training mode
            SimpleBotRunner runner = new SimpleBotRunner(
                new ApiToolkit(serverURL, apiKey, trainingMode, gameId, 1200),
                bot,
                showBrowser);

            runner.Run();

            Console.Read();
        }
        public void PaperBeatsRockTest()
        {
            // Arrange
            var me = new MyBot();
            var randomBot = new RandomBot();

            var myMove = new BotMove { Player = me, Move = Moves.Paper };
            var theirMove = new BotMove { Player = randomBot, Move = Moves.Rock };

            // Act
            var winner1 = new GameEmulator().DetermineWinner(myMove, theirMove);
            var winner2 = new GameEmulator().DetermineWinner(theirMove, myMove);

            // Assert
            Assert.AreSame(me, winner1);
            Assert.AreSame(me, winner2);
        }
Exemplo n.º 21
0
 /// <summary>
 /// In CreateGameBoardInstance you have created the gameboard, now use it with your bot.
 /// </summary>
 public override void DoMove()
 {
     RandomBot.DoTurn(gameboard);
     gameboard.FinishTurn();
 }
Exemplo n.º 22
0
        static void Main(string[] args)
        {
            Console.WriteLine(
                @"Choose bots to play with. 
-""Human Bot"" to play.
-""Min Max Bot"" to play a good robot
-""Cheat Bot"" to crash the game in 2 turns.
-""First Bot"" to play a bot who chooses the first open square.
-""Random Bot"" to fight a random bot.");
            IBot xBot = null;
            Game game = new Game();
            IBot oBot = null;

            do
            {
                string input = Console.ReadLine();
                switch (input)
                {
                case "Human Bot":
                    xBot = new HumanBot();
                    break;

                case "Cheat Bot":
                    xBot = new CheatBot();
                    break;

                case "Min Max Bot":
                    xBot = new MinMaxBot();
                    break;

                case "First Bot":
                    xBot = new FirstBot();
                    break;

                case "Random Bot":
                    xBot = new RandomBot();
                    break;

                default:
                    Console.WriteLine("Please pick a type of bot");
                    break;
                }
            } while (xBot == null);
            Console.WriteLine("Now choose the other player.");
            do
            {
                string input = Console.ReadLine();
                switch (input)
                {
                case "Human Bot":
                    oBot = new HumanBot();
                    break;

                case "Cheat Bot":
                    oBot = new CheatBot();
                    break;

                case "Min Max Bot":
                    oBot = new MinMaxBot();
                    break;

                case "First Bot":
                    oBot = new FirstBot();
                    break;

                case "Random Bot":
                    oBot = new RandomBot();
                    break;

                default:
                    Console.WriteLine("Please pick a type of bot");
                    break;
                }
            } while (oBot == null);



            Console.WriteLine($"{xBot.Name} (X) vs. {oBot.Name} (O)");

            while (!game.IsOver)
            {
                // Make a copy of the game and give it to the bot. This allows the bot to do
                // whatever it wants to the copy without messing up our official game.
                Game botGame = game.Copy();

                IBot             bot  = game.IsXTurn ? xBot : oBot;
                Tuple <int, int> move = bot.GetMove(botGame);
                game.Mark(move.Item1, move.Item2);

                Console.WriteLine($"{bot.Name} selected ({move.Item1}, {move.Item2})");

                Console.WriteLine(game.Board.ToString());
            }

            if (game.IsXWin)
            {
                Console.WriteLine($"{xBot.Name} wins!");
            }
            else if (game.IsOWin)
            {
                Console.WriteLine($"{oBot.Name} wins!");
            }
            else if (game.IsTie)
            {
                Console.WriteLine($"Game is a tie!");
            }
            else
            {
                Console.WriteLine("How did we get here?");
            }

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
Exemplo n.º 23
0
        void StartGame_Clicked(object sender, System.EventArgs e)
        {
            // Figure out size of board
            Board b = null;

            switch (ddlDimensions.SelectedIndex)
            {
            case 0: b = Board.NewBoard(3, 6, 3); break;

            case 1: b = Board.NewBoard(4, 9, 4); break;

            case 2: b = Board.NewBoard(5, 11, 5); break;

            default: b = Board.NewBoard(7, 13, 6); break;
            }

            // Figure out dice rule
            switch (ddlDiceRule.SelectedIndex)
            {
            case 0: b.BattleRule = new AlwaysWin(); break;

            case 1: b.BattleRule = new HighestRoll(); break;

            default: b.BattleRule = new RankedDice(); break;
            }

            // Figure out reinforcement rule
            switch (ddlReinforcements.SelectedIndex)
            {
            case 0: b.ReinforcementRule = new RandomAnywhere(); break;

            case 1: b.ReinforcementRule = new RandomWithinLargestArea(); break;

            default: b.ReinforcementRule = new RandomBorder(); break;
            }

            // Full auto play means all players are bots
            if (!cbxAutoPlay.IsToggled)
            {
                b.Players[0].IsHuman = true;
            }

            // Computer Difficulty
            IBot bot = null;

            switch (ddlDifficulty.SelectedIndex)
            {
            case 0: bot = new BorderShrinkBot(); break;

            case 1: bot = new TurtleBot(); break;

            default: bot = new RandomBot(); break;
            }
            foreach (var p in b.Players)
            {
                if (!p.IsHuman)
                {
                    p.Bot = bot;
                }
            }

            // Start game
            Navigation.PushModalAsync(new MainPage(b));
        }