Ejemplo n.º 1
0
        public void TestAttackAndTake()
        {
            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);
              GameObject.whites.Add(wKing);
              GameObject.blacks.Add(bKing);
              GameObject.blacks.Add(bQueen);
              GameObject.whites.Add(wQueen);
              GameObject.UpdateAllBeatFields();

              Assert.IsTrue(wKing.CanAttackPosition(1, 1));
              Assert.IsTrue(wKing.CanAttackPosition(1, 2));
              Assert.IsTrue(wKing.CanAttackPosition(3, 1));
              Assert.IsTrue(wKing.CanAttackPosition(3, 2));
              Assert.IsTrue(wKing.CanAttackPosition(2, 2));

              Assert.IsTrue(bKing.CanAttackPosition(6, 8));
              Assert.IsTrue(bKing.CanAttackPosition(6, 7));
              Assert.IsTrue(bKing.CanAttackPosition(8, 8));
              Assert.IsTrue(bKing.CanAttackPosition(8, 7));
              Assert.IsTrue(bKing.CanAttackPosition(7, 7));
        }
Ejemplo n.º 2
0
        public void TestAttackAndTake()
        {
            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.IsTrue(wPawn1.CanAttackPosition(2, 3));
              Assert.IsTrue(wPawn1.CanAttackPosition(4, 3));

              Assert.IsTrue(bPawn2.CanAttackPosition(3, 6));
              Assert.IsTrue(bPawn2.CanAttackPosition(5, 6));
        }
Ejemplo n.º 3
0
 public Rook(GameObject _g, sbyte x, sbyte y, Color c)
 {
     this.GameObject = _g;
       this.field = new Field(x, y);
       this.color = c;
       this.type = FigureTypes.Rook;
       this.moveCount = 0;
 }
Ejemplo n.º 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
        }
Ejemplo n.º 5
0
        public void TestMove()
        {
            GameObject GameObject = new GameObject();
              GameObject.whites = new List<Figure>();
              GameObject.blacks = new List<Figure>();
              King wKing = new King(GameObject, 1, 1, Color.white);
              Bishop wBish = new Bishop(GameObject, 3, 3, Color.white);
              King bKing = new King(GameObject, 7, 7, Color.black);
              Bishop bBish = new Bishop(GameObject, 5, 5, Color.black);
              GameObject.whites.Add(wKing);
              GameObject.blacks.Add(bKing);
              GameObject.blacks.Add(bBish);
              GameObject.whites.Add(wBish);

              GameObject.UpdateAllBeatFields();
              Assert.IsTrue(wBish.MoveFields.Count == 6);
              Assert.IsTrue(wBish.CanMoveToPosition(2, 4));
              Assert.IsTrue(wBish.CanMoveToPosition(1, 5));
              Assert.IsTrue(wBish.CanMoveToPosition(2, 2));
              Assert.IsTrue(wBish.CanMoveToPosition(4, 2));
              Assert.IsTrue(wBish.CanMoveToPosition(5, 1));
              Assert.IsTrue(wBish.CanMoveToPosition(4, 4));

              Assert.IsTrue(bBish.MoveFields.Count == 8);
              Assert.IsTrue(bBish.CanMoveToPosition(6, 6));
              Assert.IsTrue(bBish.CanMoveToPosition(6, 4));
              Assert.IsTrue(bBish.CanMoveToPosition(7, 3));
              Assert.IsTrue(bBish.CanMoveToPosition(8, 2));
              Assert.IsTrue(bBish.CanMoveToPosition(4, 4));
              Assert.IsTrue(bBish.CanMoveToPosition(4, 6));
              Assert.IsTrue(bBish.CanMoveToPosition(3, 7));
              Assert.IsTrue(bBish.CanMoveToPosition(2, 8));

              Assert.IsFalse(wBish.Move(2, 4));
              Assert.IsFalse(wBish.Move(1, 5));
              Assert.IsFalse(wBish.Move(4, 2));
              Assert.IsFalse(wBish.Move(5, 1));
              Assert.IsTrue(wBish.Move(2, 2));

              Assert.IsFalse(bBish.Move(6, 4));
              Assert.IsFalse(bBish.Move(7, 3));
              Assert.IsFalse(bBish.Move(8, 2));
              Assert.IsFalse(bBish.Move(4, 6));
              Assert.IsFalse(bBish.Move(3, 7));
              Assert.IsFalse(bBish.Move(2, 8));
              Assert.IsTrue(bBish.Move(4, 4));

              Assert.IsTrue(wBish.Move(4, 4));
              Assert.IsTrue(GameObject.blacks.Count == 1);
        }
