Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Board gameBoard = new Board(3, 3);

            Console.WriteLine("........Game Begins...........");
            gameBoard.display();

            ResultAnalyzer analyser = new ResultAnalyzer(gameBoard);
            Player         player1  = new Player("Dharmesh", MarkFactory.Cross);
            Player         player2  = new Player("Chandan", MarkFactory.Nought);
            Game           game     = new Game(analyser, gameBoard, player1, player2);


            while (game.GameStatus == GameStatus.ONGOING)
            {
                Console.WriteLine("\nHey " + game.GetPlayerTurn().Name + " its your turn");
                Console.WriteLine("Enter your " + game.GetPlayerTurn().Mark.Mark + " position:");

                int position = Convert.ToInt32(Console.ReadLine());

                game.play(position);

                if (game.GameStatus == GameStatus.WON)
                {
                    Console.WriteLine(game.GetCurrentPlayer().Name + " Wons");
                }
                else if (game.GameStatus == GameStatus.DRAW)
                {
                    Console.WriteLine("........Game is draw.........");
                }
            }
        }
Exemplo n.º 2
0
 private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     this.SwitchView(true);
     this.resultPerStudentsGroup = ResultAnalyzer.GetResultByStudentsGroups(this.configuration, this.ga);
     this.BindResultControls();
     this.toolStripStatusLabel1.Text    = "Complete";
     this.toolStripProgressBar1.Visible = false;
     MessageBox.Show("Done");
 }
 void Intialize()
 {
     board      = new Board();
     result     = new ResultAnalyzer(board);
     players    = new Player[2];
     players[0] = new Player("akash", Mark.O);
     players[1] = new Player("dhruv", Mark.X);
     game       = new Game(players, board, result);
 }
Exemplo n.º 4
0
 void Intialize()
 {
     board      = new Board();
     result     = new ResultAnalyzer(board);
     players    = new Player[2];
     players[0] = new Player("priyank", Mark.O);
     players[1] = new Player("meet", Mark.X);
     game       = new Game(players, board, result);
 }
        public void TestForResultAnalyzerWorkingOrNot()
        {
            Board board = new Board();

            board.SetMark(3, Mark.O);
            ResultAnalyzer resultanalyzer = new ResultAnalyzer(board);

            Assert.AreEqual(Result.PROGRESS, resultanalyzer.Analyze(Mark.O));
        }
Exemplo n.º 6
0
        public void Test_PlayForOutOfCellException()
        {
            Player         player1        = new Player("SK", Mark.O);
            Player         player2        = new Player("PK", Mark.X);
            ResultAnalyzer resultAnalyzer = new ResultAnalyzer(new Board(3));
            Game           game           = new Game(resultAnalyzer, player1, player2);

            game.Play(10);
        }
Exemplo n.º 7
0
        public void GotDifferentMarkInHorizontal_Result_is_Going_on()
        {
            Board          board  = new Board();
            ResultAnalyzer result = new ResultAnalyzer(board);

            board.SetLocation(Mark.X, 0);
            board.SetLocation(Mark.O, 1);
            board.SetLocation(Mark.X, 2);
            Assert.AreEqual(Result.ONGOING, result.AnalyzeResult());
        }
        public void Wincross2testMethod()
        {
            Board          board    = new Board();
            ResultAnalyzer analyzer = new ResultAnalyzer(board);

            board.SetPosition(2, Mark.O);
            board.SetPosition(4, Mark.O);
            board.SetPosition(6, Mark.O);
            Assert.AreEqual(Result.WIN, analyzer.resultGenerator());
        }
Exemplo n.º 9
0
        public void Test_PlayForCellAlreadyOccupiedException()
        {
            Player         player1        = new Player("SK", Mark.O);
            Player         player2        = new Player("PK", Mark.X);
            ResultAnalyzer resultAnalyzer = new ResultAnalyzer(new Board(3));
            Game           game           = new Game(resultAnalyzer, player1, player2);

            game.Play(2);
            game.Play(2);
        }
Exemplo n.º 10
0
        public void GotMark_Empty_InHorizontal_Result_Is_In_Progress()
        {
            Board          board  = new Board();
            ResultAnalyzer result = new ResultAnalyzer(board);

            board.SetLocation(Mark.O, 6);
            board.SetLocation(Mark.EMPTY, 7);
            board.SetLocation(Mark.O, 8);
            Assert.AreEqual(Result.ONGOING, result.AnalyzeResult());
        }
Exemplo n.º 11
0
        public void Initialize()
        {
            board = new Board();
            ResultAnalyzer analyzer = new ResultAnalyzer(board);

            players    = new Player[2];
            players[0] = new Player("Akash", Mark.X);
            players[1] = new Player("Dhruv", Mark.O);
            game       = new Game(players, board, analyzer);
        }
Exemplo n.º 12
0
        public void GotSameMarkIn_Diagonal_Result_IsWin()
        {
            Board          board  = new Board();
            ResultAnalyzer result = new ResultAnalyzer(board);

            board.SetLocation(Mark.O, 2);
            board.SetLocation(Mark.O, 4);
            board.SetLocation(Mark.O, 6);
            Assert.AreEqual(Result.WIN, result.AnalyzeResult());
        }
