コード例 #1
0
        public void Attack_Bishop()
        {
            // setup environment for test
            GameController.StartGame ();
            List<Piece> PL1 = GameController.Players [0].PieceList;
            List<Piece> PL2 = GameController.Players [1].PieceList;
            for (int i = 0; i < PL1.Count; i++)
            {
                PL1 [i].isDead = true;
                PL1 [i].X = -1;
                PL1 [i].Y = -1;
                PL2 [i].isDead = true;
                PL2 [i].X = -1;
                PL2 [i].Y = -1;
            }
            UtilityFunctions.CheckAvaiMoveOfAllPieces ();

            //test piece
            Piece testBishop = new Bishop (2, 3, true);
            Piece testPawn = null;
            Piece testPawn2 = null;

            //get a pwan from write player for test attack
            foreach (Piece p in PL1)
            {
                if (p.type == PieceType.Pawn)
                {
                    testPawn = p;
                    break;
                }
            }
            testPawn.isDead = false;
            testPawn.X = 0;
            testPawn.Y = 1;
            testBishop.AvailableMoves ();
            testBishop.Move (0, 1);
            Assert.AreEqual (true, testPawn.isDead);

            //get a pwan from black player for test attack
            foreach (Piece p in PL2)
            {
                if (p.type == PieceType.Pawn)
                {
                    testPawn2 = p;
                    break;
                }
            }
            testPawn2.isDead = false;
            testPawn2.X = 1;
            testPawn2.Y = 0;
            testBishop.AvailableMoves ();
            testBishop.Move (1, 0);
            Assert.AreEqual (false, testPawn2.isDead);
        }
コード例 #2
0
        public void TestBishopMoveWithRestriction()
        {
            Player [] _player = new Player [2];
            _player [0] = new Player("Player");
            _player [1] = new Player("AI");

            Cell   firstCell        = new Cell(Color.Black, 140, 140);
            Cell   invalidCell      = new Cell(Color.White, 50, 50);
            Cell   validCell        = new Cell(Color.White, 0, 0);
            Cell   anotherValidCell = new Cell(Color.White, 350, 350);
            Bishop someBishop       = new Bishop(Color.Black, firstCell);

            Assert.IsFalse(someBishop.MoveRestriction(invalidCell, _player));
            Assert.IsTrue(someBishop.MoveRestriction(validCell, _player));
            Assert.IsTrue(someBishop.MoveRestriction(anotherValidCell, _player));
        }
コード例 #3
0
        public void TestCreateAllPieces()
        {
            Cell   someCell   = new Cell(Color.Black, 0, 0);
            Pawn   somePawn   = new Pawn(Color.Black, someCell);
            King   someKing   = new King(Color.Black, someCell);
            Queen  someQueen  = new Queen(Color.Black, someCell);
            Rook   someRook   = new Rook(Color.Black, someCell);
            Knight someKnight = new Knight(Color.Black, someCell);
            Bishop someBishop = new Bishop(Color.Black, someCell);

            Assert.IsInstanceOf <Pawn> (somePawn);
            Assert.IsInstanceOf <King> (someKing);
            Assert.IsInstanceOf <Queen> (someQueen);
            Assert.IsInstanceOf <Rook> (someRook);
            Assert.IsInstanceOf <Knight> (someKnight);
            Assert.IsInstanceOf <Bishop> (someBishop);
        }
コード例 #4
0
        public void AvaliableMove_Bishop()
        {
            // setup environment for test
            GameController.StartGame ();
            List<Piece> PL1 = GameController.Players [0].PieceList;
            List<Piece> PL2 = GameController.Players [1].PieceList;
            for (int i = 0; i < PL1.Count; i++)
            {
                PL1 [i].isDead = true;
                PL1 [i].X = -1;
                PL1 [i].Y = -1;
                PL2 [i].isDead = true;
                PL2 [i].X = -1;
                PL2 [i].Y = -1;
            }
            UtilityFunctions.CheckAvaiMoveOfAllPieces ();

            //test piece
            Piece testBishop = new Bishop (2, 3, true);
            testBishop.AvailableMoves ();
            Assert.IsTrue (hasContain (testBishop.AvaliableMove_X, testBishop.AvaliableMove_Y, 0, 1));
            Assert.IsTrue (hasContain (testBishop.AvaliableMove_X, testBishop.AvaliableMove_Y, 1, 2));
            Assert.IsTrue (hasContain (testBishop.AvaliableMove_X, testBishop.AvaliableMove_Y, 3, 4));
            Assert.IsTrue (hasContain (testBishop.AvaliableMove_X, testBishop.AvaliableMove_Y, 4, 5));
            Assert.IsTrue (hasContain (testBishop.AvaliableMove_X, testBishop.AvaliableMove_Y, 4, 1));
            Assert.IsTrue (hasContain (testBishop.AvaliableMove_X, testBishop.AvaliableMove_Y, 3, 2));
            Assert.IsTrue (hasContain (testBishop.AvaliableMove_X, testBishop.AvaliableMove_Y, 1, 4));
            Assert.IsTrue (hasContain (testBishop.AvaliableMove_X, testBishop.AvaliableMove_Y, 0, 5));

            Piece testBishop2 = new Bishop (1, 4, false);
            testBishop2.AvailableMoves ();
            Assert.IsTrue (hasContain (testBishop2.AvaliableMove_X, testBishop2.AvaliableMove_Y, 0, 3));
            Assert.IsTrue (hasContain (testBishop2.AvaliableMove_X, testBishop2.AvaliableMove_Y, 0, 5));
            Assert.IsTrue (hasContain (testBishop2.AvaliableMove_X, testBishop2.AvaliableMove_Y, 2, 3));
            Assert.IsTrue (hasContain (testBishop2.AvaliableMove_X, testBishop2.AvaliableMove_Y, 3, 2));
            Assert.IsTrue (hasContain (testBishop2.AvaliableMove_X, testBishop2.AvaliableMove_Y, 4, 1));
            Assert.IsTrue (hasContain (testBishop2.AvaliableMove_X, testBishop2.AvaliableMove_Y, 5, 0));
            Assert.IsTrue (hasContain (testBishop2.AvaliableMove_X, testBishop2.AvaliableMove_Y, 2, 5));
            Assert.IsTrue (hasContain (testBishop2.AvaliableMove_X, testBishop2.AvaliableMove_Y, 3, 6));
            Assert.IsTrue (hasContain (testBishop2.AvaliableMove_X, testBishop2.AvaliableMove_Y, 4, 7));
        }