Ejemplo n.º 6
0
 public King(GameObject _g, sbyte x, sbyte y, Color c)
 {
     this.GameObject = _g;
       this.field = new Field(x, y);
       this.color = c;
       this.moveCount = 0;
       this.type = FigureTypes.King;
       this.moves = new List<Field>();
       this.moves.Add(new Field((sbyte) 1, (sbyte) 1));
       this.moves.Add(new Field((sbyte) 1, (sbyte) 0));
       this.moves.Add(new Field((sbyte) 1, (sbyte) -1));
       this.moves.Add(new Field((sbyte) 0, (sbyte) 1));
       this.moves.Add(new Field((sbyte) 0, (sbyte) -1));
       this.moves.Add(new Field((sbyte) -1, (sbyte) 1));
       this.moves.Add(new Field((sbyte) -1, (sbyte) 0));
       this.moves.Add(new Field((sbyte) -1, (sbyte) -1));
       this.type = FigureTypes.King;
 }
Ejemplo n.º 7
0
        public void TestTakeAndAttack()
        {
            GameObject GameObject = new GameObject();
              GameObject.whites = new List<Figure>();
              GameObject.blacks = new List<Figure>();
              King wKing = new King(GameObject, 2, 1, Color.white);
              Bishop wBish = new Bishop(GameObject, 3, 3, Color.white);
              King bKing = new King(GameObject, 8, 7, Color.black);
              Bishop bBish = new Bishop(GameObject, 5, 5, Color.black);
              GameObject.whites.Add(wKing);
              GameObject.blacks.Add(bKing);
              GameObject.blacks.Add(bBish);
              GameObject.whites.Add(wBish);

              GameObject.UpdateAllBeatFields();
              Assert.IsTrue(wBish.CanAttackPosition(2, 4));
              Assert.IsTrue(wBish.CanAttackPosition(1, 5));
              Assert.IsTrue(wBish.CanAttackPosition(1, 1));
              Assert.IsTrue(wBish.CanAttackPosition(2, 2));
              Assert.IsTrue(wBish.CanAttackPosition(4, 2));
              Assert.IsTrue(wBish.CanAttackPosition(5, 1));
              Assert.IsTrue(wBish.CanAttackPosition(4, 4));
              Assert.IsTrue(wBish.CanAttackPosition(5, 5));

              Assert.IsTrue(bBish.CanAttackPosition(6, 6));
              Assert.IsTrue(bBish.CanAttackPosition(7, 7));
              Assert.IsTrue(bBish.CanAttackPosition(8, 8));
              Assert.IsTrue(bBish.CanAttackPosition(6, 4));
              Assert.IsTrue(bBish.CanAttackPosition(7, 3));
              Assert.IsTrue(bBish.CanAttackPosition(8, 2));
              Assert.IsTrue(bBish.CanAttackPosition(4, 4));
              Assert.IsTrue(bBish.CanAttackPosition(3, 3));
              Assert.IsTrue(bBish.CanAttackPosition(4, 6));
              Assert.IsTrue(bBish.CanAttackPosition(3, 7));
              Assert.IsTrue(bBish.CanAttackPosition(2, 8));
        }
Ejemplo n.º 8
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());
        }
