/// <summary>
        /// Parse method, implements the Strategy pattern.
        /// </summary>
        /// <remarks>
        /// The object recieves concrete strategy implementation of the renderer
        /// </remarks>
        /// <param name="renderer">
        /// Must be an instance of IRenderer
        /// </param>
        /// <param name="score">
        /// Must be an instance of IScoreBoard
        /// </param>
        public void Parse(IRenderer renderer, IScoreBoard score)
        {
            switch (this.Player.Command)
            {
            case PlayerCommand.InvalidMove:
                renderer.Render(INVALID_MOVE_MESSAGE);
                break;

            case PlayerCommand.InvalidCommand:
                renderer.Render(INVALID_COMMAND_MESSAGE);
                break;

            case PlayerCommand.PrintTopScores:
                score.Render(renderer);
                break;

            case PlayerCommand.Restart:
                this.IsRestartCommandEntered = true;
                renderer.Clear();
                return;

            case PlayerCommand.Exit:
                renderer.Render(GOODBYE_MESSAGE);
                this.IsExitCommandEntered = true;
                return;
            }
        }
Esempio n. 2
0
 public MiniMaxPlayer(int player, int depth, IScoreBoard sb, bool firstMoveRandom) : base(player, depth, sb, firstMoveRandom)
 {
     Player          = player;
     Depth           = depth;
     Sb              = sb;
     FirstMoveRandom = firstMoveRandom;
     times           = new List <TimeSpan>();
 }
Esempio n. 3
0
 public AIPlayer(int player, int depth, IScoreBoard sb, bool firstMoveRandom)
 {
     Player          = player;
     Depth           = depth;
     Sb              = sb;
     FirstMoveRandom = firstMoveRandom;
     //times = new List<TimeSpan>();
 }
Esempio n. 4
0
 /// <summary>
 /// LabyrinthGame consturctor
 /// <remarks>
 /// Will initiate the console renderer and all other required classes
 /// </remarks>
 /// </summary>
 public LabyrinthGame()
 {
     this.Renderer  = new ConsoleRenderer();
     this.commander = new Commander();
     this.Scores    = ScoreBoardCreator.CreateScoreBoard();
     this.Player    = PlayerCreator.CreatePlayer();
     this.Maze      = this.InitMaze();
 }
Esempio n. 5
0
        // <summary>
        /// ScoreBoard creation method
        /// </summary>
        /// <remarks>
        /// Will return instance of IScoreBoard
        /// </remarks>

        public static IScoreBoard CreateScoreBoard()
        {
            if (scoreBoard == null)
            {
                scoreBoard = new ScoreBoard();
            }

            return(scoreBoard);
        }
Esempio n. 6
0
 /// <summary>
 /// Parse the current command
 /// </summary>
 /// <param name="renderer">
 /// Must be an instance of IRenderer
 /// </param>
 /// <param name="score">
 /// Must be an instance of IScoreBoard
 /// </param>
 public void ParseCommand(IRenderer renderer, IScoreBoard score)
 {
     if (this.command != null)
     {
         if (this.command is PrintCommand)
         {
             (this.command as PrintCommand).Parse(renderer, score);
         }
     }
 }
        /// <summary>
        /// Renders the scoreboard to the console.
        /// </summary>
        /// <param name="scoreBoard">Scoreboard instance for the particular game.</param>
        public void RenderScoreBoard(IScoreBoard scoreBoard)
        {
            if (scoreBoard == null)
            {
                throw new ArgumentNullException("Scoreboard is null!");
            }

            string generatedList = scoreBoard.Generate();

            Console.WriteLine(generatedList);
        }
        /// <summary>
        /// Create a new MinesweeperEngine with the provided winCondition, IGameBoard, IScoreBoard and IUserInterface.
        /// </summary>
        /// <param name="winCondition"> The number of successful turns required to win the game. </param>
        /// <param name="gameBoard"> Required to check against. </param>
        /// <param name="scoreBoard"> Required to keep track of score history. </param>
        /// <param name="userInterface"> Required to display the game to the user. </param>
        /// <exception cref="ArgumentNullException"></exception>
        public MinesweeperEngine(int winCondition, IGameBoard gameBoard, IScoreBoard scoreBoard, IUserInterface userInterface)
        {
            this.CheckIfConstructorObjectIsNull(gameBoard);
            this.CheckIfConstructorObjectIsNull(scoreBoard);
            this.CheckIfConstructorObjectIsNull(userInterface);

            this.gameBoard     = gameBoard;
            this.scoreBoard    = scoreBoard;
            this.userInterface = userInterface;
            this.winConditionSuccsessfulTurns = winCondition;
        }
