Exemplo n.º 1
0
        public void TestGameBoard_FigurePositionOutOfTheBoard()
        {
            List<Figure> figures = new List<Figure>();
            figures.Add(new Pawn(new Position(1, 1), 'A')); // need to add some figures because we don`t want
            figures.Add(new King(new Position(2, 2)));      // the exception to happen because of no pawns or king
            figures.Add(new Pawn(new Position(1000,1000),'B'));

            GameBoard gameBoard = new GameBoard(figures);
        }
Exemplo n.º 2
0
 public void TestGameBoard_Indexer()
 {
     List<Figure> figures = new List<Figure>();
     figures.Add(new Pawn(new Position(0, 0), 'A'));
     figures.Add(new King(new Position(1, 1))); // if there is no king added there is another exception
     GameBoard gameBoard = new GameBoard(figures);
     gameBoard[1, 1] = '3';
     Assert.AreEqual('3', gameBoard[1, 1], "GameBoard indexer is not working correctly");
     Assert.AreEqual('A', gameBoard[0, 0+4], "GameBoard indexer is not working correctly"); // +4 because there are some symbols outside the border
 }
Exemplo n.º 3
0
        public void TestGameBoard_FiguresWithTheSameName()
        {
            List<Figure> figures = new List<Figure>();
            figures.Add(new King(new Position(1, 1))); // if there is no king added there is another exception
            figures.Add(new Pawn(new Position(0, 0), 'A')); //2,4
            figures.Add(new Pawn(new Position(0, 2), 'B')); //2,8
            figures.Add(new Pawn(new Position(0, 4), 'C')); //2,12
            figures.Add(new Pawn(new Position(0, 6), 'B')); //2,16

            GameBoard gameBoard = new GameBoard(figures);
        }
Exemplo n.º 4
0
 public void TestInputCommandNameKingIsEligible_DL()
 {
     List<Figure> figures = new List<Figure>();
     figures.Add(new Pawn(new Position(0, 0), 'A'));
     figures.Add(new Pawn(new Position(0, 2), 'B'));
     figures.Add(new Pawn(new Position(0, 4), 'C'));
     figures.Add(new Pawn(new Position(0, 6), 'D'));
     figures.Add(new King(new Position(3, 7)));
     GameBoard gameBoard = new GameBoard(figures);
     Engine currentEngine = new Engine(gameBoard, figures);
     string command = "KUR";
     Assert.IsTrue(currentEngine.ValidateCommand(command), "KDL is valid command");
 }
Exemplo n.º 5
0
        public void TestGameBoard_IfKingStartsAtTheSameRowWithThePawns()
        {
            List<Figure> figures = new List<Figure>();
            // adding pawns
            figures.Add(new Pawn(new Position(3, 0), 'A'));
            figures.Add(new Pawn(new Position(4, 2), 'B'));
            figures.Add(new Pawn(new Position(5, 4), 'C'));
            figures.Add(new Pawn(new Position(5, 6), 'D'));
            // adding king
            figures.Add(new King(new Position(3, 8)));

            GameBoard gameBoard = new GameBoard(figures);
        }
Exemplo n.º 6
0
 public void TestInputCommandForPawnIsNotEligible()
 {
     List<Figure> figures = new List<Figure>();
     figures.Add(new Pawn(new Position(0, 0), 'A'));
     figures.Add(new Pawn(new Position(0, 2), 'B'));
     figures.Add(new Pawn(new Position(0, 4), 'C'));
     figures.Add(new Pawn(new Position(0, 6), 'D'));
     figures.Add(new King(new Position(3, 7)));
     GameBoard gameBoard = new GameBoard(figures);
     Engine currentEngine = new Engine(gameBoard, figures);
     currentEngine.MoveCounter = 3;
     string currentComand = "ADRt";
     Assert.IsFalse(currentEngine.ValidateCommand(currentComand), "Command is not valid named");
 }
Exemplo n.º 7
0
 public Engine(GameBoard gameBoard, List<Figure> figures)
 {
     this.gameBoard = gameBoard;
     this.figures = figures;
     this.charRepresentationsPawns = new List<char>();
     this.GameIsInProgress = true;
     foreach (var figure in this.figures)
     {
         if (figure is Pawn)
         {
             charRepresentationsPawns.Add(figure.SymbolRepresentation);
         }
     }
 }
