Example #1
0
        public void CreateGame()
        {
            GameObject GameObject = new GameObject();
              // check defaults
              Assert.IsNotNull(GameObject);
              Assert.IsTrue(GameObject.GetColorTurn() == Color.white);
              Assert.IsFalse(GameObject.IsMat());
              Assert.IsFalse(GameObject.IsPat());
              Assert.IsNotNull(GameObject.whites);
              Assert.IsNotNull(GameObject.blacks);
              Assert.IsTrue(GameObject.moveCount == 0);

              // check whites
              foreach (Figure f in GameObject.whites)
            Assert.IsTrue(f.color == Color.white);

              Assert.IsNotNull(GameObject.GetFigureByXY(1, 1));
              Assert.IsNotNull(GameObject.GetFigureByXY(8, 1));
              Assert.IsNotNull(GameObject.GetFigureByXY(2, 1));
              Assert.IsNotNull(GameObject.GetFigureByXY(7, 1));
              Assert.IsNotNull(GameObject.GetFigureByXY(3, 1));
              Assert.IsNotNull(GameObject.GetFigureByXY(6, 1));
              Assert.IsNotNull(GameObject.GetFigureByXY(4, 1));
              Assert.IsNotNull(GameObject.GetFigureByXY(5, 1));
              Assert.IsNotNull(GameObject.GetFigureByXY(1, 2));
              Assert.IsNotNull(GameObject.GetFigureByXY(2, 2));
              Assert.IsNotNull(GameObject.GetFigureByXY(3, 2));
              Assert.IsNotNull(GameObject.GetFigureByXY(4, 2));
              Assert.IsNotNull(GameObject.GetFigureByXY(5, 2));
              Assert.IsNotNull(GameObject.GetFigureByXY(6, 2));
              Assert.IsNotNull(GameObject.GetFigureByXY(7, 2));
              Assert.IsNotNull(GameObject.GetFigureByXY(8, 2));

              Assert.IsInstanceOfType(GameObject.GetFigureByXY(1, 1), typeof (Rook));
              Assert.IsInstanceOfType(GameObject.GetFigureByXY(8, 1), typeof (Rook));
              Assert.IsInstanceOfType(GameObject.GetFigureByXY(2, 1), typeof (Knight));
              Assert.IsInstanceOfType(GameObject.GetFigureByXY(7, 1), typeof (Knight));
              Assert.IsInstanceOfType(GameObject.GetFigureByXY(3, 1), typeof (Bishop));
              Assert.IsInstanceOfType(GameObject.GetFigureByXY(6, 1), typeof (Bishop));
              Assert.IsInstanceOfType(GameObject.GetFigureByXY(4, 1), typeof (Queen));
              Assert.IsInstanceOfType(GameObject.GetFigureByXY(5, 1), typeof (King));
              Assert.IsInstanceOfType(GameObject.GetFigureByXY(1, 2), typeof (Pawn));
              Assert.IsInstanceOfType(GameObject.GetFigureByXY(2, 2), typeof (Pawn));
              Assert.IsInstanceOfType(GameObject.GetFigureByXY(3, 2), typeof (Pawn));
              Assert.IsInstanceOfType(GameObject.GetFigureByXY(4, 2), typeof (Pawn));
              Assert.IsInstanceOfType(GameObject.GetFigureByXY(5, 2), typeof (Pawn));
              Assert.IsInstanceOfType(GameObject.GetFigureByXY(6, 2), typeof (Pawn));
              Assert.IsInstanceOfType(GameObject.GetFigureByXY(7, 2), typeof (Pawn));
              Assert.IsInstanceOfType(GameObject.GetFigureByXY(8, 2), typeof (Pawn));

              Assert.IsTrue(GameObject.GetFigureByXY(1, 1).color == Color.white);
              Assert.IsTrue(GameObject.GetFigureByXY(8, 1).color == Color.white);
              Assert.IsTrue(GameObject.GetFigureByXY(2, 1).color == Color.white);
              Assert.IsTrue(GameObject.GetFigureByXY(7, 1).color == Color.white);
              Assert.IsTrue(GameObject.GetFigureByXY(3, 1).color == Color.white);
              Assert.IsTrue(GameObject.GetFigureByXY(6, 1).color == Color.white);
              Assert.IsTrue(GameObject.GetFigureByXY(4, 1).color == Color.white);
              Assert.IsTrue(GameObject.GetFigureByXY(5, 1).color == Color.white);
              Assert.IsTrue(GameObject.GetFigureByXY(1, 2).color == Color.white);
              Assert.IsTrue(GameObject.GetFigureByXY(2, 2).color == Color.white);
              Assert.IsTrue(GameObject.GetFigureByXY(3, 2).color == Color.white);
              Assert.IsTrue(GameObject.GetFigureByXY(4, 2).color == Color.white);
              Assert.IsTrue(GameObject.GetFigureByXY(5, 2).color == Color.white);
              Assert.IsTrue(GameObject.GetFigureByXY(6, 2).color == Color.white);
              Assert.IsTrue(GameObject.GetFigureByXY(7, 2).color == Color.white);
              Assert.IsTrue(GameObject.GetFigureByXY(8, 2).color == Color.white);

              // check blacks
              foreach (Figure f in GameObject.blacks)
            Assert.IsTrue(f.color == Color.black);

              Assert.IsNotNull(GameObject.GetFigureByXY(1, 8));
              Assert.IsNotNull(GameObject.GetFigureByXY(8, 8));
              Assert.IsNotNull(GameObject.GetFigureByXY(2, 8));
              Assert.IsNotNull(GameObject.GetFigureByXY(7, 8));
              Assert.IsNotNull(GameObject.GetFigureByXY(3, 8));
              Assert.IsNotNull(GameObject.GetFigureByXY(6, 8));
              Assert.IsNotNull(GameObject.GetFigureByXY(4, 8));
              Assert.IsNotNull(GameObject.GetFigureByXY(5, 8));
              Assert.IsNotNull(GameObject.GetFigureByXY(1, 7));
              Assert.IsNotNull(GameObject.GetFigureByXY(2, 7));
              Assert.IsNotNull(GameObject.GetFigureByXY(3, 7));
              Assert.IsNotNull(GameObject.GetFigureByXY(4, 7));
              Assert.IsNotNull(GameObject.GetFigureByXY(5, 7));
              Assert.IsNotNull(GameObject.GetFigureByXY(6, 7));
              Assert.IsNotNull(GameObject.GetFigureByXY(7, 7));
              Assert.IsNotNull(GameObject.GetFigureByXY(8, 7));

              Assert.IsInstanceOfType(GameObject.GetFigureByXY(1, 8), typeof (Rook));
              Assert.IsInstanceOfType(GameObject.GetFigureByXY(8, 8), typeof (Rook));
              Assert.IsInstanceOfType(GameObject.GetFigureByXY(2, 8), typeof (Knight));
              Assert.IsInstanceOfType(GameObject.GetFigureByXY(7, 8), typeof (Knight));
              Assert.IsInstanceOfType(GameObject.GetFigureByXY(3, 8), typeof (Bishop));
              Assert.IsInstanceOfType(GameObject.GetFigureByXY(6, 8), typeof (Bishop));
              Assert.IsInstanceOfType(GameObject.GetFigureByXY(4, 8), typeof (Queen));
              Assert.IsInstanceOfType(GameObject.GetFigureByXY(5, 8), typeof (King));
              Assert.IsInstanceOfType(GameObject.GetFigureByXY(1, 7), typeof (Pawn));
              Assert.IsInstanceOfType(GameObject.GetFigureByXY(2, 7), typeof (Pawn));
              Assert.IsInstanceOfType(GameObject.GetFigureByXY(3, 7), typeof (Pawn));
              Assert.IsInstanceOfType(GameObject.GetFigureByXY(4, 7), typeof (Pawn));
              Assert.IsInstanceOfType(GameObject.GetFigureByXY(5, 7), typeof (Pawn));
              Assert.IsInstanceOfType(GameObject.GetFigureByXY(6, 7), typeof (Pawn));
              Assert.IsInstanceOfType(GameObject.GetFigureByXY(7, 7), typeof (Pawn));
              Assert.IsInstanceOfType(GameObject.GetFigureByXY(8, 7), typeof (Pawn));

              Assert.IsTrue(GameObject.GetFigureByXY(1, 8).color == Color.black);
              Assert.IsTrue(GameObject.GetFigureByXY(8, 8).color == Color.black);
              Assert.IsTrue(GameObject.GetFigureByXY(2, 8).color == Color.black);
              Assert.IsTrue(GameObject.GetFigureByXY(7, 8).color == Color.black);
              Assert.IsTrue(GameObject.GetFigureByXY(3, 8).color == Color.black);
              Assert.IsTrue(GameObject.GetFigureByXY(6, 8).color == Color.black);
              Assert.IsTrue(GameObject.GetFigureByXY(4, 8).color == Color.black);
              Assert.IsTrue(GameObject.GetFigureByXY(5, 8).color == Color.black);
              Assert.IsTrue(GameObject.GetFigureByXY(1, 7).color == Color.black);
              Assert.IsTrue(GameObject.GetFigureByXY(2, 7).color == Color.black);
              Assert.IsTrue(GameObject.GetFigureByXY(3, 7).color == Color.black);
              Assert.IsTrue(GameObject.GetFigureByXY(4, 7).color == Color.black);
              Assert.IsTrue(GameObject.GetFigureByXY(5, 7).color == Color.black);
              Assert.IsTrue(GameObject.GetFigureByXY(6, 7).color == Color.black);
              Assert.IsTrue(GameObject.GetFigureByXY(7, 7).color == Color.black);
              Assert.IsTrue(GameObject.GetFigureByXY(8, 7).color == Color.black);

              // check kings
              Assert.IsInstanceOfType(GameObject.GetKing(Color.black), typeof (King));
              Assert.IsInstanceOfType(GameObject.GetKing(Color.white), typeof (King));
              Assert.IsTrue(GameObject.GetKing(Color.black).color == Color.black);
              Assert.IsTrue(GameObject.GetKing(Color.white).color == Color.white);
        }
