public void Attack_Knight()
        {
            // 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 testKnight = new Knight (3, 5, 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 = 2;
            testPawn.Y = 3;
            testKnight.AvailableMoves ();
            testKnight.Move (2, 3);
            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 = 5;
            testKnight.AvailableMoves ();
            testKnight.Move (1, 5);
            Assert.AreEqual (false, testPawn2.isDead);
        }
        public void AvaliableMove_Knight()
        {
            // 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 testKnight = new Knight (1, 2, true);
            testKnight.AvailableMoves ();
            Assert.IsTrue (hasContain (testKnight.AvaliableMove_X, testKnight.AvaliableMove_Y, 0, 0));
            Assert.IsTrue (hasContain (testKnight.AvaliableMove_X, testKnight.AvaliableMove_Y, 2, 0));
            Assert.IsTrue (hasContain (testKnight.AvaliableMove_X, testKnight.AvaliableMove_Y, 3, 1));
            Assert.IsTrue (hasContain (testKnight.AvaliableMove_X, testKnight.AvaliableMove_Y, 3, 3));
            Assert.IsTrue (hasContain (testKnight.AvaliableMove_X, testKnight.AvaliableMove_Y, 2, 4));
            Assert.IsTrue (hasContain (testKnight.AvaliableMove_X, testKnight.AvaliableMove_Y, 0, 4));

            Piece testKnight2 = new Knight (3, 5, false);
            testKnight2.AvailableMoves ();
            Assert.IsTrue (hasContain (testKnight2.AvaliableMove_X, testKnight2.AvaliableMove_Y, 2, 3));
            Assert.IsTrue (hasContain (testKnight2.AvaliableMove_X, testKnight2.AvaliableMove_Y, 4, 3));
            Assert.IsTrue (hasContain (testKnight2.AvaliableMove_X, testKnight2.AvaliableMove_Y, 5, 4));
            Assert.IsTrue (hasContain (testKnight2.AvaliableMove_X, testKnight2.AvaliableMove_Y, 5, 6));
            Assert.IsTrue (hasContain (testKnight2.AvaliableMove_X, testKnight2.AvaliableMove_Y, 4, 7));
            Assert.IsTrue (hasContain (testKnight2.AvaliableMove_X, testKnight2.AvaliableMove_Y, 2, 7));
            Assert.IsTrue (hasContain (testKnight2.AvaliableMove_X, testKnight2.AvaliableMove_Y, 1, 6));
            Assert.IsTrue (hasContain (testKnight2.AvaliableMove_X, testKnight2.AvaliableMove_Y, 1, 4));
        }
        /// <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 ();
        }