Esempio n. 9
0
 public GameScene(ISnake snake, IDrawManager drawManager, IFoodFactory foodFactory, IBorder border, IScoreBoard scoreBoard, IScene pauseScene, IScene gameOverScene)
 {
     this.snake         = snake;
     this.drawManager   = drawManager;
     this.foodFactory   = foodFactory;
     this.border        = border;
     this.scoreBoard    = scoreBoard;
     this.pauseScene    = pauseScene;
     this.gameOverScene = gameOverScene;
     this.spawnedFood   = null;
     this.GameSpeed     = GameMinSpeed;
 }
Esempio n. 10
0
        public void IsInTieBreakShouldReturnFalseWhenOneOfPlayersScoreIsLessThan40()
        {
            var player1 = playerBuilder.Build();

            player1.Score = 3;
            var player2 = playerBuilder.Build();

            player2.Score = 2;
            scoreBoard    = new ScoreBoard(player1, player2);
            referee       = new Referee(scoreBoard);

            Assert.That(referee.IsInTieBreak(), Is.Not.True);
        }
Esempio n. 11
0
        public GameEngine()
        {
            this.randomGenerator = new Random();
            this.words           = new string[] { "computer", "programmer", "software", "debugger", "compiler",
                                                  "developer", "algorithm", "array", "method", "variable" };
            this.scoreBoard = new ScoreBoard();
            string word = this.GetRandomWord();

            this.game = new Hangman(word);
            Console.WriteLine("Commands: top, help, restart, exit.");
            // commands should be global constants
            Console.WriteLine("Welcome to “Hangman” game. Please try to guess my secret word.");
            this.command = null;
        }