コード例 #5
0
        /// <summary>
        /// Loads the game.
        /// </summary>
        public static void LoadGame()
        {
            string filename = SwinGame.PathToResource ("records.txt");
            string[,] img = {{"Pawn_W","Rock_W","Knight_W","Bishop_W","Queen_W","King_W"},{"Pawn_B","Rock_B","Knight_B","Bishop_B","Queen_B","King_B"}};
            StreamReader sr = new StreamReader (filename);
            _players.Clear ();
            _deadPieceW.Clear ();
            _deadPieceB.Clear ();
            _players.Add (new Player ("", false));
            _players.Add (new Player ("", true));
            _players [0].PieceList.Clear ();
            _players [1].PieceList.Clear ();
            Result = 3;
            //Read names
            _players[0].name = sr.ReadLine();
            _players [1].name = sr.ReadLine ();
            // Modify Pieces Location
            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 16; j++)
                {
                    string carry = "";
                    carry = sr.ReadLine ();
                    Piece p = null;
                    switch (carry [0])
                    {
                    case 'P':
                        p = new Pawn (PieceType.Pawn);
                        p.Image = img [i, 0];
                        break;
                    case 'Q':
                        p = new Queen (PieceType.Queen);
                        p.Image = img [i, 4];
                        break;
                    case 'R':
                        p = new Rock (PieceType.Rock);
                        p.Image = img [i, 1];
                        break;
                    case 'K':
                        p = new King (PieceType.King);
                        p.Image = img [i, 5];
                        break;
                    case 'N':
                        p = new Knight (PieceType.Knight);
                        p.Image = img [i, 2];
                        break;
                    case 'B':
                        p = new Bishop (PieceType.Bishop);
                        p.Image = img [i, 3];
                        break;
                    }

                    p.IsBlack = (i == 1);
                    p.HasBeenMoved = false;
                    if (carry [1] == 'M')
                    {
                        p.HasBeenMoved = true;
                    }
                    if (carry [2] == 'L')
                    {
                        p.isDead = false;
                    }
                    else
                    {
                        p.isDead = true;
                        if (!p.IsBlack)
                        {
                            _deadPieceW.Add (p);
                        }
                        else
                        {
                            _deadPieceB.Add (p);
                        }
                    }
                    if (carry [3] == '-')
                    {
                        p.X = (-1) * (Convert.ToInt32 (carry [4]) - 48);
                        if (carry [5] == '-')
                        {
                            p.Y = (-1) * (Convert.ToInt32 (carry [6]) - 48);
                        }
                        else
                        {
                            p.Y = (Convert.ToInt32 (carry [5]) - 48);
                        }
                    }
                    else
                    {
                        p.X = Convert.ToInt32 (carry [3]) - 48;
                        if (carry [4] == '-')
                        {
                            p.Y = (-1) * (Convert.ToInt32 (carry [5]) - 48);
                        }
                        else
                        {
                            p.Y = (Convert.ToInt32 (carry [4]) - 48);
                        }
                    }
                    GameController.Players [i].PieceList.Add (p);
                }
            }
            SelectedPiece = null;
            string curr = sr.ReadLine();
            int current = Convert.ToInt32 (curr[0]) - 48;
            CurrentPlayerIndex = current;
            CurrentPlayer = Players [current];
            UtilityFunctions.CheckAvaiMoveOfAllPieces ();
            curr = sr.ReadLine ();
            if (curr == "CHECKING")
            {
                GameController.Checking = true;
                if (!MainGameController.CanPreventAttack ())
                {
                    GameController.Result = Math.Abs (GameController.CurrentPlayerIndex - 1);
                    GameController.EndCurrentState (); //Need to be changed later
                }
            }else
            {
                Checking = false;
            }
            AddState (GameState.MainGame);
            sr.Close ();
        }