Exemplo n.º 13
0
        public void Test_GetResultMethod_PassingFirstDiagonal()
        {
            Board board = new Board();

            board.SetPosition(0, Mark.X);
            board.SetPosition(4, Mark.X);
            board.SetPosition(8, Mark.X);
            ResultAnalyzer analyzer = new ResultAnalyzer(board);

            Assert.AreEqual(Results.WIN, analyzer.GetResult());
        }
Exemplo n.º 14
0
        public void Test_GetResultMethod_PassingThirdColumn()
        {
            Board board = new Board();

            board.SetPosition(2, Mark.X);
            board.SetPosition(5, Mark.X);
            board.SetPosition(8, Mark.X);
            ResultAnalyzer analyzer = new ResultAnalyzer(board);

            Assert.AreEqual(Results.WIN, analyzer.GetResult());
        }
Exemplo n.º 15
0
        public void Test_GetResultMethod_PassingSecondRow()
        {
            Board board = new Board();

            board.SetPosition(3, Mark.X);
            board.SetPosition(4, Mark.X);
            board.SetPosition(5, Mark.X);
            ResultAnalyzer analyzer = new ResultAnalyzer(board);

            Assert.AreEqual(Results.WIN, analyzer.GetResult());
        }
        public void TestForHorizontalWinCondition()
        {
            Board          board          = new Board();
            ResultAnalyzer resultanalyzer = new ResultAnalyzer(board);

            board.SetMark(1, Mark.O);
            board.SetMark(2, Mark.O);
            board.SetMark(0, Mark.O);

            Assert.AreEqual(Result.WIN, resultanalyzer.Analyze(Mark.O));
        }
Exemplo n.º 17
0
        protected PrintTestRunner TestRunnerFactory(string caseName, IProfile settings)
        {
            var engine          = new EngineFFF();
            var resultGenerator = new ResultGenerator(engine, new ConsoleLogger())
            {
                Settings = settings
            };
            var resultAnalyzer = new ResultAnalyzer <FeatureInfo>(new FeatureInfoFactoryFFF());

            return(new PrintTestRunner(caseName, resultGenerator, resultAnalyzer));
        }
Exemplo n.º 18
0
    public static void UpdateGame(ThrowableScriptable playerChoice, ThrowableScriptable opponentHand, Action <Dictionary <string, object>, Result> onLoaded)  // capitalized
    {
        Result drawResult = ResultAnalyzer.GetResultState(playerChoice, opponentHand);
        Dictionary <string, object> mockGameUpdate = new Dictionary <string, object>();

        mockGameUpdate[HashConstants.GUD_PLAYER_RESULT]   = playerChoice;
        mockGameUpdate[HashConstants.GUD_OPPONENT_RESULT] = opponentHand;
        mockGameUpdate[HashConstants.GUD_MONEY_CHANGE]    = GetCoinsAmount(drawResult);

        onLoaded?.Invoke(mockGameUpdate, drawResult);        // ? to avoid null refs
    }
        public void GameGoingOn_IfThereisNowinnerOrBoardIsNotFull()
        {

            Board board1 = new Board();
            ResultAnalyzer analyzer = new ResultAnalyzer(board1);
            board1.SetLocation(Mark.X, 0);
            board1.SetLocation(Mark.O, 1);
            board1.SetLocation(Mark.X, 2);
            board1.SetLocation(Mark.O, 7);
            board1.SetLocation(Mark.X, 5);

            Assert.AreEqual(Result.ONGOING, analyzer.AnalyzeResult());
        }
Exemplo n.º 20
0
    public void Load()
    {
        UseableItem opponentHand = (UseableItem)Enum.GetValues(typeof(UseableItem)).GetValue(UnityEngine.Random.Range(1, 4));

        Hashtable mockGameUpdate = new Hashtable();

        mockGameUpdate[GameConstants.resultPlayer]   = _choice;
        mockGameUpdate[GameConstants.resultOpponent] = opponentHand;
        //mockGameUpdate[GameConstants.coinsAmountChange] = GetCoinsAmount(_choice, opponentHand);
        mockGameUpdate[GameConstants.gameResult] = ResultAnalyzer.GetResultState(_choice, opponentHand);

        OnLoaded(mockGameUpdate);
    }
        public void TestingWinCase_Verically()
        {
              
            Board board1 = new Board();
            ResultAnalyzer analyzer = new ResultAnalyzer(board1);
            board1.SetLocation(Mark.X, 0);
            board1.SetLocation(Mark.O, 1);
            board1.SetLocation(Mark.X, 3);
            board1.SetLocation(Mark.O, 4);
            board1.SetLocation(Mark.O, 5);
            board1.SetLocation(Mark.X, 6);

            Assert.AreEqual(Result.WIN, analyzer.AnalyzeResult());
        }