Esempio n. 12
0
 public GameController(
     IPlayerBuilder playerBuilder,
     IPlayersDataReader playersDataReader,
     IEvenOrOdd evenOrOdd,
     IScoreBoard scoreBoard,
     IReferee referee)
 {
     _playerBuilder           = playerBuilder;
     _playersDataReader       = playersDataReader;
     _evenOrOdd               = evenOrOdd;
     _scoreBoard              = scoreBoard;
     _referee                 = referee;
     scoreBoard.PlayerScored += referee.OnPlayerScored;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="Engine"/> class.
        /// </summary>
        /// <param name="mineField">Must contain a class that inherits IField interface</param>
        /// <param name="playingField">Must contain a class that inherits IField interface</param>
        /// <param name="renderer">Must contain a class that inherits IRenderer interface</param>
        /// <param name="inputReader">Must contain a class that inherits IReadInput interface</param>
        /// <param name="scoreboard">Must contain a class that inherits IScoreBoard interface</param>
        public Engine(IField mineField, IField playingField, IRenderer renderer, IReadInput inputReader, IScoreBoard scoreboard)
        {
            this.playingField = playingField;
            this.mineField = mineField;

            this.renderer = renderer;
            this.inputReader = inputReader;
            this.scoreBoard = scoreboard;

            this.playing = true;
            this.currentUserName = "******";
            this.currentUserScore = 0;
            this.openedCells = 0;
        }
Esempio n. 14
0
        public void OnPlayerScoredShouldSetGameEndedToTrueWhenPlayer1Wins()
        {
            var player1 = playerBuilder.Build();

            player1.Score = 4;
            var player2 = playerBuilder.Build();

            player2.Score = 3;
            scoreBoard    = new ScoreBoard(player1, player2);
            referee       = new Referee(scoreBoard);

            scoreBoard.PlayerScored += referee.OnPlayerScored;
            scoreBoard.SetPlayerOneScore();

            Assert.That(referee.GameEnded);
        }
Esempio n. 15
0
        public StandardTwoPlayerEngine(ContainerConsole container)
        {
            movementStrategy  = new NormalMovementStrategy();
            renderer          = new ConsoleRenderer(container);
            selectedPositions = new List <Position>();
            scoreBoard        = new ScoreBoard(container);
            board             = new Board();

            // main event that drives the game
            renderer.Console.MouseMove += MouseClickOnBoard;

            // keyboard
            keyboardHandler     = new KeyboardHandler(this);
            container.IsFocused = true;
            container.Components.Add(keyboardHandler);
        }
Esempio n. 16
0
        public void IsInTieBreakShouldReturnTrueWhenPlayerTwoTies()
        {
            var player1 = playerBuilder.Build();

            player1.Score = 3;
            var player2 = playerBuilder.Build();

            player2.Score = 2;
            scoreBoard    = new ScoreBoard(player1, player2);
            referee       = new Referee(scoreBoard);

            scoreBoard.PlayerScored += referee.OnPlayerScored;
            scoreBoard.SetPlayerTwoScore();

            Assert.That(referee.IsInTieBreak(), Is.True);
        }
Esempio n. 17
0
        public void IsDeuceShouldReturnFalseWhenPlayesTieWhileNotInTieBreak()
        {
            var player1 = playerBuilder.Build();

            player1.Score = 1;
            var player2 = playerBuilder.Build();

            player2.Score = 2;
            scoreBoard    = new ScoreBoard(player1, player2);
            referee       = new Referee(scoreBoard);

            scoreBoard.PlayerScored += referee.OnPlayerScored;
            scoreBoard.SetPlayerOneScore();

            Assert.That(referee.IsDeuce(), Is.False);
        }
Esempio n. 18
0
        public void OnPlayerScoredShouldChangeScoreListOfScoreBoardAndZeroPlayrsScore()
        {
            var player1 = playerBuilder.Build();

            player1.Score = 3;
            var player2 = playerBuilder.Build();

            player2.Score = 2;
            scoreBoard    = new ScoreBoard(player1, player2);
            referee       = new Referee(scoreBoard);

            scoreBoard.PlayerScored += referee.OnPlayerScored;
            scoreBoard.SetPlayerTwoScore();

            Assert.That(scoreBoard.Player1.Score, Is.EqualTo(0));
            Assert.That(scoreBoard.Player2.Score, Is.EqualTo(0));
        }
Esempio n. 19
0
        public void OnPlayerScoredShouldChangeTheScoreListWhenStartingTieBreakByPlayer2()
        {
            var player1 = playerBuilder.Build();

            player1.Score = 3;
            var player2 = playerBuilder.Build();

            player2.Score = 2;
            scoreBoard    = new ScoreBoard(player1, player2);
            referee       = new Referee(scoreBoard);

            scoreBoard.PlayerScored += referee.OnPlayerScored;
            scoreBoard.SetPlayerTwoScore();

            Assert.That(scoreBoard.ScoreList[1], Is.EqualTo(1));
            Assert.That(scoreBoard.ScoreList.Count, Is.EqualTo(100));
        }
Esempio n. 20
0
        public void IsAdvantageShoulfReturnTrueWhenPlayer1UntiesDuringTieBreak()
        {
            var player1 = playerBuilder.Build();

            player1.Score = 2;
            var player2 = playerBuilder.Build();

            player2.Score = 3;
            scoreBoard    = new ScoreBoard(player1, player2);
            referee       = new Referee(scoreBoard);

            scoreBoard.PlayerScored += referee.OnPlayerScored;
            scoreBoard.SetPlayerOneScore();
            scoreBoard.SetPlayerOneScore();

            Assert.That(referee.IsAdvantage(), Is.True);
        }
        public void Setup()
        {
            IRandomNumber  randomNumber  = new RandomNumber();
            IPlayerBuilder playerBuilder = new PlayerBuilder(randomNumber);

            _scoreBoard     = new ScoreBoard(new Player(randomNumber), new Player(randomNumber));
            _gameController = new GameController(
                playerBuilder,
                playerDataReaderMock.Object,
                evenOrOddMock.Object,
                _scoreBoard,
                refereeMock.Object);

            var player1DataMock = new string[] { "Tonho", "Experienced", "Even", "25" };
            var player2DataMock = new string[] { "Zé", "Experienced", "Odd", "21" };

            playerDataReaderMock.Setup(pdr => pdr.GetPlayerOneData("fakeFilePath")).Returns(player1DataMock);
            playerDataReaderMock.Setup(pdr => pdr.GetPlayerTwoData("fakeFilePath")).Returns(player2DataMock);
        }
Esempio n. 22
0
        /// <summary>
        /// Prints the scoreboard on the console
        /// </summary>
        /// <param name="scoreBoardString">Given scoreboard to be printed</param>
        public static void ShowScoreboard(IScoreBoard <IPlayer> scoreBoard)
        {
            if (scoreBoard.Count != 0)
            {
                StringBuilder sb = new StringBuilder("Scoreboard:");
                sb.Append(Environment.NewLine);
                int i = 1;
                foreach (IPlayer player in scoreBoard)
                {
                    sb.AppendFormat("{0}. {1} --> {2} guess" + ((player.Attempts == 1) ? "" : "es"), i++, player.Name, player.Attempts);
                    sb.Append(Environment.NewLine);
                }

                Console.WriteLine(sb.ToString().Trim());
            }
            else
            {
                Console.WriteLine("Top scoreboard is empty.");
            }
        }
Esempio n. 23
0
        public void PlayMines()
        {
            this.scoreBoard = new ScoreBoard(new TextFileDataManager());
            this.printer = Printer.GetInstance(this.scoreBoard);
            this.validator = new Validator();
            var cel = new Cell();
            this.field = new Field(5, 10, 15);
            this.commandFactory = new CommandFactoryWithLazyLoading(this.printer, this.field, this.validator);

            this.field.Initialize();

            bool isBoomed = false;
            bool playerWon = false;

            this.printer.PrintMessage(Messages.StartMessage);

            while (true)
            {
                if (isBoomed || playerWon)
                {
                    this.field.Initialize();
                    isBoomed = false;
                }

                this.printer.PrintField(this.field.MineField, isBoomed);

                this.printer.PrintMessage(Messages.EnterRowColCommand);
                string line = Console.ReadLine();
                line = line.Trim();

                if (this.validator.IsMoveEntered(line))
                {
                    string[] inputParams = line.Split();
                    int row = int.Parse(inputParams[0]);
                    int col = int.Parse(inputParams[1]);

                    if (this.field.IsMoveInBounds(row, col) && !this.field.IsCellClickled(row, col))
                    {
                        isBoomed = this.field.MineField[row, col].IsBomb;
                        playerWon = this.IsPlayerGrandWinner(this.field.MineField, this.field.NumberOfMines);

                        this.EndGame(isBoomed, playerWon);

                        this.field.RevialCell(row, col);
                    }
                    else
                    {
                        this.printer.PrintMessage(Messages.AlreadyOpenedOrOutOfRange);
                    }
                }
                else
                {
                    ICommand command = this.commandFactory.CreateCommand(line);

                    if (command != null)
                    {
                        command.Execute();
                    }
                }
            }
        }
Esempio n. 24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ScoreBoardService"/> class.
 /// </summary>
 /// <param name="scoreBoard">Instance of IScoreBoard</param>
 public ScoreBoardService(IScoreBoard scoreBoard)
 {
     this.currentScoreBoard = scoreBoard;
 }
Esempio n. 25
0
 public ScoreBoard(IScoreBoard scoreBoard)
 {
     this.scoreBoard = scoreBoard;
 }
Esempio n. 26
0
        static void RunnerAI()
        {
            var csv = new StringBuilder();

            PlayerHuman human  = new PlayerHuman();
            PlayerHuman human2 = new PlayerHuman();

            NaiveScore    sb = new NaiveScore();
            OtherScore    os = new OtherScore();
            BalancedScore bs = new BalancedScore();

            IScoreBoard sf = bs;

            AIPlayer ai1 = new MiniMaxPlayer(1, 5, sf, true);
            AIPlayer ai2 = new MiniMaxPlayer(2, 5, sf, true);

            AIPlayer ai3 = new AlphaBetaPlayer(1, 9, sf, true);
            AIPlayer ai4 = new AlphaBetaPlayer(2, 9, sf, true);

            var p1 = ai3;
            var p2 = ai4;

            Game gra      = new Game(p1, p2);
            int  winningP = gra.Play();

            var p1avg = p1.GetAvgTime();
            var p1all = p1.GetAllTimes();

            Console.WriteLine(p1avg);

            var p2avg = p2.GetAvgTime();
            var p2all = p2.GetAllTimes();

            Console.WriteLine(p2avg);

            var firstL  = "";
            var secondL = "";

            foreach (TimeSpan time in p1all)
            {
                //Console.WriteLine(string.Format("{0:0}:{1:00}:{2:000},", time.Minutes, time.Seconds, time.Milliseconds));
                //firstL += string.Format("{0:0}:{1:00}:{2:000};", time.Minutes, time.Seconds, time.Milliseconds);

                firstL += string.Format("{0};", time.Milliseconds);
            }

            firstL += string.Format(";{0};", p1avg.Ticks);

            foreach (TimeSpan time in p2all)
            {
                //secondL += string.Format("{0:0}:{1:00}:{2:000};", time.Minutes, time.Seconds, time.Milliseconds);

                secondL += string.Format("{0};", time.Milliseconds);
            }

            secondL += string.Format(";{0};", p2avg.Ticks);

            firstL  += ";";
            secondL += ";";

            if (winningP == 1)
            {
                csv.AppendLine(firstL);
            }
            else if (winningP == 2)
            {
                csv.AppendLine(secondL);
            }
            else
            {
                csv.AppendLine(firstL);
                csv.AppendLine(secondL);
            }

            File.WriteAllText("results.csv", csv.ToString());
        }
 public void Init()
 {
     this.scoreBoard = new ScoreBoard();
     this.scoreBoardService = new ScoreBoardService(this.scoreBoard);
 }
 public void CleanUp()
 {
     this.scoreBoard = null;
     this.scoreBoardService = null;
 }
Esempio n. 29
0
        static void RunnerLogger()
        {
            var csv = new StringBuilder();

            string start = "description;winner;depth;heur;avgInSec;avgInmili;moves;time";

            csv.AppendLine(start);

            NaiveScore    sb = new NaiveScore();
            OtherScore    os = new OtherScore();
            BalancedScore bs = new BalancedScore();

            Console.WriteLine("Start");

            List <IScoreBoard> heurs = new List <IScoreBoard>()
            {
                sb, os, bs
            };

            List <IScoreBoard> heurs2 = new List <IScoreBoard>()
            {
                sb, os, bs
            };

            foreach (var heur1 in heurs)
            {
                IScoreBoard h1 = heur1;

                foreach (var heur2 in heurs2)
                {
                    IScoreBoard h2 = heur2;

                    Console.WriteLine("H1: {0} H2: {1}", h1.GetName(), h2.GetName());

                    for (int i = 2; i < 7; i++)
                    {
                        for (int j = 2; j < 9; j++)
                        {
                            Console.WriteLine("P1:{0} - {1} P2: {2} - {3}", h1.GetName(), i, h2.GetName(), j);

                            AIPlayer ai1 = new MiniMaxPlayer(1, i, h1, true);
                            AIPlayer ai2 = new AlphaBetaPlayer(2, j, h2, true);

                            Game gra      = new Game(ai1, ai2);
                            int  winningP = gra.Play();

                            var line = "";

                            line += string.Format("P1:{0} - {1} P2: {2} - {3};", h1.GetName(), i, h2.GetName(), j);

                            if (winningP == 1)
                            {
                                line += string.Format("{0};{1};{2};", 1, i, h1.GetName());

                                var avg   = ai1.GetAvgTime();
                                var times = ai1.GetAllTimes();

                                //foreach (TimeSpan time in times)
                                //{
                                //    line += string.Format("{0};", time.Milliseconds);
                                //}

                                line += string.Format("{0};", avg.TotalSeconds);
                                line += string.Format("{0};", avg.TotalMilliseconds);
                                line += string.Format("{0};", times.Count);
                                line += string.Format("{0:00}:{1:000};", avg.Seconds, avg.Milliseconds);

                                csv.AppendLine(line);
                            }
                            else if (winningP == 2)
                            {
                                line += string.Format("{0};{1};{2};", 2, j, h2.GetName());

                                var avg   = ai2.GetAvgTime();
                                var times = ai2.GetAllTimes();

                                //foreach (TimeSpan time in times)
                                //{
                                //    line += string.Format("{0};", time.Milliseconds);
                                //}

                                line += string.Format("{0};", avg.TotalSeconds);
                                line += string.Format("{0};", avg.TotalMilliseconds);
                                line += string.Format("{0};", times.Count);
                                line += string.Format("{0:00}:{1:000};", avg.Seconds, avg.Milliseconds);

                                csv.AppendLine(line);
                            }
                            else
                            {
                                line += string.Format("{0};{1};{2};", 0, i, h1.GetName());

                                var avg   = ai1.GetAvgTime();
                                var times = ai1.GetAllTimes();

                                //foreach (TimeSpan time in times)
                                //{
                                //    line += string.Format("{0};", time.Milliseconds);
                                //}
                                line += string.Format("{0};", avg.TotalSeconds);
                                line += string.Format("{0};", avg.TotalMilliseconds);
                                line += string.Format("{0};", times.Count);
                                line += string.Format("{0:00}:{1:000};", avg.Seconds, avg.Milliseconds);

                                csv.AppendLine(line);
                            }
                        }
                    }
                }
            }


            Console.WriteLine("ukończono");

            File.WriteAllText("results.csv", csv.ToString());
        }
Esempio n. 30
0
 public Referee(IScoreBoard scoreBoard)
 {
     _scoreBoard = scoreBoard;
 }
 public BullsAndCows(IRandomNumberProvider randomNumberProvider, IScoreBoard scoreBoard)
 {
     this.randomGenerator = randomNumberProvider;
     this.scoreBoard = scoreBoard;
     this.SetNewDigits();
 }
        /// <summary>
        /// Prints the scoreboard on the console
        /// </summary>
        /// <param name="scoreBoardString">Given scoreboard to be printed</param>
        public static void ShowScoreboard(IScoreBoard<IPlayer> scoreBoard)
        {
            if (scoreBoard.Count != 0)
            {
                StringBuilder sb = new StringBuilder("Scoreboard:");
                sb.Append(Environment.NewLine);
                int i = 1;
                foreach (IPlayer player in scoreBoard)
                {
                    sb.AppendFormat("{0}. {1} --> {2} guess" + ((player.Attempts == 1) ? "" : "es"), i++, player.Name, player.Attempts);
                    sb.Append(Environment.NewLine);
                }

                Console.WriteLine(sb.ToString().Trim());
            }
            else
            {
                Console.WriteLine("Top scoreboard is empty.");
            }
        }
Esempio n. 33
0
        public ScoreBoardTest()
        {
            this.gameRepositoryStub = new GameRepositoryStub();

            this.scoreBoard = new ScoreBoard(gameRepositoryStub);
        }