예제 #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);
        }
예제 #2
0
        public void GameMoves()
        {
            GameObject game = new GameObject();
              // whites ♔ WHITE KING | ♕ WHITE QUEEN | ♖ WHITE ROOK | ♗ WHITE BISHOP | ♘ WHITE KNIGHT | ♙ WHITE PAWN
              // blacks ♚ BLACK KING | ♛ BLACK QUEEN | ♜ BLACK ROOK | ♝ BLACK BISHOP | ♞ BLACK KNIGHT | ♟ BLACK PAWN
              short movecount = game.moveCount;
              Assert.IsFalse(game.blacks[0].Move(1, 4)); // not black turn
              Assert.IsTrue(movecount == game.moveCount && movecount == game.blacks[0].moveCount);
              Assert.IsFalse(game.GetKing(Color.white).Move(5, 1)); // can't move to the field figure standing in
              Assert.IsTrue(movecount == game.moveCount && 0 == game.GetKing(Color.white).moveCount);
              Assert.IsFalse(game.whites[0].Move(1, 5)); // wrong move for pawn
              Assert.IsTrue(movecount == game.moveCount && movecount == game.whites[0].moveCount);
              Assert.IsTrue(game.whites[4].Move(5, 4)); // correct move by King's pawn
              movecount++;
              Assert.IsTrue(movecount == game.moveCount && movecount == game.whites[4].moveCount);
              Assert.IsFalse(game.GetKing(Color.white).Move(5, 2)); // can't move - black's turn
              Assert.IsTrue(movecount == game.moveCount && 0 == game.GetKing(Color.white).moveCount);
              Assert.IsTrue(game.blacks[4].Move(5, 5)); // correct move by King's pawn
              movecount++;
              Assert.IsTrue(movecount == game.moveCount && movecount == game.blacks[4].moveCount);

              Figure wBishop = game.GetFigureByXY(6, 1);
              Assert.IsTrue(wBishop.Move(4, 3));
              Assert.IsNull(game.GetFigureByXY(6, 1));
              movecount++;
              Assert.IsTrue(movecount == game.moveCount && movecount == wBishop.moveCount);

              Figure bBishop = game.GetFigureByXY(6, 8);
              Assert.IsTrue(bBishop.Move(4, 6));
              movecount++;
              Assert.IsTrue(movecount == game.moveCount && movecount == bBishop.moveCount);

              Figure wKnight = game.GetFigureByXY(7, 1);
              Assert.IsTrue(wKnight.Move(6, 3));
              movecount++;
              Assert.IsTrue(movecount == game.moveCount && movecount == wKnight.moveCount);

              Figure bKnight = game.GetFigureByXY(7, 8);
              Assert.IsTrue(bKnight.Move(6, 6));
              movecount++;
              Assert.IsTrue(movecount == game.moveCount && movecount == bKnight.moveCount);

              King wKing = game.GetKing(Color.white); // castling
              Assert.IsTrue(wKing.Move(7, 1));
              movecount++;
              Assert.IsTrue(movecount == game.moveCount && movecount == wKing.moveCount);

              Figure bRook = game.GetFigureByXY(8, 8); // prevent castling for black's
              bRook.moveCount = movecount;
              King bKing = game.GetKing(Color.black);
              Assert.IsFalse(bKing.Move(7, 8));
              Assert.IsTrue(bKing.field.x == 5);
              bRook.moveCount = 0;
              Assert.IsTrue(bKing.Move(7, 8));
        }