Example #2
0
        public void TestDraw()
        {
            GameObject game = new GameObject();
              // get knight
              game.whites = new List<Figure>();
              game.blacks = new List<Figure>();
              King wKing = new King(game, 2, 2, Color.white);
              King bKing = new King(game, 2, 6, Color.black);
              Rook wRook = new Rook(game, 1, 1, Color.white);
              Rook bRook = new Rook(game, 1, 7, Color.black);
              Pawn wPawn = new Pawn(game, 5, 2, Color.white);
              game.whites.Add(wKing);
              game.whites.Add(wRook);
              game.blacks.Add(bKing);
              game.blacks.Add(bRook);
              game.whites.Add(wPawn);
              game.UpdateAllBeatFields();

              Assert.IsFalse(game.isDraw);
              wRook.Move(2, 1);
              bRook.Move(2, 7);
              Assert.IsTrue(game.movesToDraw == 2);
              wPawn.Move(5, 4);
              Assert.IsTrue(game.movesToDraw == 0);
              bRook.Move(3, 7);
              wPawn.Move(5, 5);
              Assert.IsTrue(game.movesToDraw == 0);
              bRook.Move(4, 7);
              wPawn.Move(5, 6);
              Assert.IsTrue(game.movesToDraw == 0);
              bRook.Move(1, 7);
              wPawn.Move(5, 7);
              Assert.IsTrue(game.movesToDraw == 0);
              bRook.Move(2, 7);
              wRook.Move(1, 1);
              Assert.IsTrue(game.movesToDraw == 2);
              bRook.Move(5, 7);
              Assert.IsTrue(game.movesToDraw == 0);

              sbyte new_x;
              for (int i = 0; i < 100; i++)
              {
            if (game.GetColorTurn() == Color.white)
            {
              new_x = (sbyte) (wRook.field.x == 1 ? 2 : 1);
              Assert.IsTrue(wRook.Move(new_x, 1));
            }
            else
            {
              new_x = (sbyte) (bRook.field.x == 1 ? 2 : 1);
              Assert.IsTrue(bRook.Move(new_x, 7));
            }
            if (game.movesToDraw == 100)
              Assert.IsTrue(game.isDraw);
              }
        }