Exemplo n.º 22
0
        public void Test_CheckColumnResult()
        {
            bool           expected       = true;
            Player         player         = new Player("Sumit", Mark.X);
            Board          board          = new Board(3);
            ResultAnalyzer resultAnalyzer = new ResultAnalyzer(board);

            board.SetMarkInPosition(player, 1);
            board.SetMarkInPosition(player, 4);
            board.SetMarkInPosition(player, 7);

            bool actual = resultAnalyzer.CheckColumn(Mark.X, 7);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 23
0
        public void Test_ResultWithWin()
        {
            Result         expected       = Result.Win;
            Player         player         = new Player("Sumit", Mark.O);
            Board          board          = new Board(3);
            ResultAnalyzer resultAnalyzer = new ResultAnalyzer(board);

            board.SetMarkInPosition(player, 2);
            board.SetMarkInPosition(player, 4);
            board.SetMarkInPosition(player, 6);

            Result actual = resultAnalyzer.GameResult(Mark.O, 6);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 24
0
        public void Test_CheckRightToLeftDiagonalResult()
        {
            bool           expected       = true;
            Player         player         = new Player("Sumit", Mark.O);
            Board          board          = new Board(3);
            ResultAnalyzer resultAnalyzer = new ResultAnalyzer(board);

            board.SetMarkInPosition(player, 2);
            board.SetMarkInPosition(player, 4);
            board.SetMarkInPosition(player, 6);

            bool actual = resultAnalyzer.CheckRightToLeftDiagonal(Mark.O, 6);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 25
0
        public void If_Board_is_Full_With_Win()
        {
            Board          board  = new Board();
            ResultAnalyzer result = new ResultAnalyzer(board);

            board.SetLocation(Mark.X, 0);
            board.SetLocation(Mark.X, 1);
            board.SetLocation(Mark.X, 2);
            board.SetLocation(Mark.O, 3);
            board.SetLocation(Mark.X, 4);
            board.SetLocation(Mark.O, 5);
            board.SetLocation(Mark.O, 6);
            board.SetLocation(Mark.X, 7);
            board.SetLocation(Mark.O, 8);
            Assert.AreEqual(Result.WIN, result.AnalyzeResult());
        }
Exemplo n.º 26
0
        public void GotSameMarkInVertical_Result_IsWin()
        {
            Board          board  = new Board();
            ResultAnalyzer result = new ResultAnalyzer(board);

            board.SetLocation(Mark.X, 2);
            board.SetLocation(Mark.O, 5);
            board.SetLocation(Mark.X, 8);
            board.SetLocation(Mark.O, 1);
            board.SetLocation(Mark.O, 4);
            board.SetLocation(Mark.X, 3);
            board.SetLocation(Mark.O, 7);


            Assert.AreEqual(Result.WIN, result.AnalyzeResult());
        }
Exemplo n.º 27
0
        public void TestOnGoingResult()
        {
            Board          board          = new Board();
            ResultAnalyzer resultAnalyzer = new ResultAnalyzer(board);

            MarkType cross  = MarkFactory.CROSS;
            MarkType nought = MarkFactory.NOUGHT;

            board.UpdateBoard(nought, 1);
            board.UpdateBoard(cross, 8);
            board.UpdateBoard(cross, 9);

            resultAnalyzer.AnalyzeBoard();

            Assert.AreEqual(Result.ONGOING, resultAnalyzer.Result);
        }
Exemplo n.º 28
0
        public void TestGame()
        {
            Board          board    = new Board(3, 3);
            ResultAnalyzer analyzer = new ResultAnalyzer(board);
            Player         player1  = new Player("Dharmesh", MarkFactory.Cross);
            Player         player2  = new Player("Chandan", MarkFactory.Nought);
            Game           game     = new Game(analyzer, board, player1, player2);

            game.play(1);
            game.play(4);
            game.play(2);
            game.play(5);
            game.play(3);
            game.play(8);
            Assert.AreEqual(GameStatus.WON, game.GameStatus);
        }
        public void ExpectFailure <ExceptionType>(PrintProfileFFF settings) where ExceptionType : Exception
        {
            // Arrange
            var resultGenerator = TestRunnerFactoryFFF.CreateResultGenerator(settings);
            var resultAnalyzer  = new ResultAnalyzer <FeatureInfo>(new FeatureInfoFactoryFFF(), new ConsoleLogger());
            var print           = new PrintTestRunner(CaseName, resultGenerator, resultAnalyzer);

            // Act
            print.GenerateFile();

            // Assert
            Assert.ThrowsException <ExceptionType>(() =>
            {
                print.CompareResults();
            });
        }
Exemplo n.º 30
0
        public void TestDiagonalCheckWinMethod()
        {
            Board          board          = new Board();
            ResultAnalyzer resultAnalyzer = new ResultAnalyzer(board);

            MarkType cross  = MarkFactory.CROSS;
            MarkType nought = MarkFactory.NOUGHT;

            board.UpdateBoard(cross, 3);
            board.UpdateBoard(cross, 5);
            board.UpdateBoard(cross, 7);

            resultAnalyzer.AnalyzeBoard();

            Assert.AreEqual(Result.WIN, resultAnalyzer.Result);
        }