Exemplo n.º 1
0
Arquivo: Game1.cs Projeto: ssylt/Chess
        private void Load()
        {
            bool[] tmp = new bool[64];
            //Kings
            wk = new King(Content.Load <Texture2D>("wk"), wkHitbox, new Vector2(87 * 4, 87 * 7), new Vector2(87 * 4, 87 * 7), true, tmp, tmp, false, 0, tmp);
            bk = new King(Content.Load <Texture2D>("bk"), bkHitbox, new Vector2(87 * 4, 0), new Vector2(87 * 4, 0), false, tmp, tmp, false, 0, tmp);

            //Queens
            wQ  = new Queen(Content.Load <Texture2D>("wq"), wQHitbox, new Vector2(87 * 3, 87 * 7), new Vector2(87 * 3, 87 * 7), true, tmp, tmp, false, 0, tmp);
            bQ  = new Queen(Content.Load <Texture2D>("bq"), bQHitbox, new Vector2(87 * 3, 0), new Vector2(87 * 3, 0), false, tmp, tmp, false, 0, tmp);
            wQ2 = new Queen(Content.Load <Texture2D>("wq"), wQ2Hitbox, new Vector2(87 * 88, 87 * 99), new Vector2(87 * 88, 87 * 99), true, tmp, tmp, false, 0, tmp);
            bQ2 = new Queen(Content.Load <Texture2D>("bq"), bQ2Hitbox, new Vector2(87 * 88, 88), new Vector2(87 * 88, 88), false, tmp, tmp, false, 0, tmp);

            //White rooks
            wR1 = new Rook(Content.Load <Texture2D>("wr"), wR1Hitbox, new Vector2(87 * 0, 87 * 0), new Vector2(87 * 0, 87 * 7), true, tmp, tmp, false, 0, tmp);
            wR2 = new Rook(Content.Load <Texture2D>("wr"), wR2Hitbox, new Vector2(87 * 7, 87 * 0), new Vector2(87 * 7, 87 * 7), true, tmp, tmp, false, 0, tmp);

            //Black rooks
            bR1 = new Rook(Content.Load <Texture2D>("br"), bR1Hitbox, new Vector2(87 * 0, 87 * 0), new Vector2(87 * 0, 87 * 0), false, tmp, tmp, false, 0, tmp);
            bR2 = new Rook(Content.Load <Texture2D>("br"), bR2Hitbox, new Vector2(87 * 7, 87 * 0), new Vector2(87 * 7, 87 * 0), false, tmp, tmp, false, 0, tmp);

            //White Pawns
            wp1 = new WhitePawn(Content.Load <Texture2D>("wp"), wpHitbox1, new Vector2(87 * 0, 87 * 6), new Vector2(87 * 0, 87 * 6), true, tmp, tmp, false, 0, tmp);
            wp2 = new WhitePawn(Content.Load <Texture2D>("wp"), wpHitbox2, new Vector2(87 * 1, 87 * 6), new Vector2(87 * 1, 87 * 6), true, tmp, tmp, false, 0, tmp);
            wp3 = new WhitePawn(Content.Load <Texture2D>("wp"), wpHitbox3, new Vector2(87 * 2, 87 * 6), new Vector2(87 * 2, 87 * 6), true, tmp, tmp, false, 0, tmp);
            wp4 = new WhitePawn(Content.Load <Texture2D>("wp"), wpHitbox4, new Vector2(87 * 3, 87 * 6), new Vector2(87 * 3, 87 * 6), true, tmp, tmp, false, 0, tmp);
            wp5 = new WhitePawn(Content.Load <Texture2D>("wp"), wpHitbox5, new Vector2(87 * 4, 87 * 6), new Vector2(87 * 4, 87 * 6), true, tmp, tmp, false, 0, tmp);
            wp6 = new WhitePawn(Content.Load <Texture2D>("wp"), wpHitbox6, new Vector2(87 * 5, 87 * 6), new Vector2(87 * 5, 87 * 6), true, tmp, tmp, false, 0, tmp);
            wp7 = new WhitePawn(Content.Load <Texture2D>("wp"), wpHitbox7, new Vector2(87 * 6, 87 * 6), new Vector2(87 * 6, 87 * 6), true, tmp, tmp, false, 0, tmp);
            wp8 = new WhitePawn(Content.Load <Texture2D>("wp"), wpHitbox8, new Vector2(87 * 7, 87 * 6), new Vector2(87 * 7, 87 * 6), true, tmp, tmp, false, 0, tmp);

            //Black Pawns
            bp1 = new BlackPawn(Content.Load <Texture2D>("bp"), bpHitbox1, new Vector2(87 * 0, 87 * 1), new Vector2(87 * 0, 87 * 1), false, tmp, tmp, false, 0, tmp);
            bp2 = new BlackPawn(Content.Load <Texture2D>("bp"), bpHitbox2, new Vector2(87 * 1, 87 * 1), new Vector2(87 * 1, 87 * 1), false, tmp, tmp, false, 0, tmp);
            bp3 = new BlackPawn(Content.Load <Texture2D>("bp"), bpHitbox3, new Vector2(87 * 2, 87 * 1), new Vector2(87 * 2, 87 * 1), false, tmp, tmp, false, 0, tmp);
            bp4 = new BlackPawn(Content.Load <Texture2D>("bp"), bpHitbox4, new Vector2(87 * 3, 87 * 1), new Vector2(87 * 3, 87 * 1), false, tmp, tmp, false, 0, tmp);
            bp5 = new BlackPawn(Content.Load <Texture2D>("bp"), bpHitbox5, new Vector2(87 * 4, 87 * 1), new Vector2(87 * 4, 87 * 1), false, tmp, tmp, false, 0, tmp);
            bp6 = new BlackPawn(Content.Load <Texture2D>("bp"), bpHitbox6, new Vector2(87 * 5, 87 * 1), new Vector2(87 * 5, 87 * 1), false, tmp, tmp, false, 0, tmp);
            bp7 = new BlackPawn(Content.Load <Texture2D>("bp"), bpHitbox7, new Vector2(87 * 6, 87 * 1), new Vector2(87 * 6, 87 * 1), false, tmp, tmp, false, 0, tmp);
            bp8 = new BlackPawn(Content.Load <Texture2D>("bp"), bpHitbox8, new Vector2(87 * 7, 87 * 1), new Vector2(87 * 7, 87 * 1), false, tmp, tmp, false, 0, tmp);

            //Bishops
            wB  = new Bishop(Content.Load <Texture2D>("wb"), wBHitbox, new Vector2(87 * 2, 87 * 7), new Vector2(87 * 2, 87 * 7), true, tmp, tmp, false, 0, tmp);
            wB2 = new Bishop(Content.Load <Texture2D>("wb"), wBHitbox2, new Vector2(87 * 5, 87 * 7), new Vector2(87 * 5, 87 * 7), true, tmp, tmp, false, 0, tmp);
            bB  = new Bishop(Content.Load <Texture2D>("bb"), bBHitbox, new Vector2(87 * 2, 87 * 0), new Vector2(87 * 2, 87 * 0), false, tmp, tmp, false, 0, tmp);
            bB2 = new Bishop(Content.Load <Texture2D>("bb"), bBHitbox2, new Vector2(87 * 5, 87 * 0), new Vector2(87 * 5, 87 * 0), false, tmp, tmp, false, 0, tmp);

            //Knights (Horses)
            wh  = new Knight(Content.Load <Texture2D>("wh"), whHitbox, new Vector2(87 * 1, 87 * 7), new Vector2(87 * 1, 87 * 7), true, tmp, tmp, false, 0, tmp);
            wh2 = new Knight(Content.Load <Texture2D>("wh"), whHitbox2, new Vector2(87 * 6, 87 * 7), new Vector2(87 * 6, 87 * 7), true, tmp, tmp, false, 0, tmp);
            bh  = new Knight(Content.Load <Texture2D>("bh"), bhHitbox, new Vector2(87 * 1, 87 * 0), new Vector2(87 * 1, 87 * 0), false, tmp, tmp, false, 0, tmp);
            bh2 = new Knight(Content.Load <Texture2D>("bh"), bhHitbox2, new Vector2(87 * 6, 87 * 0), new Vector2(87 * 6, 87 * 0), false, tmp, tmp, false, 0, tmp);

            //-----------------------------------------------------------------

            //Queens add
            activePiece.Add(wQ);
            activePiece.Add(bQ);

            //White Pawns add
            activePiece.Add(wp1);
            activePiece.Add(wp2);
            activePiece.Add(wp3);
            activePiece.Add(wp4);
            activePiece.Add(wp5);
            activePiece.Add(wp6);
            activePiece.Add(wp7);
            activePiece.Add(wp8);

            //Black Pawns add
            activePiece.Add(bp1);
            activePiece.Add(bp2);
            activePiece.Add(bp3);
            activePiece.Add(bp4);
            activePiece.Add(bp5);
            activePiece.Add(bp6);
            activePiece.Add(bp7);
            activePiece.Add(bp8);

            //Bishops add
            activePiece.Add(wB2);
            activePiece.Add(wB);
            activePiece.Add(bB);
            activePiece.Add(bB2);

            //Rooks add
            activePiece.Add(wR1);
            activePiece.Add(wR2);
            activePiece.Add(bR1);
            activePiece.Add(bR2);

            //Knights add
            activePiece.Add(wh);
            activePiece.Add(wh2);
            activePiece.Add(bh);
            activePiece.Add(bh2);

            //Kings add
            activePiece.Add(wk);
            activePiece.Add(bk);


            //Load img -----------------------------------------------------------------
            wb           = Content.Load <Texture2D>("wb");
            red          = Content.Load <Texture2D>("red");
            wH           = Content.Load <Texture2D>("wh");
            wkImg        = Content.Load <Texture2D>("wk");
            wpImg        = Content.Load <Texture2D>("wp");
            wr           = Content.Load <Texture2D>("wr");
            bkImg        = Content.Load <Texture2D>("bk");
            menyBak      = Content.Load <Texture2D>("menyBak");
            playKnapp    = Content.Load <Texture2D>("Play");
            arial        = Content.Load <SpriteFont>("arial");
            settings     = Content.Load <Texture2D>("settings");
            debug        = Content.Load <Texture2D>("debugging");
            back         = Content.Load <Texture2D>("back");
            exit         = Content.Load <Texture2D>("exit");
            disableDebug = Content.Load <Texture2D>("disableDebugging");
            whitewins    = Content.Load <Texture2D>("whitewins");
            blackwins    = Content.Load <Texture2D>("blackwins");
            placingPiece = Content.Load <SoundEffect>("chessmove");
            newGame      = Content.Load <Texture2D>("newgame");
            chessGray    = Content.Load <Texture2D>("chessgray");
            //isWho -----------------------------------------------------------------
            isWho[0] = bR1;
            isWho[1] = bh;
            isWho[2] = bB;
            isWho[3] = bQ;
            isWho[4] = bk;
            isWho[5] = bB2;
            isWho[6] = bh2;
            isWho[7] = bR2;

            isWho[8]  = bp1;
            isWho[9]  = bp2;
            isWho[10] = bp3;
            isWho[11] = bp4;
            isWho[12] = bp5;
            isWho[13] = bp6;
            isWho[14] = bp7;
            isWho[15] = bp8;

            isWho[48] = wp1;
            isWho[49] = wp2;
            isWho[50] = wp3;
            isWho[51] = wp4;
            isWho[52] = wp5;
            isWho[53] = wp6;
            isWho[54] = wp7;
            isWho[55] = wp8;

            isWho[56] = wR1;
            isWho[57] = wh;
            isWho[58] = wB;
            isWho[59] = wQ;
            isWho[60] = wk;
            isWho[61] = wB2;
            isWho[62] = wh2;
            isWho[63] = wR2;
        }
