public void AvaliableMove_King()
        {
            // 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 testKing = new King (3, 1, false);
            testKing.AvailableMoves ();
            Assert.IsTrue (hasContain (testKing.AvaliableMove_X, testKing.AvaliableMove_Y, 2, 0));
            Assert.IsTrue (hasContain (testKing.AvaliableMove_X, testKing.AvaliableMove_Y, 3, 0));
            Assert.IsTrue (hasContain (testKing.AvaliableMove_X, testKing.AvaliableMove_Y, 4, 0));
            Assert.IsTrue (hasContain (testKing.AvaliableMove_X, testKing.AvaliableMove_Y, 4, 1));
            Assert.IsTrue (hasContain (testKing.AvaliableMove_X, testKing.AvaliableMove_Y, 4, 2));
            Assert.IsTrue (hasContain (testKing.AvaliableMove_X, testKing.AvaliableMove_Y, 3, 2));
            //Assert.IsTrue (hasContain (testKing.AvaliableMove_X, testKing.AvaliableMove_Y, 2, 2));
            Assert.IsTrue (hasContain (testKing.AvaliableMove_X, testKing.AvaliableMove_Y, 2, 1));
            testKing.isDead = true;
            testKing.X = -1;
            testKing.Y = -1;

            Piece testKing2 = new King (0, 3,false);
            testKing2.AvailableMoves ();
            Assert.IsTrue (hasContain (testKing2.AvaliableMove_X, testKing2.AvaliableMove_Y, 0, 2));
            Assert.IsTrue (hasContain (testKing2.AvaliableMove_X, testKing2.AvaliableMove_Y, 1, 2));
            Assert.IsTrue (hasContain (testKing2.AvaliableMove_X, testKing2.AvaliableMove_Y, 1, 3));
            Assert.IsTrue (hasContain (testKing2.AvaliableMove_X, testKing2.AvaliableMove_Y, 1, 4));
            Assert.IsTrue (hasContain (testKing2.AvaliableMove_X, testKing2.AvaliableMove_Y, 0, 4));
        }
        public void Attack_King()
        {
            // 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 testKing = new King (3, 1, 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 = 0;
            testKing.AvailableMoves ();
            testKing.Move (2, 0);
            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 = 3;
            testPawn2.Y = 0;
            testKing.AvailableMoves ();
            testKing.Move (3, 0);
            Assert.AreEqual (false, testPawn2.isDead);
        }
        /// <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 ();
        }