Ejemplo n.º 9
0
        public void TestMove()
        {
            GameObject GameObject = new GameObject();
              GameObject.whites = new List<Figure>();
              GameObject.blacks = new List<Figure>();
              King wKing = new King(GameObject, 1, 1, Color.white);
              King bKing = new King(GameObject, 8, 8, Color.black);
              Knight bKnight = new Knight(GameObject, 5, 5, Color.black);
              Knight wKnight = new Knight(GameObject, 5, 4, Color.white);
              GameObject.whites.Add(wKing);
              GameObject.blacks.Add(bKing);
              GameObject.blacks.Add(bKnight);
              GameObject.whites.Add(wKnight);

              // knights in the middle of the field
              GameObject.UpdateAllBeatFields();
              Assert.IsTrue(wKnight.MoveFields.Count == 8);
              Assert.IsTrue(wKnight.CanMoveToPosition(3, 5));
              Assert.IsTrue(wKnight.CanMoveToPosition(3, 3));
              Assert.IsTrue(wKnight.CanMoveToPosition(4, 6));
              Assert.IsTrue(wKnight.CanMoveToPosition(4, 2));
              Assert.IsTrue(wKnight.CanMoveToPosition(6, 6));
              Assert.IsTrue(wKnight.CanMoveToPosition(6, 2));
              Assert.IsTrue(wKnight.CanMoveToPosition(7, 3));
              Assert.IsTrue(wKnight.CanMoveToPosition(7, 5));

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

              // knights at the border of the field
              bKnight.field.x = 8;
              bKnight.field.y = 7;
              wKnight.field.x = 3;
              wKnight.field.y = 2;
              GameObject.UpdateAllBeatFields();

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

              Assert.IsTrue(bKnight.MoveFields.Count == 3);
              Assert.IsTrue(bKnight.CanMoveToPosition(6, 8));
              Assert.IsTrue(bKnight.CanMoveToPosition(6, 6));
              Assert.IsTrue(bKnight.CanMoveToPosition(7, 5));

              // Add white rook
              Rook wRook = new Rook(GameObject, 8, 2, Color.white);
              GameObject.whites.Add(wRook);
              GameObject.UpdateAllBeatFields();

              Assert.IsTrue(wRook.Move(8, 3));
              Assert.IsFalse(bKnight.Move(6, 8)); // Can't move knight - open attack on king
              Assert.IsTrue(bKnight.field.x == 8 && bKnight.field.y == 7);
              Assert.IsFalse(bKnight.Move(6, 6)); // Can't move knight - open attack on king
              Assert.IsTrue(bKnight.field.x == 8 && bKnight.field.y == 7);
              Assert.IsFalse(bKnight.Move(7, 5)); // Can't move knight - open attack on king
              Assert.IsTrue(bKnight.field.x == 8 && bKnight.field.y == 7);

              // Add white pawn and beat it by knight
              Pawn p1 = new Pawn(GameObject, 6, 6, Color.white);
              GameObject.whites.Add(p1);
              GameObject.UpdateAllBeatFields();
              Assert.IsFalse(bKnight.Move(6, 6));

              // remove rook
              GameObject.whites.Remove(wRook);
              GameObject.UpdateAllBeatFields();
              Assert.IsTrue(bKnight.Move(6, 6));

              // add white rook
              wRook.field.x = 5;
              wRook.field.y = 1;
              GameObject.whites.Add(wRook);
              GameObject.UpdateAllBeatFields();
              Assert.IsTrue(wRook.Move(5, 8));
              Assert.IsTrue(bKnight.Move(5, 8));

              // add white rook again
              wRook.field.x = 1;
              wRook.field.y = 2;
              bKnight.field.x = 6;
              bKnight.field.y = 6;
              GameObject.whites.Add(wRook);
              GameObject.UpdateAllBeatFields();
              Assert.IsTrue(wRook.Move(1, 8));
              Assert.IsFalse(bKnight.Move(5, 4)); //king not covered
              Assert.IsFalse(bKnight.Move(7, 4)); //king not covered
              Assert.IsTrue(bKnight.Move(7, 8)); //cover king
        }
Ejemplo n.º 10
0
        public void TestAttackAndTake()
        {
            GameObject GameObject = new GameObject();
              GameObject.whites = new List<Figure>();
              GameObject.blacks = new List<Figure>();
              King wKing = new King(GameObject, 1, 1, Color.white);
              King bKing = new King(GameObject, 8, 8, Color.black);
              Knight bKnight = new Knight(GameObject, 5, 5, Color.black);
              Knight wKnight = new Knight(GameObject, 5, 4, Color.white);
              GameObject.whites.Add(wKing);
              GameObject.blacks.Add(bKing);
              GameObject.blacks.Add(bKnight);
              GameObject.whites.Add(wKnight);

              // knights in the middle of the field
              GameObject.UpdateAllBeatFields();
              Assert.IsTrue(wKnight.CanAttackPosition(3, 5));
              Assert.IsTrue(wKnight.CanAttackPosition(3, 3));
              Assert.IsTrue(wKnight.CanAttackPosition(4, 6));
              Assert.IsTrue(wKnight.CanAttackPosition(4, 2));
              Assert.IsTrue(wKnight.CanAttackPosition(6, 6));
              Assert.IsTrue(wKnight.CanAttackPosition(6, 2));
              Assert.IsTrue(wKnight.CanAttackPosition(7, 3));
              Assert.IsTrue(wKnight.CanAttackPosition(7, 5));

              Assert.IsTrue(bKnight.CanAttackPosition(3, 6));
              Assert.IsTrue(bKnight.CanAttackPosition(3, 4));
              Assert.IsTrue(bKnight.CanAttackPosition(4, 7));
              Assert.IsTrue(bKnight.CanAttackPosition(4, 3));
              Assert.IsTrue(bKnight.CanAttackPosition(6, 7));
              Assert.IsTrue(bKnight.CanAttackPosition(6, 3));
              Assert.IsTrue(bKnight.CanAttackPosition(7, 4));
              Assert.IsTrue(bKnight.CanAttackPosition(7, 6));

              // knights at the border of the field
              bKnight.field.x = 8;
              bKnight.field.y = 7;
              wKnight.field.x = 3;
              wKnight.field.y = 2;
              GameObject.UpdateAllBeatFields();

              Assert.IsTrue(wKnight.CanAttackPosition(1, 3));
              Assert.IsTrue(wKnight.CanAttackPosition(2, 4));
              Assert.IsTrue(wKnight.CanAttackPosition(4, 4));
              Assert.IsTrue(wKnight.CanAttackPosition(5, 3));
              Assert.IsTrue(wKnight.CanAttackPosition(5, 1));

              Assert.IsTrue(bKnight.CanMoveToPosition(6, 8));
              Assert.IsTrue(bKnight.CanMoveToPosition(6, 6));
              Assert.IsTrue(bKnight.CanMoveToPosition(7, 5));

              // Add black pawns
              Pawn bp1 = new Pawn(GameObject, 2, 4, Color.black);
              Pawn bp2 = new Pawn(GameObject, 5, 3, Color.black);
              GameObject.blacks.Add(bp1);
              GameObject.blacks.Add(bp2);
              Assert.IsTrue(wKnight.CanAttackPosition(1, 3));
              Assert.IsTrue(wKnight.CanAttackPosition(2, 4));
              Assert.IsTrue(wKnight.CanAttackPosition(4, 4));
              Assert.IsTrue(wKnight.CanAttackPosition(5, 3));
              Assert.IsTrue(wKnight.CanAttackPosition(5, 1));
        }
