Beispiel #1
0
        public void TestMove()
        {
            GameObject GameObject = new GameObject();
              GameObject.whites = new List<Figure>();
              GameObject.blacks = new List<Figure>();
              King wKing = new King(GameObject, 2, 1, Color.white);
              Queen wQueen = new Queen(GameObject, 2, 2, Color.white);
              King bKing = new King(GameObject, 7, 8, Color.black);
              Queen bQueen = new Queen(GameObject, 7, 7, Color.black);
              Rook bRook1 = new Rook(GameObject, 1, 8, Color.black);
              Rook bRook2 = new Rook(GameObject, 8, 8, Color.black);
              Rook wRook1 = new Rook(GameObject, 1, 1, Color.white);
              Rook wRook2 = new Rook(GameObject, 8, 1, Color.white);
              GameObject.whites.Add(wKing);
              GameObject.blacks.Add(bKing);
              GameObject.blacks.Add(bQueen);
              GameObject.whites.Add(wQueen);
              GameObject.UpdateAllBeatFields();

              Assert.IsTrue(wKing.MoveFields.Count == 4);
              Assert.IsTrue(wKing.CanMoveToPosition(1, 1));
              Assert.IsTrue(wKing.CanMoveToPosition(1, 2));
              Assert.IsTrue(wKing.CanMoveToPosition(3, 1));
              Assert.IsTrue(wKing.CanMoveToPosition(3, 2));

              Assert.IsTrue(bKing.MoveFields.Count == 4);
              Assert.IsTrue(bKing.CanMoveToPosition(6, 8));
              Assert.IsTrue(bKing.CanMoveToPosition(6, 7));
              Assert.IsTrue(bKing.CanMoveToPosition(8, 8));
              Assert.IsTrue(bKing.CanMoveToPosition(8, 7));

              Assert.IsTrue(wKing.Move(3, 2));
              Assert.IsTrue(bKing.Move(6, 7));
              Assert.IsFalse(wKing.Move(3, 3));
              Assert.IsTrue(wQueen.Move(7, 7));
              Assert.IsTrue(GameObject.blacks.Count == 1);
              Assert.IsFalse(bKing.Move(5, 7));
              Assert.IsFalse(bKing.Move(6, 8));
              Assert.IsTrue(bKing.Move(7, 7));
              Assert.IsTrue(GameObject.whites.Count == 1);

              // verify castling
              GameObject.blacks.Add(bRook1);
              GameObject.blacks.Add(bRook2);
              GameObject.whites.Add(wRook1);
              GameObject.whites.Add(wRook2);
              wKing.field = new Field(5, 1);
              bKing.field = new Field(5, 8);
              wKing.moveCount = 0;
              bKing.moveCount = 0;
              GameObject.UpdateAllBeatFields();
              Assert.IsTrue(wKing.CanMoveToPosition(7, 1));
              Assert.IsTrue(wKing.CanMoveToPosition(3, 1));
              wKing.moveCount = 1;
              GameObject.UpdateAllBeatFields();
              Assert.IsFalse(wKing.CanMoveToPosition(7, 1));
              Assert.IsFalse(wKing.CanMoveToPosition(3, 1));
              wRook2.moveCount = 1;
              wRook1.moveCount = 1;
              GameObject.UpdateAllBeatFields();
              Assert.IsFalse(wKing.CanMoveToPosition(7, 1));
              Assert.IsFalse(wKing.CanMoveToPosition(3, 1));
              wKing.moveCount = 0;
              GameObject.UpdateAllBeatFields();
              Assert.IsFalse(wKing.CanMoveToPosition(7, 1));
              Assert.IsFalse(wKing.CanMoveToPosition(3, 1));
              wRook2.moveCount = 0;
              wRook1.moveCount = 0;
              GameObject.UpdateAllBeatFields();
              Assert.IsTrue(wKing.CanMoveToPosition(7, 1));
              Assert.IsTrue(wKing.CanMoveToPosition(3, 1));

              bRook1.field = new Field(2, 7);
              GameObject.UpdateAllBeatFields();
              Assert.IsTrue(wKing.CanMoveToPosition(3, 1));
              bRook1.field = new Field(3, 7);
              GameObject.UpdateAllBeatFields();
              Assert.IsFalse(wKing.CanMoveToPosition(3, 1));
              bRook1.field = new Field(4, 7);
              GameObject.UpdateAllBeatFields();
              Assert.IsFalse(wKing.CanMoveToPosition(3, 1));
              bRook1.field = new Field(5, 7);
              GameObject.UpdateAllBeatFields();
              Assert.IsFalse(wKing.CanMoveToPosition(7, 1));
              Assert.IsFalse(wKing.CanMoveToPosition(3, 1));
              bRook1.field = new Field(6, 7);
              GameObject.UpdateAllBeatFields();
              Assert.IsTrue(wKing.CanMoveToPosition(3, 1));
              Assert.IsFalse(wKing.CanMoveToPosition(7, 1));
              bRook1.field = new Field(7, 7);
              GameObject.UpdateAllBeatFields();
              Assert.IsFalse(wKing.CanMoveToPosition(7, 1));

              // check figure taking by king
              bRook1.field = new Field(5, 2);
              bRook2.field = new Field(7, 2);
              GameObject.UpdateAllBeatFields();
              Assert.IsFalse(wKing.Move(5, 2));

              bRook2.field = new Field(7, 3);
              bKing.field = new Field(6, 3);
              GameObject.UpdateAllBeatFields();
              Assert.IsFalse(wKing.Move(5, 2));

              bRook2.field = new Field(7, 3);
              bKing.field = new Field(6, 4);
              GameObject.UpdateAllBeatFields();
              Assert.IsTrue(wKing.Move(5, 2));
              Assert.IsFalse(bKing.Move(6, 3));
              Assert.IsFalse(bKing.Move(7, 3));
              Assert.IsTrue(bKing.Move(5, 4));
        }