Exemplo n.º 2
0
        public List <int> SimulateRound(Piece ap)
        {
            List <int>  returnMoves = new List <int>();
            Piece       apCopy      = ap;
            int         currPos     = getPos(apCopy);
            Queue <int> q           = new Queue <int>();

            for (int i = 0; i < apCopy.am.Length; i++)
            {
                if (apCopy.am[i])
                {
                    q.Enqueue(i);
                }
            }
            Game1.debugger.Add(q.Count.ToString());
            while (q.Count > 0)
            {
                int i = q.Dequeue();
                if (ap is Queen)
                {
                    apCopy = new Queen(ap);
                }
                else if (ap is King)
                {
                    apCopy = new King(ap);
                }
                else if (ap is Rook)
                {
                    apCopy = new Rook(ap);
                }
                else if (ap is Bishop)
                {
                    apCopy = new Bishop(ap);
                }
                else if (ap is BlackPawn)
                {
                    apCopy = new BlackPawn(ap);
                }
                else if (ap is WhitePawn)
                {
                    apCopy = new WhitePawn(ap);
                }
                else if (ap is Knight)
                {
                    apCopy = new Knight(ap);
                }
                King wkTemp = new King(Game1.wk);
                King bkTemp = new King(Game1.bk);

                //Queens
                Queen wQTemp = new Queen(Game1.wQ);
                Queen bQTemp = new Queen(Game1.bQ);

                //White rooks
                Rook wR1Temp = new Rook(Game1.wR1);
                Rook wR2Temp = new Rook(Game1.wR2);

                //Black rooks
                Rook bR1Temp = new Rook(Game1.bR1);
                Rook bR2Temp = new Rook(Game1.bR2);

                //White Pawns
                WhitePawn wp1Temp = new WhitePawn(Game1.wp1);
                WhitePawn wp2Temp = new WhitePawn(Game1.wp2);
                WhitePawn wp3Temp = new WhitePawn(Game1.wp3);
                WhitePawn wp4Temp = new WhitePawn(Game1.wp4);
                WhitePawn wp5Temp = new WhitePawn(Game1.wp5);
                WhitePawn wp6Temp = new WhitePawn(Game1.wp6);
                WhitePawn wp7Temp = new WhitePawn(Game1.wp7);
                WhitePawn wp8Temp = new WhitePawn(Game1.wp8);

                //Black Pawns
                BlackPawn bp1Temp = new BlackPawn(Game1.bp1);
                BlackPawn bp2Temp = new BlackPawn(Game1.bp2);
                BlackPawn bp3Temp = new BlackPawn(Game1.bp3);
                BlackPawn bp4Temp = new BlackPawn(Game1.bp4);
                BlackPawn bp5Temp = new BlackPawn(Game1.bp5);
                BlackPawn bp6Temp = new BlackPawn(Game1.bp6);
                BlackPawn bp7Temp = new BlackPawn(Game1.bp7);
                BlackPawn bp8Temp = new BlackPawn(Game1.bp8);

                //Bishops
                Bishop wBTemp  = new Bishop(Game1.wB);
                Bishop wB2Temp = new Bishop(Game1.wB2);
                Bishop bBTemp  = new Bishop(Game1.bB);
                Bishop bB2Temp = new Bishop(Game1.bB2);

                //Knights (Horses)
                Knight whTemp  = new Knight(Game1.wh);
                Knight wh2Temp = new Knight(Game1.wh2);
                Knight bhTemp  = new Knight(Game1.bh);
                Knight bh2Temp = new Knight(Game1.bh2);

                tmpList.Clear();
                //Queens add
                tmpList.Add(wQTemp);
                tmpList.Add(bQTemp);

                //White Pawns add
                tmpList.Add(wp1Temp);
                tmpList.Add(wp2Temp);
                tmpList.Add(wp3Temp);
                tmpList.Add(wp4Temp);
                tmpList.Add(wp5Temp);
                tmpList.Add(wp6Temp);
                tmpList.Add(wp7Temp);
                tmpList.Add(wp8Temp);

                //Black Pawns add
                tmpList.Add(bp1Temp);
                tmpList.Add(bp2Temp);
                tmpList.Add(bp3Temp);
                tmpList.Add(bp4Temp);
                tmpList.Add(bp5Temp);
                tmpList.Add(bp6Temp);
                tmpList.Add(bp7Temp);
                tmpList.Add(bp8Temp);

                //Bishops add
                tmpList.Add(wB2Temp);
                tmpList.Add(wBTemp);
                tmpList.Add(bBTemp);
                tmpList.Add(bB2Temp);

                //Rooks add
                tmpList.Add(wR1Temp);
                tmpList.Add(wR2Temp);
                tmpList.Add(bR1Temp);
                tmpList.Add(bR2Temp);

                //Knights add
                tmpList.Add(whTemp);
                tmpList.Add(wh2Temp);
                tmpList.Add(bhTemp);
                tmpList.Add(bh2Temp);

                //Kings add
                tmpList.Add(wkTemp);
                tmpList.Add(bkTemp);

                if (!isTakenTemp[i])
                {
                    isTakenTemp[i]       = true;
                    isTakenTemp[currPos] = false;
                    apCopy.rectangle.X   = Game1.boardList[i].X;
                    apCopy.rectangle.Y   = Game1.boardList[i].Y;
                    apCopy.tempPos.X     = apCopy.rectangle.X;
                    apCopy.tempPos.Y     = apCopy.rectangle.Y;
                    isWhoTemp[i]         = apCopy;
                    isWhoTemp[currPos]   = null;
                }
                else if (isTakenTemp[i] && isWhoTemp[i].isWhite != apCopy.isWhite)
                {
                    Seize(isWhoTemp[i]);
                    isWhoTemp[i].isDead = true;
                    for (int j = 0; j < tmpList.Count; j++)
                    {
                        if (getPos(tmpList[j]) == i)
                        {
                            Seize(tmpList[j]);
                        }
                    }
                    Game1.debugger.Add("Seizing " + isWhoTemp[i].toString());
                    isTakenTemp[i]       = true;
                    isTakenTemp[currPos] = false;
                    apCopy.rectangle.X   = Game1.boardList[i].X;
                    apCopy.rectangle.Y   = Game1.boardList[i].Y;
                    apCopy.tempPos.X     = apCopy.rectangle.X;
                    apCopy.tempPos.Y     = apCopy.rectangle.Y;
                    isWhoTemp[i]         = apCopy;
                    isWhoTemp[currPos]   = null;
                }
                for (int j = 0; j < tmpList.Count; j++)
                {
                    tmpList[j].SimulateAllowedMoves(getPos(tmpList[j]), isWhoTemp, isTakenTemp, tmpList);
                }
                Piece king = apCopy;
                if (apCopy.isWhite)
                {
                    king = tmpList[30];
                }
                else if (!apCopy.isWhite)
                {
                    king = tmpList[31];
                }
                Game1.debugger.Add(king.toString() + " IsWhite = " + king.isWhite + " Pos " + getPos(king));
                Game1.debugger.Add(getPos(apCopy).ToString());
                Game1.debugger.Add(isTakenTemp[currPos].ToString());
                int tmp = 0;
                for (int j = 0; j < tmpList.Count; j++)
                {
                    if (tmpList[j].isWhite != king.isWhite && !tmpList[j].isDead)
                    {
                        for (int k = 0; k < tmpList[j].am.Length; k++)
                        {
                            if (tmpList[j].am[k] && k == getPos(king))
                            {
                                tmp++;
                                Game1.debugger.Add(tmpList[j].toString());
                                break;
                            }
                        }
                    }
                }
                Game1.debugger.Add("Tmp " + tmp.ToString());
                if (tmp == 0)
                {
                    returnMoves.Add(i);
                }
                Copyer(isWhoTemp, isTakenTemp);
            }
            return(returnMoves);
        }