Exemplo n.º 8
0
        public void TestInputCommandIsNull_ThrowsException()
        {
            string num = null;
            Console.SetIn(new StringReader(num));
            List<Figure> figures = new List<Figure>();
            figures.Add(new Pawn(new Position(0, 0), 'A'));
            figures.Add(new Pawn(new Position(0, 2), 'B'));
            figures.Add(new Pawn(new Position(0, 4), 'C'));
            figures.Add(new Pawn(new Position(0, 6), 'D'));
            figures.Add(new King(new Position(3, 7)));
            GameBoard gameBoard = new GameBoard(figures);

            Engine currentEngine = new Engine(gameBoard, figures);
            currentEngine.ProcessASide("King");
        }
 public static void Main()
 {
     List<Figure> figures = new List<Figure>();
     //figures coordinates are 0-based
     figures.Add(new Pawn(new Position(0, 0), 'A')); //2,4
     figures.Add(new Pawn(new Position(0, 2), 'B')); //2,8
     figures.Add(new Pawn(new Position(0, 4), 'C')); //2,12
     figures.Add(new Pawn(new Position(0, 6), 'D')); //2,16
     //figures.Add(new Pawn(new Position(1, 1), 'Z'));
     //figures.Add(new Pawn(new Position(2, 2), 'I'));
     figures.Add(new King(new Position(7, 3))); //9, 10
     GameBoard gameBoard = new GameBoard(figures);
     Engine engine = new Engine(gameBoard, figures);
     engine.Run();
     Console.WriteLine("\nThank you for using this game!\n\n");
 }
Exemplo n.º 10
0
        public void TestGameBoard_MoreThanOneKingOnTheBoard()
        {
            List<Figure> figures = new List<Figure>();
            // adding pawns
            figures.Add(new Pawn(new Position(0, 0), 'A')); //2,4
            figures.Add(new Pawn(new Position(0, 2), 'B')); //2,8
            figures.Add(new Pawn(new Position(0, 4), 'C')); //2,12
            figures.Add(new Pawn(new Position(0, 6), 'D')); //2,16
            // adding kingS
            figures.Add(new King(new Position(7, 3))); //9, 10
            figures.Add(new King(new Position(4, 4))); //9, 10

            GameBoard gameBoard = new GameBoard(figures);
        }
Exemplo n.º 11
0
 public void TestGameBoard_NoFiguresOnTheBoard()
 {
     GameBoard board = new GameBoard(new List<Figure>());
 }
Exemplo n.º 12
0
 public void TestPawnImpossibleOutOfBorderMove()
 {
     List<Figure> figures = new List<Figure>();
     figures.Add(new Pawn(new Position(0, 0), 'A'));
     figures.Add(new Pawn(new Position(0, 2), 'B'));
     figures.Add(new Pawn(new Position(0, 4), 'C'));
     figures.Add(new Pawn(new Position(0, 6), 'D'));
     King newKing = new King(new Position(3, 7));
     figures.Add(newKing);
     GameBoard gameBoard = new GameBoard(figures);
     Engine currentEngine = new Engine(gameBoard, figures);
     Assert.IsNull(currentEngine.GetNewCoordinates(newKing, Direction.UR), "You can't move here");
 }
Exemplo n.º 13
0
        public void TestPawnImpossibleMove()
        {
            List<Figure> figures = new List<Figure>();
            figures.Add(new Pawn(new Position(0, 0), 'A'));
            figures.Add(new Pawn(new Position(0, 2), 'B'));
            figures.Add(new Pawn(new Position(0, 4), 'C'));
            Pawn newPawn = new Pawn(new Position(3, 4), 'D');
            figures.Add(newPawn);
            King newKing = new King(new Position(4, 5));
            figures.Add(newKing);
            GameBoard gameBoard = new GameBoard(figures);
            Engine currentEngine = new Engine(gameBoard, figures);
            Position newPosition = currentEngine.GetNewCoordinates(newPawn, Direction.DR) ;

            Assert.IsNull(newPosition, "You can't move here,cell is busy");
        }
Exemplo n.º 14
0
        public void TestPositiveKingExit()
        {
            List<Figure> figures = new List<Figure>();
            figures.Add(new Pawn(new Position(0, 0), 'A'));
            figures.Add(new Pawn(new Position(0, 2), 'B'));
            figures.Add(new Pawn(new Position(0, 4), 'C'));
            figures.Add(new Pawn(new Position(0, 6), 'D'));
            figures.Add(new King(new Position(7, 3)));
            GameBoard gameBoard = new GameBoard(figures);

            Engine currentEngine = new Engine(gameBoard, figures);
            int currentKingRow = 2;
            currentEngine.CheckForKingExit(currentKingRow);
            Assert.IsFalse(currentEngine.GameIsInProgress, "King wins for sure!Game over");
        }