Beispiel #2
0
        public void GamePat()
        {
            GameObject game = new GameObject();
              game.whites = new List<Figure>();
              game.blacks = new List<Figure>();
              King wKing = new King(game, 2, 3, Color.white);
              King bKing = new King(game, 1, 1, Color.black);
              Knight bKnight = new Knight(game, 2, 1, Color.black);
              Rook wRook = new Rook(game, 7, 2, Color.white);
              game.whites.Add(wKing);
              game.whites.Add(wRook);
              game.blacks.Add(bKing);
              game.blacks.Add(bKnight);
              game.UpdateAllBeatFields();

              Assert.IsTrue(wRook.Move(2, 2));
              Assert.IsFalse(game.isPat);
              Assert.IsTrue(bKnight.Move(4, 2));
              Assert.IsTrue(wRook.Move(4, 2));
              Assert.IsTrue(bKing.Move(2, 1));
              Assert.IsTrue(wRook.Move(3, 2));
              Assert.IsTrue(bKing.Move(1, 1));
              Assert.IsTrue(wRook.Move(2, 2));
              Assert.IsTrue(game.isPat);
        }
Beispiel #3
0
        public void TestRepeatPosition3Times()
        {
            GameObject game = new GameObject();
              game.UpdateAllBeatFields();
              game.whites[0].Move(1, 4);
              game.blacks[0].Move(1, 5);
              Assert.IsFalse(game.IsPositionRepeatsThirdTime());
              game.GetFigureByXY(2, 1).Move(3, 3);
              game.GetFigureByXY(2, 8).Move(3, 6);
              Assert.IsFalse(game.IsPositionRepeatsThirdTime());
              game.GetFigureByXY(3, 3).Move(2, 1);
              game.GetFigureByXY(3, 6).Move(2, 8);
              Assert.IsFalse(game.IsPositionRepeatsThirdTime());
              game.GetFigureByXY(2, 1).Move(3, 3);
              game.GetFigureByXY(2, 8).Move(3, 6);
              Assert.IsFalse(game.IsPositionRepeatsThirdTime());
              game.GetFigureByXY(3, 3).Move(2, 1);
              game.GetFigureByXY(3, 6).Move(2, 8);
              Assert.IsTrue(game.IsPositionRepeatsThirdTime());

              game = new GameObject();
              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);
              game.whites.Add(wKing);
              game.blacks.Add(bKing);
              game.UpdateAllBeatFields();
              wKing.Move(1, 2);
              bKing.Move(1, 6);
              wKing.Move(2, 2);
              bKing.Move(2, 6);
              wKing.Move(1, 2);
              bKing.Move(1, 6);
              wKing.Move(2, 2);
              bKing.Move(2, 6);
              wKing.Move(1, 2);
              Assert.IsTrue(game.IsPositionRepeatsThirdTime());
        }
Beispiel #4
0
        public void TestMove()
        {
            GameObject GameObject = new GameObject();
              GameObject.whites = new List<Figure>();
              GameObject.blacks = new List<Figure>();
              King wKing = new King(GameObject, 1, 5, Color.white);
              Pawn wPawn1 = new Pawn(GameObject, 3, 2, Color.white);
              Pawn wPawn2 = new Pawn(GameObject, 4, 2, Color.white);
              Pawn wPawn3 = new Pawn(GameObject, 5, 2, Color.white);
              King bKing = new King(GameObject, 8, 4, Color.black);
              Pawn bPawn1 = new Pawn(GameObject, 3, 7, Color.black);
              Pawn bPawn2 = new Pawn(GameObject, 4, 7, Color.black);
              Pawn bPawn3 = new Pawn(GameObject, 5, 7, Color.black);
              GameObject.whites.Add(wKing);
              GameObject.whites.Add(wPawn1);
              GameObject.whites.Add(wPawn2);
              GameObject.whites.Add(wPawn3);

              GameObject.blacks.Add(bKing);
              GameObject.blacks.Add(bPawn1);
              GameObject.blacks.Add(bPawn2);
              GameObject.blacks.Add(bPawn3);
              GameObject.UpdateAllBeatFields();

              Assert.IsFalse(wPawn1.Move(3, 5));
              Assert.IsFalse(wPawn1.Move(2, 3));
              Assert.IsTrue(wPawn1.Move(3, 4));
              Assert.IsTrue(bPawn3.Move(5, 6));
              Assert.IsTrue(wPawn1.Move(3, 5));
              Assert.IsFalse(bPawn3.Move(5, 4));
              Assert.IsTrue(bPawn2.Move(4, 5));
              Assert.IsTrue(wPawn1.Move(4, 6)); // cross-field taking
              Assert.IsTrue(GameObject.blacks.Count == 3);

              Assert.IsTrue(bPawn1.Move(4, 6));
              Assert.IsTrue(GameObject.whites.Count == 3);

              bPawn1.field = new Field(3, 7);
              bPawn1.moveCount = 0;
              wPawn2.field = new Field(4, 5);
              Queen bQueen = new Queen(GameObject, 8, 5, Color.black);
              GameObject.blacks.Add(bQueen);
              GameObject.UpdateAllBeatFields();

              Assert.IsTrue(wKing.Move(2, 5));
              Assert.IsTrue(bPawn1.Move(3, 5));
              Assert.IsFalse(wPawn2.Move(3, 6)); // Can't take on cross-field because of wKing became opened to attack
              Assert.IsTrue(wKing.Move(1, 6));
              Assert.IsTrue(bQueen.Move(7, 4));
              Assert.IsFalse(wPawn2.Move(3, 6)); // Can't take on cross-field because of different move count
        }