Ejemplo n.º 11
0
 public Bishop(GameObject _g, sbyte x, sbyte y, Color c)
 {
     this.GameObject = _g;
       this.field = new Field(x, y);
       this.color = c;
 }
Ejemplo n.º 12
0
        public void GameMate()
        {
            // Variant 1
              GameObject game = new GameObject();
              Assert.IsTrue(game.GetFigureByXY(5, 2).Move(5, 4));
              Assert.IsTrue(game.GetFigureByXY(5, 7).Move(5, 5));
              Assert.IsTrue(game.GetFigureByXY(6, 1).Move(3, 4));
              Assert.IsTrue(game.GetFigureByXY(6, 8).Move(3, 5));
              Assert.IsTrue(game.GetFigureByXY(4, 1).Move(6, 3));
              Assert.IsTrue(game.GetFigureByXY(8, 7).Move(8, 5));
              Assert.IsTrue(game.GetFigureByXY(6, 3).Move(6, 7));
              Assert.IsTrue(game.isMat);

              // Variant 2
              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(1, 2));
              Assert.IsTrue(game.isMat);
        }
Ejemplo n.º 13
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));
        }
Ejemplo n.º 14
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);
        }
Ejemplo n.º 15
0
        public void TestTransform()
        {
            GameObject GameObject = new GameObject();
              GameObject.whites = new List<Figure>();
              GameObject.blacks = new List<Figure>();
              King wKing = new King(GameObject, 1, 5, Color.white);
              King bKing = new King(GameObject, 8, 4, Color.black);
              Pawn wPawn1 = new Pawn(GameObject, 1, 7, Color.white);
              GameObject.blacks.Add(bKing);
              GameObject.whites.Add(wKing);
              GameObject.whites.Add(wPawn1);
              GameObject.UpdateAllBeatFields();

              Assert.IsFalse(wPawn1.Transform(FigureTypes.Knight));
              Assert.IsTrue(wPawn1.Move(1, 8));
              Assert.IsFalse(wPawn1.Transform(FigureTypes.Pawn));
              Assert.IsFalse(wPawn1.Transform(FigureTypes.King));
              Assert.IsTrue(wPawn1.Transform(FigureTypes.Knight));
              Figure newFigure = GameObject.GetFigureByXY(wPawn1.field.x, wPawn1.field.y);
              Assert.IsTrue(newFigure.type == FigureTypes.Knight);
              Assert.IsTrue(newFigure.field.x == 1);
              Assert.IsTrue(newFigure.field.y == 8);
              Assert.IsTrue(newFigure.MoveFields.Count == 2);
              Assert.IsTrue(newFigure.CanMoveToPosition(2, 6));
              Assert.IsTrue(newFigure.CanMoveToPosition(3, 7));
        }
Ejemplo n.º 16
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);
              }
        }
Ejemplo n.º 17
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);
        }
Ejemplo n.º 18
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));
        }