Exemplo n.º 15
0
        public void TestPawnUpMoveInTableBorders()
        {
            List<Figure> figures = new List<Figure>();
            figures.Add(new Pawn(new Position(0, 0), 'A'));
            figures.Add(new Pawn(new Position(0, 2), 'B'));
            figures.Add(new Pawn(new Position(0, 4), 'C'));
            Pawn newPawn = new Pawn(new Position(3, 4), 'D');
            figures.Add(newPawn);
            King newKing = new King(new Position(4, 5));
            figures.Add(newKing);
            GameBoard gameBoard = new GameBoard(figures);
            Engine currentEngine = new Engine(gameBoard, figures);
            Position newPosition = currentEngine.GetNewCoordinates(newPawn, Direction.UR) ;

            Assert.IsFalse(currentEngine.ValidateCommand("DUR"), "You can't move in this direction");
        }
Exemplo n.º 16
0
 public void TestGameBoard_PawnWithSymbolRepresentationAsKing()
 {
     List<Figure> figures = new List<Figure>();
     figures.Add(new Pawn(new Position(0, 0), 'K'));
     figures.Add(new King(new Position(1,1))); // if there is no king added there is another exception
     GameBoard gameBoard = new GameBoard(figures);
 }
Exemplo n.º 17
0
        public void TestGameBoard_NoPawnsOnTheBoard()
        {
            List<Figure> figures = new List<Figure>();
            figures.Add(new King(new Position(7, 3))); //9, 10

            GameBoard gameBoard = new GameBoard(figures);
        }
Exemplo n.º 18
0
        public void TestGameBoard_NoKingOnTheBoard()
        {
            // adding only pawns
            List<Figure> figures = new List<Figure>();
            figures.Add(new Pawn(new Position(0, 0), 'A')); //2,4
            figures.Add(new Pawn(new Position(0, 2), 'B')); //2,8
            figures.Add(new Pawn(new Position(0, 4), 'C')); //2,12
            figures.Add(new Pawn(new Position(0, 6), 'D')); //2,16

            GameBoard gameBoard = new GameBoard(figures);
        }
Exemplo n.º 19
0
        public void TestKingPossibleMove()
        {
            List<Figure> figures = new List<Figure>();
            figures.Add(new Pawn(new Position(0, 0), 'A'));
            figures.Add(new Pawn(new Position(0, 2), 'B'));
            figures.Add(new Pawn(new Position(0, 4), 'C'));
            figures.Add(new Pawn(new Position(0, 6), 'D'));
            King newKing = new King(new Position(3, 7));
            figures.Add(newKing);
            GameBoard gameBoard = new GameBoard(figures);
            Engine currentEngine = new Engine(gameBoard, figures);
            bool isNewPosition=(currentEngine.GetNewCoordinates(newKing, Direction.UL))is Position ;

            Assert.IsTrue(isNewPosition, "You can move here");
        }
Exemplo n.º 20
0
        public void TestScenario_KingWinsIn7Moves()
        {
            //string moves = string.Format("kul{0}bdr{0}kul{0}bdl{0}kur{0}adr{0}kur{0}bdl{0}kur{0}bdl{0}kul{0}ddl{0}kul{0}", Environment.NewLine);
            string moves = System.IO.File.ReadAllText("inputScenario_KingWinsIn7Moves.txt");
            using (StringWriter stringWriter = new StringWriter())
            {
                Console.SetOut(stringWriter);

                using (StringReader stringReader = new StringReader(moves))
                {
                    Console.SetIn(stringReader);
                    List<Figure> figures = new List<Figure>();
                    figures.Add(new Pawn(new Position(0, 0), 'A')); //2,4
                    figures.Add(new Pawn(new Position(0, 2), 'B')); //2,8
                    figures.Add(new Pawn(new Position(0, 4), 'C')); //2,12
                    figures.Add(new Pawn(new Position(0, 6), 'D')); //2,16
                    //figures.Add(new Pawn(new Position(2, 6), 'Z'));
                    figures.Add(new King(new Position(7, 3))); //9, 10
                    GameBoard gameBoard = new GameBoard(figures);

                    Engine engine = new Engine(gameBoard, figures); // adding everything to the engine

                    engine.Run(); // executing the game

                    string[] outputLines = stringWriter.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

                    string expected = "King wins in 7 moves!";
                    string actual = outputLines[outputLines.Length - 1];

                    Assert.AreEqual(expected, actual);
                }
            }
        }