Exemple #1
0
        public void OnPaint(PaintEventArgs e)
        {
            Graphics   et    = e.Graphics;
            ValidMoves k     = new ValidMoves(Ostanati[idx1], idx1, Zafateni, Enpassant);
            Brush      pinkt = new SolidBrush(Color.FromArgb(255, 182, 193));

            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    {
                        if (k.Valid[i][j])
                        {
                            et.FillRectangle(pinkt, i * 50, j * 50, 50, 50);
                        }
                    }
                }
            }
        }
Exemple #2
0
        public void DrawIt()
        {
            Graphics   et    = this.CreateGraphics();
            ValidMoves k     = new ValidMoves(Ostanati[kliknato], kliknato, matrica, Enpassant);
            Brush      pinkt = new SolidBrush(Color.FromArgb(255, 182, 193));


            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    {
                        if (k.Valid[i][j])
                        {
                            if (i % 2 == 0 && j % 2 == 0 || i % 2 == 1 && j % 2 == 1)
                            {
                                et.DrawRectangle(new Pen(new SolidBrush(Color.BlanchedAlmond), 3), j * 50 + 2, i * 50 + 2, 44, 44);
                            }
                            if (i % 2 == 1 && j % 2 == 0 || i % 2 == 0 && j % 2 == 1)
                            {
                                et.DrawRectangle(new Pen(new SolidBrush(Color.Brown), 3), j * 50 + 2, i * 50 + 2, 44, 44);
                            }
                        }
                        else
                        {
                            if (i % 2 == 0 && j % 2 == 0 || i % 2 == 1 && j % 2 == 1)
                            {
                                et.DrawRectangle(new Pen(new SolidBrush(Color.Brown), 3), j * 50 + 2, i * 50 + 2, 44, 44);
                            }
                            if (i % 2 == 1 && j % 2 == 0 || i % 2 == 0 && j % 2 == 1)
                            {
                                et.DrawRectangle(new Pen(new SolidBrush(Color.FromArgb(238, 221, 187)), 3), j * 50 + 2, i * 50 + 2, 44, 44);
                            }
                        }
                    }
                }
            }
            if (Ostanati[k.index].t != DifFigures.tip.None)
            {
                et.DrawRectangle(new Pen(new SolidBrush(Color.Black), 3), k.index % 8 * 50 + 2, k.index / 8 * 50 + 2, 44, 44);
            }
        }
Exemple #3
0
 public bool Value()
 {
     // Провери за секое валидно место на коешто можам да го движам кралот, дали некоја фигура од спротивниот тим има пристап
     if (!White)
     {
         for (int i = 0; i < 64; i++)
         {
             if (OstanatiFiguri[i].White && OstanatiFiguri[i].t != DifFigures.tip.None)
             {
                 ValidMoves k = new ValidMoves(OstanatiFiguri[i], i, Zafateni, Enpassant);
                 if (k.Valid[idx / 8][idx % 8])
                 {
                     MessageBox.Show("Вашиот крал е оставен под директен напад од " + OstanatiFiguri[i].t + " на таа позиција");
                     return(true);
                 }
             }
         }
         return(false);
     }
     else
     {
         for (int i = 0; i < 64; i++)
         {
             if (!OstanatiFiguri[i].White && OstanatiFiguri[i].t != DifFigures.tip.None)
             {
                 ValidMoves k = new ValidMoves(OstanatiFiguri[i], i, Zafateni, Enpassant);
                 if (k.Valid[idx / 8][idx % 8])
                 {
                     MessageBox.Show("Вашиот крал е оставен под директен напад од " + OstanatiFiguri[i].t + " на таа позиција");
                     return(true);
                 }
             }
         }
         return(false);
     }
 }
Exemple #4
0
        void figureHandlers(object sender, EventArgs e)
        {
            PictureBox ptt = (PictureBox)sender;
            ValidMoves k   = new ValidMoves(Ostanati[kliknato], kliknato, matrica, Enpassant);

            if (PlayerTurn[3])
            {
                kliknato2 = Array.IndexOf(figures, ptt);
                if (kliknato2 == -1)
                {
                    // Ако кликнеш надвор од шахот
                    kliknato2     = 0;
                    PlayerTurn[2] = true;
                    PlayerTurn[3] = false;
                }
                else if (k.Zafateni.Whitte[kliknato2 / 8][kliknato2 % 8] == false)
                {
                    // Ако се премислиш која фигура да ја поместиш
                    PlayerTurn[2] = true;
                }
                if ((kliknato2 / 8 == 3 && Dva[0] / 8 == 1 && matrica.ZafateniMesta[Dva[0] / 8][Dva[0] % 8] && Ostanati[Dva[0]].t == DifFigures.tip.Pawn))
                {
                    // Валидирање за enpassant move
                    Enpassant[1][Dva[0] % 8] = true;
                    for (int i = 0; i < 8; i++)
                    {
                        if (Enpassant[1][i] && i != Dva[0] % 8)
                        {
                            Enpassant[1][i] = false;
                            // Сите останати enpassant се false
                        }
                    }
                }

                // Рокада за црн лев топ && крал
                if (Castling[4] && Castling[5] && (Castling[6] || Castling[7]))
                {
                    if (((kliknato2 == 0 && Dva[0] == 4) || (kliknato2 == 4 && Dva[0] == 0)) && Castling[6])
                    {
                        Castling t = new Castling(matrica, false, true);
                        if (t.ValidirajCastle())
                        {
                            figures[Dva[0]].Image    = null;
                            figures[2].Image         = Properties.Resources.Piece4;
                            figures[2].SizeMode      = PictureBoxSizeMode.StretchImage;
                            figures[3].Image         = Properties.Resources.Piece0;
                            figures[3].SizeMode      = PictureBoxSizeMode.StretchImage;
                            figures[kliknato2].Image = null;

                            for (int i = 5; i < 8; i++)
                            {
                                Castling[i] = false;
                            }
                            FinishedPlayer = false;
                            PlayerTurn[3]  = false;
                            PlayerTurn[0]  = true;
                            this.SpecialDraw();
                            DifFigures pomosna  = Ostanati[Dva[0]];
                            DifFigures pomosna2 = Ostanati[kliknato2];

                            Ostanati[3].t = DifFigures.tip.Rook;
                            Ostanati[2].t = DifFigures.tip.King;
                            Ostanati[0].t = DifFigures.tip.None;
                            Ostanati[4].t = DifFigures.tip.None;
                            matrica.ZafateniMesta[0][2] = true;
                            matrica.ZafateniMesta[0][3] = true;
                            matrica.ZafateniMesta[0][0] = false;
                            matrica.ZafateniMesta[0][4] = false;
                            matrica.Whitte[0][2]        = false;
                            matrica.Whitte[0][3]        = false;
                            Ostanati[2].White           = false;
                            Ostanati[3].White           = false;

                            label1.Text = "White's Turn";
                        }
                    }
                    // Рокада за крал и десен црн топ
                    else if (((kliknato2 == 4 && Dva[0] == 7) || (kliknato2 == 7 && Dva[0] == 4)) && Castling[7])
                    {
                        Castling t = new Castling(matrica, false, false);

                        if (t.ValidirajCastle())
                        {
                            figures[Dva[0]].Image    = null;
                            figures[5].Image         = Properties.Resources.Piece0;
                            figures[5].SizeMode      = PictureBoxSizeMode.StretchImage;
                            figures[6].Image         = Properties.Resources.Piece4;
                            figures[6].SizeMode      = PictureBoxSizeMode.StretchImage;
                            figures[kliknato2].Image = null;

                            for (int i = 5; i < 8; i++)
                            {
                                Castling[i] = false;
                            }

                            FinishedPlayer = false;
                            PlayerTurn[3]  = false;
                            PlayerTurn[0]  = true;
                            // Да ги отселектира валидните потези
                            this.SpecialDraw();
                            DifFigures pomosna  = Ostanati[Dva[0]];
                            DifFigures pomosna2 = Ostanati[kliknato2];

                            Ostanati[5].t = DifFigures.tip.Rook;
                            Ostanati[6].t = DifFigures.tip.King;
                            Ostanati[7].t = DifFigures.tip.None;
                            Ostanati[4].t = DifFigures.tip.None;
                            matrica.ZafateniMesta[0][5] = true;
                            matrica.ZafateniMesta[0][6] = true;
                            matrica.ZafateniMesta[0][4] = false;
                            matrica.ZafateniMesta[0][7] = false;
                            matrica.Whitte[0][5]        = false;
                            matrica.Whitte[0][6]        = false;
                            Ostanati[5].White           = false;
                            Ostanati[6].White           = false;

                            label1.Text = "White's Turn";
                        }
                    }
                }
                // Проверка дали спротивниот крал е во Шах позиција
                if (k.figura.t == DifFigures.tip.King)
                {
                    matrica.ZafateniMesta[Dva[0] / 8][Dva[0] % 8]       = false;
                    matrica.ZafateniMesta[kliknato2 / 8][kliknato2 % 8] = true;
                    matrica.Whitte[kliknato2 / 8][kliknato2 % 8]        = false;
                    SahMat t = new SahMat(kliknato2, Ostanati, matrica, false);
                    if (t.Value())
                    {
                        k.Valid[kliknato2 / 8][kliknato2 % 8] = false;
                    }

                    matrica.ZafateniMesta[kliknato2 / 8][kliknato2 % 8] = false;
                }

                // Менување pictureboxes и зачувани фигури во array листата
                if (k.Valid[kliknato2 / 8][kliknato2 % 8])
                {
                    figures[kliknato2].Image    = Pom1.Image;
                    figures[kliknato2].SizeMode = PictureBoxSizeMode.StretchImage;
                    figures[Dva[0]].Image       = null;
                    bool         GoIma    = false;
                    int          indGoIma = 0;
                    TakenFigures pomosna  = new TakenFigures();
                    // Додавање во листа, доколку е земена фигура
                    if (Ostanati[kliknato2].t != DifFigures.tip.None)
                    {
                        TakenFigures l = new TakenFigures();
                        foreach (TakenFigures p in listBox2.Items)
                        {
                            pomosna = (TakenFigures)p;
                            if (pomosna.v.Equals(Ostanati[kliknato2].t))
                            {
                                GoIma    = true;
                                indGoIma = listBox2.Items.IndexOf(p);
                                l        = p;
                            }
                        }


                        if (GoIma)
                        {
                            listBox2.Items.Remove(l);
                            l.taken++;
                            listBox2.Items.Add(l);
                        }

                        if (!GoIma)
                        {
                            WhiteTaken.Add(Ostanati[kliknato2].t);
                            if (Ostanati[kliknato2].t == DifFigures.tip.Pawn)
                            {
                                listBox2.Items.Add(new TakenFigures(DifFigures.tip.Pawn, 1));
                            }
                            else if (Ostanati[kliknato2].t == DifFigures.tip.Knight)
                            {
                                listBox2.Items.Add(new TakenFigures(DifFigures.tip.Knight, 1));
                            }
                            else if (Ostanati[kliknato2].t == DifFigures.tip.Bishop)
                            {
                                listBox2.Items.Add(new TakenFigures(DifFigures.tip.Bishop, 1));
                            }
                            else if (Ostanati[kliknato2].t == DifFigures.tip.Rook)
                            {
                                listBox2.Items.Add(new TakenFigures(DifFigures.tip.Rook, 1));
                            }
                            else if (Ostanati[kliknato2].t == DifFigures.tip.Queen)
                            {
                                listBox2.Items.Add(new TakenFigures(DifFigures.tip.Queen, 1));
                            }
                            else if (Ostanati[kliknato2].t == DifFigures.tip.King)
                            {
                                listBox2.Items.Add(new TakenFigures(DifFigures.tip.King, 1));
                            }
                        }
                    }

                    // Ако сум го поместил кралот, или некој од топовите, оневозможување на рокада
                    if (FinishedPlayer)
                    {
                        if (Dva[0] == 4)
                        {
                            Castling[5] = false;
                        }
                        if (Dva[0] == 0)
                        {
                            Castling[6] = false;
                        }
                        if (Dva[0] == 7)
                        {
                            Castling[7] = false;
                        }
                        bool enpa = false;

                        // За enpassante дали е валиден
                        if ((Dva[0] % 8 != kliknato2 % 8 && Dva[0] / 8 == 4 && kliknato2 / 8 == 5 && Ostanati[kliknato2].t == DifFigures.tip.None && Ostanati[Dva[0]].t == DifFigures.tip.Pawn && Ostanati[kliknato2 - 8].t == DifFigures.tip.Pawn))
                        {
                            Ostanati[kliknato2 - 8].t = DifFigures.tip.None;
                            Ostanati[kliknato2].t     = DifFigures.tip.Pawn;
                            Ostanati[Dva[0]].t        = DifFigures.tip.None;
                            if (ShowValid)
                            {
                                this.DrawIt();
                            }

                            matrica.ZafateniMesta[kliknato2 / 8 - 1][kliknato2 % 8] = false;
                            matrica.ZafateniMesta[kliknato2 / 8][kliknato2 % 8]     = true;
                            matrica.ZafateniMesta[Dva[0] / 8][Dva[0] % 8]           = false;
                            Ostanati[kliknato2].White    = false;
                            figures[kliknato2 - 8].Image = null;
                            enpa           = true;
                            PlayerTurn[3]  = false;
                            PlayerTurn[0]  = true;
                            FinishedPlayer = false;
                            bool goIma = false;

                            TakenFigures t = new TakenFigures();
                            foreach (TakenFigures p in listBox2.Items)
                            {
                                if (p.v.Equals(DifFigures.tip.Pawn))
                                {
                                    goIma = true;
                                    t     = p;
                                }
                            }
                            if (goIma)
                            {
                                listBox2.Items.Remove(t);
                                t.taken++;
                                listBox2.Items.Add(t);
                            }
                            else
                            {
                                listBox2.Items.Add(new TakenFigures(DifFigures.tip.Pawn, 1));
                            }
                        }
                        // Ако enpa е true, тогаш е завршен потегот и не треба да влегува во овој иф
                        if (!enpa)
                        {
                            Ostanati[kliknato2].t     = Ostanati[Dva[0]].t;
                            Ostanati[kliknato2].White = false;
                            Ostanati[Dva[0]].White    = false;
                            Ostanati[Dva[0]].t        = DifFigures.tip.None;
                            PlayerTurn[3]             = false;
                            PlayerTurn[0]             = true;
                            FinishedPlayer            = false;
                            matrica.ZafateniMesta[kliknato2 / 8][kliknato2 % 8] = true;
                            matrica.Whitte[kliknato2 / 8][kliknato2 % 8]        = false;
                            matrica.ZafateniMesta[Dva[0] / 8][Dva[0] % 8]       = false;
                            if (ShowValid)
                            {
                                this.DrawIt();
                            }
                        }

                        label1.Text = "White's Turn";
                    }

                    bool Nekoja = false;
                    // Го барам белиот крал за да проверам дали е во Шах позиција, доколку не го најдам, завршена е играта
                    for (int i = 0; i < 64; i++)
                    {
                        if (Ostanati[i].t == DifFigures.tip.King && Ostanati[i].White)
                        {
                            indGoIma = i;
                            Nekoja   = true;
                        }
                    }


                    if (Nekoja)
                    {
                        SahMat Krall = new SahMat(indGoIma, Ostanati, matrica, true);
                        Krall.Val();
                    }
                    else if (!Nekoja)
                    {
                        PlayerTurn[0] = PlayerTurn[1] = PlayerTurn[2] = PlayerTurn[3] = false;
                        label1.Text   = "Victory!!!";
                        File.AppendAllText("HighScores.txt", Environment.NewLine + vtorIgrac + " " + textBox2.Text + " " + prvIgrac + " " + textBox1.Text);
                        MessageBox.Show("" + vtorIgrac + " победи! Честитки!", "Победа");
                    }


                    // Доколку пионот стигне на другиот крај од шаховската табла
                    if (kliknato2 / 8 == 7 && Ostanati[kliknato2].t == DifFigures.tip.Pawn)
                    {
                        MessageBox.Show("Pawn Promotion! Одберете друга фигура којашто сакате да ја замените наместо пионот");
                        PawnPromotion Promotion = new PawnPromotion(this, false, kliknato2, BlackTaken);
                        Promotion.Show();
                    }
                }
            }

            if (PlayerTurn[2] && FinishedPlayer)
            {
                Keep       = 0;
                k          = new ValidMoves(Ostanati[kliknato], kliknato, matrica, Enpassant);
                Pom1.Image = figures[kliknato].Image;
                kliknato   = Array.IndexOf(figures, ptt);
                if (Keep == 1)
                {
                    Keep = 0;
                }
                Dva[Keep] = kliknato;
                Keep++;

                // Ако сум одбрал црна фигура и белите фигури завршиле
                if (!Ostanati[kliknato].t.Equals(DifFigures.tip.None) && PlayerTurn[2] && Ostanati[kliknato].White == false)
                {
                    PictureBox pttt = (PictureBox)sender;
                    Pom1.Image = pttt.Image;

                    PlayerTurn[3] = true;
                    PlayerTurn[2] = false;
                    if (ShowValid)
                    {
                        DrawIt();
                    }
                }

                /*   else if (!PlayerTurn[3] && (Ostanati[kliknato].t.Equals(DifFigures.tip.None) || Ostanati[kliknato].White))
                 *    {
                 *        PlayerTurn[1] = false;
                 *    } */
            }
            else if (PlayerTurn[1])
            {
                kliknato2 = Array.IndexOf(figures, ptt);


                if (kliknato2 == -1)
                {
                    kliknato2     = 0;
                    PlayerTurn[1] = false;
                    PlayerTurn[0] = true;
                }
                // Aко кликнам бело, селектирај ја новата фигура
                else if (k.Zafateni.Whitte[kliknato2 / 8][kliknato2 % 8] == true)
                {
                    PlayerTurn[0] = true;
                }
                // Enpassante за бели фигури
                if ((kliknato2 / 8 == 4 && Dva[0] / 8 == 6 && matrica.ZafateniMesta[Dva[0] / 8][Dva[0] % 8] && Ostanati[Dva[0]].t == DifFigures.tip.Pawn))
                {
                    try
                    {
                        if (kliknato % 8 - 1 >= 0 && matrica.ZafateniMesta[4][kliknato2 % 8 - 1] && !matrica.Whitte[4][kliknato2 % 8 - 1] ||
                            (kliknato % 8 + 1 < 8) && matrica.ZafateniMesta[4][kliknato2 % 8 + 1] && !matrica.Whitte[4][kliknato2 % 8 + 1])
                        {
                            Enpassant[0][Dva[0] % 8] = true;
                            for (int i = 0; i < 8; i++)
                            {
                                if (Enpassant[0][i] && i != Dva[0] % 8)
                                {
                                    Enpassant[0][i] = false;
                                }
                            }
                        }
                    }
                    catch (Exception ent)
                    {
                    }
                }



                // Рокада за бел крал и десен бел топ
                if (Castling[0] && Castling[1] && (Castling[2] || Castling[3]))
                {
                    if (((kliknato2 == 63 && Dva[0] == 60) || (kliknato2 == 60 && Dva[0] == 63)) && Castling[3])
                    {
                        Castling t = new Castling(matrica, true, false);
                        if (t.ValidirajCastle())
                        {
                            this.SpecialDraw();
                            figures[Dva[0]].Image    = null;
                            figures[61].Image        = Properties.Resources.Piece63;
                            figures[61].SizeMode     = PictureBoxSizeMode.StretchImage;
                            figures[62].Image        = Properties.Resources.Piece60;
                            figures[62].SizeMode     = PictureBoxSizeMode.StretchImage;
                            figures[kliknato2].Image = null;

                            for (int i = 0; i < 4; i++)
                            {
                                Castling[i] = false;
                            }
                            FinishedPlayer = true;
                            PlayerTurn[1]  = false;
                            PlayerTurn[2]  = true;

                            DifFigures pomosna  = Ostanati[Dva[0]];
                            DifFigures pomosna2 = Ostanati[kliknato2];

                            Ostanati[61].t = DifFigures.tip.Rook;
                            Ostanati[62].t = DifFigures.tip.King;
                            Ostanati[60].t = DifFigures.tip.None;
                            Ostanati[63].t = DifFigures.tip.None;
                            matrica.ZafateniMesta[7][5] = true;
                            matrica.ZafateniMesta[7][6] = true;
                            matrica.ZafateniMesta[7][7] = false;
                            matrica.ZafateniMesta[7][4] = false;
                            matrica.Whitte[7][5]        = true;
                            matrica.Whitte[7][6]        = true;
                            Ostanati[61].White          = true;
                            Ostanati[62].White          = true;

                            label1.Text = "Black's Turn";
                        }
                    }
                    // Рокада за лев бел топ и бел крал
                    else if (((kliknato2 == 56 && Dva[0] == 60) || (kliknato2 == 60 && Dva[0] == 56)) && Castling[2])
                    {
                        Castling t = new Castling(matrica, true, true);

                        if (t.ValidirajCastle())
                        {
                            this.SpecialDraw();
                            figures[Dva[0]].Image    = null;
                            figures[58].Image        = Properties.Resources.Piece60;
                            figures[58].SizeMode     = PictureBoxSizeMode.StretchImage;
                            figures[59].Image        = Properties.Resources.Piece63;
                            figures[59].SizeMode     = PictureBoxSizeMode.StretchImage;
                            figures[kliknato2].Image = null;

                            for (int i = 0; i < 4; i++)
                            {
                                Castling[i] = false;
                            }
                            FinishedPlayer = true;
                            PlayerTurn[1]  = false;
                            PlayerTurn[2]  = true;

                            DifFigures pomosna  = Ostanati[Dva[0]];
                            DifFigures pomosna2 = Ostanati[kliknato2];

                            Ostanati[59].t = DifFigures.tip.Rook;
                            Ostanati[58].t = DifFigures.tip.King;
                            Ostanati[56].t = DifFigures.tip.None;
                            Ostanati[60].t = DifFigures.tip.None;
                            matrica.ZafateniMesta[7][2] = true;
                            matrica.ZafateniMesta[7][3] = true;
                            matrica.ZafateniMesta[7][0] = false;
                            matrica.ZafateniMesta[7][4] = false;
                            matrica.Whitte[7][2]        = true;
                            matrica.Whitte[7][3]        = true;
                            Ostanati[59].White          = true;
                            Ostanati[58].White          = true;

                            label1.Text = "Black's Turn";
                        }
                    }
                }
                // Проверка дали кралот е уште во игра
                if (k.figura.t == DifFigures.tip.King)
                {
                    matrica.ZafateniMesta[Dva[0] / 8][Dva[0] % 8]       = false;
                    matrica.ZafateniMesta[kliknato2 / 8][kliknato2 % 8] = true;
                    matrica.Whitte[kliknato2 / 8][kliknato2 % 8]        = true;
                    SahMat t = new SahMat(kliknato2, Ostanati, matrica, true);
                    if (t.Value())
                    {
                        k.Valid[kliknato2 / 8][kliknato2 % 8] = false;
                    }


                    matrica.ZafateniMesta[kliknato2 / 8][kliknato2 % 8] = false;
                }


                if (k.Valid[kliknato2 / 8][kliknato2 % 8] && !FinishedPlayer)
                {
                    figures[kliknato2].Image    = Pom1.Image;
                    figures[kliknato2].SizeMode = PictureBoxSizeMode.StretchImage;
                    figures[Dva[0]].Image       = null;
                    TakenFigures pomosna  = new TakenFigures();
                    bool         GoIma    = false;
                    int          indGoIma = 0;

                    // Ако е земена фигура додај ја во листа
                    if (Ostanati[kliknato2].t != DifFigures.tip.None)
                    {
                        TakenFigures l = new TakenFigures();
                        foreach (TakenFigures p in listBox1.Items)
                        {
                            pomosna = (TakenFigures)p;

                            if (pomosna.v.Equals(Ostanati[kliknato2].t))
                            {
                                GoIma    = true;
                                indGoIma = listBox1.Items.IndexOf(p);
                                l        = p;
                            }
                        }
                        // Ако ја има фигурата зголеми го само бројот во листата
                        if (GoIma)
                        {
                            listBox1.Items.Remove(l);
                            pomosna.taken++;
                            listBox1.Items.Add(l);
                        }
                        // Ако не, додај
                        if (!GoIma)
                        {
                            BlackTaken.Add(Ostanati[kliknato2].t);
                            if (Ostanati[kliknato2].t == DifFigures.tip.Pawn)
                            {
                                listBox1.Items.Add(new TakenFigures(DifFigures.tip.Pawn, 1));
                            }
                            else
                            if (Ostanati[kliknato2].t == DifFigures.tip.Knight)
                            {
                                listBox1.Items.Add(new TakenFigures(DifFigures.tip.Knight, 1));
                            }
                            else if (Ostanati[kliknato2].t == DifFigures.tip.Bishop)
                            {
                                listBox1.Items.Add(new TakenFigures(DifFigures.tip.Bishop, 1));
                            }
                            else if (Ostanati[kliknato2].t == DifFigures.tip.Rook)
                            {
                                listBox1.Items.Add(new TakenFigures(DifFigures.tip.Rook, 1));
                            }
                            else if (Ostanati[kliknato2].t == DifFigures.tip.Queen)
                            {
                                listBox1.Items.Add(new TakenFigures(DifFigures.tip.Queen, 1));
                            }
                            else if (Ostanati[kliknato2].t == DifFigures.tip.King)
                            {
                                listBox1.Items.Add(new TakenFigures(DifFigures.tip.King, 1));
                            }
                        }
                    }
                    // Ако е поместен топ или крал, постави го соодветната булова за рокада false
                    if (!FinishedPlayer)
                    {
                        if (Dva[0] == 60)
                        {
                            Castling[1] = false;
                        }
                        if (Dva[0] == 56)
                        {
                            Castling[2] = false;
                        }
                        if (Dva[0] == 63)
                        {
                            Castling[3] = false;
                        }
                        bool enpa = false;
                        // Enpassante движење
                        if ((Dva[0] % 8 != kliknato2 % 8 && Dva[0] / 8 == 3 && kliknato2 / 8 == 2 && Ostanati[kliknato2].t == DifFigures.tip.None && Ostanati[Dva[0]].t == DifFigures.tip.Pawn && Ostanati[kliknato2 + 8].t == DifFigures.tip.Pawn))
                        {
                            Ostanati[kliknato2 + 8].t = DifFigures.tip.None;
                            Ostanati[kliknato2].t     = DifFigures.tip.Pawn;
                            Ostanati[Dva[0]].t        = DifFigures.tip.None;

                            matrica.ZafateniMesta[kliknato2 / 8 + 1][kliknato2 % 8] = false;
                            matrica.ZafateniMesta[kliknato2 / 8][kliknato2 % 8]     = true;
                            matrica.ZafateniMesta[Dva[0] / 8][Dva[0] % 8]           = false;
                            Ostanati[kliknato2].White    = true;
                            figures[kliknato2 + 8].Image = null;
                            enpa           = true;
                            PlayerTurn[1]  = false;
                            PlayerTurn[2]  = true;
                            FinishedPlayer = true;
                            if (ShowValid)
                            {
                                this.DrawIt();
                            }

                            bool goIma = false;

                            TakenFigures t = new TakenFigures();
                            foreach (TakenFigures p in listBox1.Items)
                            {
                                if (p.v.Equals(DifFigures.tip.Pawn))
                                {
                                    goIma = true;
                                    t     = p;
                                }
                            }
                            // Ако ја има, зголеми бројач
                            if (goIma)
                            {
                                listBox1.Items.Remove(t);
                                t.taken++;
                                listBox1.Items.Add(t);
                            }
                            else
                            {
                                listBox1.Items.Add(new TakenFigures(DifFigures.tip.Pawn, 1));
                            }
                        }
                        // Ако не се случило enpassante движење (односно не е завршен играчот)
                        if (!enpa & k.Valid[kliknato2 / 8][kliknato2 % 8])
                        {
                            Ostanati[kliknato2].t     = Ostanati[Dva[0]].t;
                            Ostanati[kliknato2].White = true;
                            Ostanati[Dva[0]].White    = false;
                            Ostanati[Dva[0]].t        = DifFigures.tip.None;
                            PlayerTurn[1]             = false;
                            PlayerTurn[2]             = true;
                            FinishedPlayer            = true;
                            matrica.ZafateniMesta[kliknato2 / 8][kliknato2 % 8] = true;
                            matrica.Whitte[kliknato2 / 8][kliknato2 % 8]        = true;
                            matrica.ZafateniMesta[Dva[0] / 8][Dva[0] % 8]       = false;
                            matrica.Whitte[Dva[0] / 8][Dva[0] % 8] = false;

                            if (ShowValid)
                            {
                                this.DrawIt();
                            }
                        }
                        bool Nekoja = false;



                        // Барај го кралот
                        for (int i = 0; i < 64; i++)
                        {
                            if (Ostanati[i].t == DifFigures.tip.King && !Ostanati[i].White)
                            {
                                indGoIma = i;
                                Nekoja   = true;
                            }
                        }
                        // Провери дали е во шах
                        label1.Text = "Black's Turn";
                        if (Nekoja)
                        {
                            SahMat Krall = new SahMat(indGoIma, Ostanati, matrica, false);
                            Krall.Val();
                        }
                        // Кралот е погубен
                        else if (!Nekoja)
                        {
                            PlayerTurn[0] = PlayerTurn[1] = PlayerTurn[2] = PlayerTurn[3] = false;
                            label1.Text   = "Victory!!!";
                            MessageBox.Show("" + prvIgrac + " победи! Честитки!", "Победа");
                            File.AppendAllText("HighScores.txt", Environment.NewLine + prvIgrac + " " + textBox1.Text + " " + vtorIgrac + " " + textBox2.Text);
                        }
                        // Пиончето стигнало на крајот од шаховската табла
                        if (kliknato2 / 8 == 0 && Ostanati[kliknato2].t == DifFigures.tip.Pawn)
                        {
                            MessageBox.Show("Pawn Promotion! Одберете друга фигура којашто сакате да ја замените наместо пионот");
                            PawnPromotion Promotion = new PawnPromotion(this, true, kliknato2, WhiteTaken);
                            Promotion.Show();
                        }
                    }
                }
            }

            if (PlayerTurn[0])
            {
                k = new ValidMoves(Ostanati[kliknato], kliknato, matrica, Enpassant);

                Pom1.SizeMode = PictureBoxSizeMode.StretchImage;
                Pom1.Image    = figures[kliknato].Image;
                kliknato      = Array.IndexOf(figures, ptt);

                if (Keep >= 1)
                {
                    Keep = 0;
                }
                Dva[Keep] = kliknato;
                Keep++;
                if (Keep == 1)
                {
                    Keep = 0;
                }
                if (kliknato == -1)
                {
                    kliknato      = 0;
                    PlayerTurn[2] = false;
                    PlayerTurn[0] = true;
                }

                else if (!Ostanati[kliknato].t.Equals(DifFigures.tip.None) && PlayerTurn[0] && Ostanati[kliknato].White == true)
                {
                    if (ShowValid)
                    {
                        this.DrawIt();
                    }
                    PictureBox pttt = (PictureBox)sender;
                    Pom1.Image    = pttt.Image;
                    PlayerTurn[1] = true;
                    PlayerTurn[0] = false;
                }
                // Ако е кликнато нешто што не е бела фигура
                else if (!PlayerTurn[1] && (Ostanati[kliknato].t.Equals(DifFigures.tip.None) || !Ostanati[kliknato].White))
                {
                    PlayerTurn[1] = false;
                }
            }
        }
Exemple #5
0
        public void Val()
        {
            bool ednas  = false;
            bool SahMat = false;

            if (!White)
            {
                // За секоја фигура што не е од моите, провери дали му е валидна позицијата на мојот крал
                for (int i = 0; i < 64; i++)
                {
                    if (OstanatiFiguri[i].White && OstanatiFiguri[i].t != DifFigures.tip.None)
                    {
                        ValidMoves k = new ValidMoves(OstanatiFiguri[i], i, Zafateni, Enpassant);
                        if (k.Valid[idx / 8][idx % 8])
                        {
                            if (this.Mat() == false && !(ednas) && !(SahMat))
                            {
                                ednas = true;
                                MessageBox.Show("Нема валидни потези за вашиот крал. Поместете други фигури во одбрана на кралот, за да не ви биде одзеден!", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }

                            if (FinalSahMat(i) && !(SahMat) && this.Mat() == false)
                            {
                                SahMat = true;
                                MessageBox.Show("Шах Мат!");
                            }
                            if (!SahMat)
                            {
                                MessageBox.Show("Црниот крал е во \"ШАХ\" позиција од " + OstanatiFiguri[i].t, "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                Zafateni.ZafateniMesta[idx / 8][idx % 8] = false;
                            }
                            Zafateni.ZafateniMesta[idx / 8][idx % 8] = true;
                        }
                    }
                }
            }
            else if (White)
            {
                for (int i = 0; i < 64; i++)
                {
                    if (!OstanatiFiguri[i].White && OstanatiFiguri[i].t != DifFigures.tip.None)
                    {
                        ValidMoves k = new ValidMoves(OstanatiFiguri[i], i, Zafateni, Enpassant);
                        if (k.Valid[idx / 8][idx % 8] && !SahMat)
                        {
                            if (this.Mat() == false && !(ednas) && !SahMat)
                            {
                                ednas = true;
                                MessageBox.Show("Нема валидни потези за вашиот крал. Поместете други фигури во одбрана на кралот, за да не ви биде одзеден!", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }

                            if (FinalSahMat(i) && !(SahMat) && this.Mat() == false)
                            {
                                SahMat = true;
                                MessageBox.Show("Шах Мат!");
                            }
                            if (!SahMat)
                            {
                                MessageBox.Show("Белиот крал е во \"ШАХ\" позиција од " + OstanatiFiguri[i].t, "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                Zafateni.ZafateniMesta[idx / 8][idx % 8] = false;
                            }

                            Zafateni.ZafateniMesta[idx / 8][idx % 8] = true;
                        }
                    }
                }
            }
        }
Exemple #6
0
        public bool FinalSahMat(int a)
        {
            if (White)
            {
                if (OstanatiFiguri[a].t == DifFigures.tip.Knight || OstanatiFiguri[a].t == DifFigures.tip.Pawn)
                {
                    for (int i = 0; i < 8; i++)
                    {
                        for (int j = 0; j < 8; j++)
                        {
                            if (OstanatiFiguri[i * 8 + j].White && OstanatiFiguri[i * 8 + j].t != DifFigures.tip.King)
                            {
                                ValidMoves r = new ValidMoves(OstanatiFiguri[i * 8 + j], i * 8 + j, Zafateni, Enpassant);

                                if (r.Valid[a / 8][a % 8])
                                {
                                    return(false);
                                }
                            }
                        }
                    }
                    return(true);
                }


                else if (OstanatiFiguri[a].t == DifFigures.tip.Rook)
                {
                    if (a / 8 == idx / 8)
                    {
                        for (int r = Math.Min(a % 8, idx % 8); r <= Math.Max(a % 8, idx % 8); r++)
                        {
                            for (int b = 0; b < 8; b++)
                            {
                                for (int t = 0; t < 8; t++)
                                {
                                    if (OstanatiFiguri[b * 8 + t].White && OstanatiFiguri[b * 8 + t].t != DifFigures.tip.King)
                                    {
                                        ValidMoves kkk = new ValidMoves(OstanatiFiguri[b * 8 + t], b * 8 + t, Zafateni, Enpassant);
                                        if (kkk.Valid[a / 8][r])
                                        {
                                            return(false);
                                        }
                                    }
                                }
                            }
                        }
                        return(true);
                    }
                    else
                    {
                        for (int r = Math.Min(a / 8, idx / 8); r <= Math.Max(a / 8, idx / 8); r++)
                        {
                            for (int b = 0; b < 8; b++)
                            {
                                for (int t = 0; t < 8; t++)
                                {
                                    if (OstanatiFiguri[b * 8 + t].White && OstanatiFiguri[b * 8 + t].t != DifFigures.tip.King)
                                    {
                                        ValidMoves kkk = new ValidMoves(OstanatiFiguri[b * 8 + t], b * 8 + t, Zafateni, Enpassant);
                                        if (kkk.Valid[r][a % 8])
                                        {
                                            return(false);
                                        }
                                    }
                                }
                            }
                        }
                        return(true);
                    }
                }
                else if (OstanatiFiguri[a].t == DifFigures.tip.Bishop)
                {
                    for (int p = Math.Min(idx / 8, a / 8), tt = Math.Max(idx % 8, a % 8); p < Math.Max(idx / 8, a / 8) && tt > Math.Min(idx % 8, a % 8); p++, tt--)
                    {
                        for (int b = 0; b < 8; b++)
                        {
                            for (int c = 0; c < 8; c++)
                            {
                                if (OstanatiFiguri[b * 8 + c].White && OstanatiFiguri[b * 8 + c].t != DifFigures.tip.King)
                                {
                                    ValidMoves k = new ValidMoves(OstanatiFiguri[b * 8 + c], b * 8 + c, Zafateni, Enpassant);
                                    if (k.Valid[p][tt])
                                    {
                                        return(false);
                                    }
                                }
                            }
                        }
                    }
                    return(true);
                }
                else
                {
                    if ((idx / 8 > a / 8 && idx % 8 < a % 8) || (idx / 8 < a / 8 && idx % 8 > a % 8))
                    {
                        for (int p = Math.Min(idx / 8, a / 8), tt = Math.Max(idx % 8, a % 8); p < Math.Max(idx / 8, a / 8) && tt > Math.Min(idx % 8, a % 8); p++, tt--)
                        {
                            for (int b = 0; b < 8; b++)
                            {
                                for (int c = 0; c < 8; c++)
                                {
                                    if (OstanatiFiguri[b * 8 + c].White && OstanatiFiguri[b * 8 + c].t != DifFigures.tip.King)
                                    {
                                        ValidMoves k = new ValidMoves(OstanatiFiguri[b * 8 + c], b * 8 + c, Zafateni, Enpassant);
                                        if (k.Valid[p][tt])
                                        {
                                            return(false);
                                        }
                                    }
                                }
                            }
                        }
                        return(true);
                    }
                    else if (a / 8 == idx / 8)
                    {
                        for (int r = Math.Min(a % 8, idx % 8); r <= Math.Max(a % 8, idx % 8); r++)
                        {
                            for (int b = 0; b < 8; b++)
                            {
                                for (int t = 0; t < 8; t++)
                                {
                                    if (OstanatiFiguri[b * 8 + t].White && OstanatiFiguri[b * 8 + t].t != DifFigures.tip.King)
                                    {
                                        ValidMoves kkk = new ValidMoves(OstanatiFiguri[b * 8 + t], b * 8 + t, Zafateni, Enpassant);
                                        if (kkk.Valid[a / 8][r])
                                        {
                                            return(false);
                                        }
                                    }
                                }
                            }
                        }
                        return(true);
                    }
                    else
                    {
                        for (int r = Math.Min(a / 8, idx / 8); r <= Math.Max(a / 8, idx / 8); r++)
                        {
                            for (int b = 0; b < 8; b++)
                            {
                                for (int t = 0; t < 8; t++)
                                {
                                    if (OstanatiFiguri[b * 8 + t].White && OstanatiFiguri[b * 8 + t].t != DifFigures.tip.King)
                                    {
                                        ValidMoves kkk = new ValidMoves(OstanatiFiguri[b * 8 + t], b * 8 + t, Zafateni, Enpassant);
                                        if (kkk.Valid[r][a % 8])
                                        {
                                            return(false);
                                        }
                                    }
                                }
                            }
                        }
                        return(true);
                    }
                }
            }
            else
            {
                if (OstanatiFiguri[a].t == DifFigures.tip.Knight || OstanatiFiguri[a].t == DifFigures.tip.Pawn)
                {
                    for (int i = 0; i < 8; i++)
                    {
                        for (int j = 0; j < 8; j++)
                        {
                            if (!OstanatiFiguri[i * 8 + j].White && OstanatiFiguri[i * 8 + j].t != DifFigures.tip.King)
                            {
                                ValidMoves r = new ValidMoves(OstanatiFiguri[i * 8 + j], i * 8 + j, Zafateni, Enpassant);

                                if (r.Valid[a / 8][a % 8])
                                {
                                    return(false);
                                }
                            }
                        }
                    }
                    return(true);
                }


                else if (OstanatiFiguri[a].t == DifFigures.tip.Rook)
                {
                    if (a / 8 == idx / 8)
                    {
                        for (int r = Math.Min(a % 8, idx % 8); r <= Math.Max(a % 8, idx % 8); r++)
                        {
                            for (int b = 0; b < 8; b++)
                            {
                                for (int t = 0; t < 8; t++)
                                {
                                    if (!OstanatiFiguri[b * 8 + t].White && OstanatiFiguri[b * 8 + t].t != DifFigures.tip.King)
                                    {
                                        ValidMoves kkk = new ValidMoves(OstanatiFiguri[b * 8 + t], b * 8 + t, Zafateni, Enpassant);
                                        if (kkk.Valid[a / 8][r])
                                        {
                                            return(false);
                                        }
                                    }
                                }
                            }
                        }
                        return(true);
                    }
                    else
                    {
                        for (int r = Math.Min(a / 8, idx / 8); r <= Math.Max(a / 8, idx / 8); r++)
                        {
                            for (int b = 0; b < 8; b++)
                            {
                                for (int t = 0; t < 8; t++)
                                {
                                    if (!OstanatiFiguri[b * 8 + t].White && OstanatiFiguri[b * 8 + t].t != DifFigures.tip.King)
                                    {
                                        ValidMoves kkk = new ValidMoves(OstanatiFiguri[b * 8 + t], b * 8 + t, Zafateni, Enpassant);
                                        if (kkk.Valid[r][a % 8])
                                        {
                                            return(false);
                                        }
                                    }
                                }
                            }
                        }
                        return(true);
                    }
                }
                else if (OstanatiFiguri[a].t == DifFigures.tip.Bishop)
                {
                    for (int p = Math.Min(idx / 8, a / 8), tt = Math.Max(idx % 8, a % 8); p < Math.Max(idx / 8, a / 8) && tt > Math.Min(idx % 8, a % 8); p++, tt--)
                    {
                        for (int b = 0; b < 8; b++)
                        {
                            for (int c = 0; c < 8; c++)
                            {
                                if (!OstanatiFiguri[b * 8 + c].White && OstanatiFiguri[b * 8 + c].t != DifFigures.tip.King)
                                {
                                    ValidMoves k = new ValidMoves(OstanatiFiguri[b * 8 + c], b * 8 + c, Zafateni, Enpassant);
                                    if (k.Valid[p][tt])
                                    {
                                        return(false);
                                    }
                                }
                            }
                        }
                    }
                    return(true);
                }
                else
                {
                    if ((idx / 8 > a / 8 && idx % 8 < a % 8) || (idx / 8 < a / 8 && idx % 8 > a % 8))
                    {
                        for (int p = Math.Min(idx / 8, a / 8), tt = Math.Max(idx % 8, a % 8); p < Math.Max(idx / 8, a / 8) && tt > Math.Min(idx % 8, a % 8); p++, tt--)
                        {
                            for (int b = 0; b < 8; b++)
                            {
                                for (int c = 0; c < 8; c++)
                                {
                                    if (!OstanatiFiguri[b * 8 + c].White && OstanatiFiguri[b * 8 + c].t != DifFigures.tip.King)
                                    {
                                        ValidMoves k = new ValidMoves(OstanatiFiguri[b * 8 + c], b * 8 + c, Zafateni, Enpassant);
                                        if (k.Valid[p][tt])
                                        {
                                            return(false);
                                        }
                                    }
                                }
                            }
                        }
                        return(true);
                    }
                    else if (a / 8 == idx / 8)
                    {
                        for (int r = Math.Min(a % 8, idx % 8); r <= Math.Max(a % 8, idx % 8); r++)
                        {
                            for (int b = 0; b < 8; b++)
                            {
                                for (int t = 0; t < 8; t++)
                                {
                                    if (!OstanatiFiguri[b * 8 + t].White && OstanatiFiguri[b * 8 + t].t != DifFigures.tip.King)
                                    {
                                        ValidMoves kkk = new ValidMoves(OstanatiFiguri[b * 8 + t], b * 8 + t, Zafateni, Enpassant);
                                        if (kkk.Valid[a / 8][r])
                                        {
                                            return(false);
                                        }
                                    }
                                }
                            }
                        }
                        return(true);
                    }
                    else
                    {
                        for (int r = Math.Min(a / 8, idx / 8); r <= Math.Max(a / 8, idx / 8); r++)
                        {
                            for (int b = 0; b < 8; b++)
                            {
                                for (int t = 0; t < 8; t++)
                                {
                                    if (!OstanatiFiguri[b * 8 + t].White && OstanatiFiguri[b * 8 + t].t != DifFigures.tip.King)
                                    {
                                        ValidMoves kkk = new ValidMoves(OstanatiFiguri[b * 8 + t], b * 8 + t, Zafateni, Enpassant);
                                        if (kkk.Valid[r][a % 8])
                                        {
                                            return(false);
                                        }
                                    }
                                }
                            }
                        }
                        return(true);
                    }
                }
            }
        }
Exemple #7
0
        public bool Mat()
        {
            // Стави ги во листа сите валидни потези на мојот крал
            if (!White)
            {
                ValidMoves t = new ValidMoves(new DifFigures(false, DifFigures.tip.King), idx, Zafateni, Enpassant);
                for (int i = 0; i < 8; i++)
                {
                    for (int j = 0; j < 8; j++)
                    {
                        if (t.Valid[i][j])
                        {
                            pom.Add(i * 8 + j);
                        }
                    }
                }


                bool[] pomosna = new bool[8];

                bool Nevalidno = false;
                foreach (int sekojIdx in pom)
                {
                    Nevalidno = false;
                    for (int i = 0; i < 64; i++)
                    {
                        // Доколку најдеш дека фигура од спротивниот тим има пристап до тоа поле, оневозможи ја валидноста на тоа поле
                        if (OstanatiFiguri[i].White && OstanatiFiguri[i].t != DifFigures.tip.None)
                        {
                            ValidMoves k = new ValidMoves(OstanatiFiguri[i], i, Zafateni, Enpassant);
                            if (k.Valid[sekojIdx / 8][sekojIdx % 8])
                            {
                                Nevalidno = true;
                            }
                        }
                    }
                    if (!Nevalidno)
                    {
                        return(true);
                    }
                }
                return(false);
            }
            else
            {
                ValidMoves t = new ValidMoves(new DifFigures(true, DifFigures.tip.King), idx, Zafateni, Enpassant);
                for (int i = 0; i < 8; i++)
                {
                    for (int j = 0; j < 8; j++)
                    {
                        if (t.Valid[i][j])
                        {
                            pom.Add(i * 8 + j);
                        }
                    }
                }


                bool[] pomosna = new bool[8];

                bool Nevalidno = false;
                foreach (int sekojIdx in pom)
                {
                    Nevalidno = false;
                    for (int i = 0; i < 64; i++)
                    {
                        if (!OstanatiFiguri[i].White && OstanatiFiguri[i].t != DifFigures.tip.None)
                        {
                            ValidMoves k = new ValidMoves(OstanatiFiguri[i], i, Zafateni, Enpassant);
                            if (k.Valid[sekojIdx / 8][sekojIdx % 8])
                            {
                                Nevalidno = true;
                            }
                        }
                    }
                    if (!Nevalidno)
                    {
                        return(true);
                    }
                }
                return(false);
            }
        }
Exemple #8
0
        public void generatePotezi(DifFigures.tip t, int index, bool White, TakenPlaces Zafateni, bool[][] Enpassant)
        {
            if (t.Equals(DifFigures.tip.Pawn) && !White)
            {
                // Поле напред
                if ((index / 8) + 1 < 8)
                {
                    if (!(Zafateni.ZafateniMesta[index / 8 + 1][index % 8]))
                    {
                        Valid[(index / 8) + 1][(index % 8)] = true;
                    }
                }
                // Поле лево напред, доколку е зафатено
                if (index / 8 + 1 < 8 && ((index % 8) - 1) >= 0)
                {
                    if (Zafateni.ZafateniMesta[index / 8 + 1][index % 8 - 1] && Zafateni.Whitte[index / 8 + 1][index % 8 - 1] == true)
                    {
                        Valid[(index / 8) + 1][(index % 8) - 1] = true;
                    }
                }
                // Поле десно напред, доколку е зафатено
                if ((index / 8) + 1 < 8 && ((index % 8) + 1) < 8)
                {
                    if (Zafateni.ZafateniMesta[index / 8 + 1][index % 8 + 1] && Zafateni.Whitte[index / 8 + 1][index % 8 + 1] == true)
                    {
                        Valid[(index / 8) + 1][(index % 8) + 1] = true;
                    }
                }
                // Поле две напред, доколку на почетна позиција && поле едно напред не е зафатено
                if (index / 8 == 1 && index / 8 + 2 < 8)
                {
                    if (!Zafateni.ZafateniMesta[index / 8 + 2][index % 8] && !Zafateni.ZafateniMesta[index / 8 + 1][index % 8])
                    {
                        Valid[(index / 8) + 2][index % 8] = true;
                    }
                }
                // Enpassantе валидност десно
                if (index % 8 + 1 < 8)
                {
                    if (index % 8 + 1 < 8 && index / 8 == 4 && Enpassant[0][index % 8 + 1])
                    {
                        Valid[5][index % 8 + 1] = true;
                        IsEnpassant             = true;
                    }
                }
                // Enpassante лево
                if (index % 8 - 1 >= 0)
                {
                    if (index % 8 - 1 >= 0 && index / 8 == 4 && Enpassant[0][index % 8 - 1])
                    {
                        Valid[5][index % 8 - 1] = true;
                        IsEnpassant             = true;
                    }
                }
            }
            // Исто за бел пион
            else if (t.Equals(DifFigures.tip.Pawn) && White)
            {
                if ((index / 8) - 1 >= 0)
                {
                    if (!Zafateni.ZafateniMesta[index / 8 - 1][index % 8] && Zafateni.Whitte[index / 8 - 1][index % 8] == false)
                    {
                        Valid[(index / 8) - 1][(index % 8)] = true;
                    }
                }
                if (index / 8 - 1 >= 0 && ((index % 8) - 1) >= 0)
                {
                    if (Zafateni.ZafateniMesta[index / 8 - 1][index % 8 - 1] && Zafateni.Whitte[index / 8 - 1][index % 8 - 1] == false)
                    {
                        Valid[(index / 8) - 1][(index % 8) - 1] = true;
                    }
                }
                if ((index / 8) - 1 >= 0 && ((index % 8) + 1) < 8)
                {
                    if (Zafateni.ZafateniMesta[index / 8 - 1][index % 8 + 1] && Zafateni.Whitte[index / 8 - 1][index % 8 + 1] == false)
                    {
                        Valid[(index / 8) - 1][(index % 8) + 1] = true;
                    }
                }
                if (index / 8 == 6 && index / 8 - 2 >= 0)
                {
                    if (!Zafateni.ZafateniMesta[index / 8 - 2][index % 8] && !Zafateni.ZafateniMesta[index / 8 - 1][index % 8])
                    {
                        Valid[(index / 8) - 2][index % 8] = true;
                    }
                }
                if (index % 8 + 1 < 8)
                {
                    if (index % 8 + 1 < 8 && index / 8 == 3 && Enpassant[1][index % 8 + 1])
                    {
                        Valid[2][index % 8 + 1] = true;
                        IsEnpassant             = true;
                    }
                }
                if (index % 8 - 1 >= 0)
                {
                    if (index % 8 - 1 >= 0 && index / 8 == 3 && Enpassant[1][index % 8 - 1])
                    {
                        Valid[2][index % 8 - 1] = true;
                        IsEnpassant             = true;
                    }
                }
            }

            // Валидни потези за кралот (Напред (лево, право, десно), лево, десно, Назад (лево, право, десно))
            else if (t.Equals(DifFigures.tip.King))
            {
                if (White)
                {
                    if (index / 8 + 1 < 8 && index % 8 + 1 < 8)
                    {
                        if (!Zafateni.Whitte[(index / 8) + 1][(index % 8) + 1] || !Zafateni.ZafateniMesta[(index / 8) + 1][(index % 8) + 1])
                        {
                            Valid[(index / 8) + 1][(index % 8) + 1] = true;
                        }
                    }

                    if (index / 8 + 1 < 8 && index % 8 - 1 >= 0)
                    {
                        if (!Zafateni.Whitte[(index / 8) + 1][(index % 8) - 1] || !Zafateni.ZafateniMesta[(index / 8) + 1][(index % 8) - 1])
                        {
                            Valid[(index / 8) + 1][(index % 8) - 1] = true;
                        }
                    }

                    if ((index / 8 - 1 >= 0 && index % 8 + 1 < 8))
                    {
                        if (!Zafateni.Whitte[(index / 8) - 1][(index % 8) + 1] || !Zafateni.ZafateniMesta[(index / 8) - 1][(index % 8) + 1])
                        {
                            Valid[(index / 8) - 1][(index % 8) + 1] = true;
                        }
                    }

                    if ((index / 8 - 1 >= 0 && index % 8 - 1 >= 0))
                    {
                        if (!Zafateni.Whitte[(index / 8) - 1][(index % 8) - 1] || !Zafateni.ZafateniMesta[(index / 8) - 1][(index % 8) - 1])
                        {
                            Valid[(index / 8) - 1][(index % 8) - 1] = true;
                        }
                    }

                    if (index % 8 + 1 < 8)
                    {
                        if (!Zafateni.Whitte[(index / 8)][(index % 8) + 1] || !Zafateni.ZafateniMesta[(index / 8)][(index % 8) + 1])
                        {
                            Valid[(index / 8)][(index % 8) + 1] = true;
                        }
                    }

                    if (index % 8 - 1 >= 0)
                    {
                        if (!Zafateni.Whitte[(index / 8)][(index % 8) - 1] || !Zafateni.ZafateniMesta[(index / 8)][(index % 8) - 1])
                        {
                            Valid[(index / 8)][(index % 8) - 1] = true;
                        }
                    }

                    if (index / 8 + 1 < 8)
                    {
                        if (!Zafateni.Whitte[(index / 8 + 1)][(index % 8)] || !Zafateni.ZafateniMesta[(index / 8 + 1)][(index % 8)])
                        {
                            Valid[(index / 8) + 1][(index % 8)] = true;
                        }
                    }
                    if (index / 8 - 1 >= 0)
                    {
                        if (!Zafateni.Whitte[(index / 8 - 1)][(index % 8)] || !Zafateni.ZafateniMesta[(index / 8 - 1)][(index % 8)])
                        {
                            Valid[(index / 8) - 1][(index % 8)] = true;
                        }
                    }
                }
                else if (!White)
                {
                    if (index / 8 + 1 < 8 && index % 8 + 1 < 8)
                    {
                        if (Zafateni.Whitte[(index / 8) + 1][(index % 8) + 1] || !Zafateni.ZafateniMesta[(index / 8) + 1][(index % 8) + 1])
                        {
                            Valid[(index / 8) + 1][(index % 8) + 1] = true;
                        }
                    }

                    if (index / 8 + 1 < 8 && index % 8 - 1 >= 0)
                    {
                        if (Zafateni.Whitte[(index / 8) + 1][(index % 8) - 1] || !Zafateni.ZafateniMesta[(index / 8) + 1][(index % 8) - 1])
                        {
                            Valid[(index / 8) + 1][(index % 8) - 1] = true;
                        }
                    }

                    if ((index / 8 - 1 >= 0 && index % 8 + 1 < 8))
                    {
                        if (Zafateni.Whitte[(index / 8) - 1][(index % 8) + 1] || !Zafateni.ZafateniMesta[(index / 8) - 1][(index % 8) + 1])
                        {
                            Valid[(index / 8) - 1][(index % 8) + 1] = true;
                        }
                    }

                    if ((index / 8 - 1 >= 0 && index % 8 - 1 >= 0))
                    {
                        if (Zafateni.Whitte[(index / 8) - 1][(index % 8) - 1] || !Zafateni.ZafateniMesta[(index / 8) - 1][(index % 8) - 1])
                        {
                            Valid[(index / 8) - 1][(index % 8) - 1] = true;
                        }
                    }

                    if (index % 8 + 1 < 8)
                    {
                        if (Zafateni.Whitte[(index / 8)][(index % 8) + 1] || !Zafateni.ZafateniMesta[(index / 8)][(index % 8) + 1])
                        {
                            Valid[(index / 8)][(index % 8) + 1] = true;
                        }
                    }

                    if (index % 8 - 1 >= 0)
                    {
                        if (Zafateni.Whitte[(index / 8)][(index % 8) - 1] || !Zafateni.ZafateniMesta[(index / 8)][(index % 8) - 1])
                        {
                            Valid[(index / 8)][(index % 8) - 1] = true;
                        }
                    }

                    if (index / 8 + 1 < 8)
                    {
                        if (Zafateni.Whitte[(index / 8 + 1)][(index % 8)] || !Zafateni.ZafateniMesta[(index / 8 + 1)][(index % 8)])
                        {
                            Valid[(index / 8) + 1][(index % 8)] = true;
                        }
                    }
                    if (index / 8 - 1 >= 0)
                    {
                        if (Zafateni.Whitte[(index / 8 - 1)][(index % 8)] || !Zafateni.ZafateniMesta[(index / 8 - 1)][(index % 8)])
                        {
                            Valid[(index / 8) - 1][(index % 8)] = true;
                        }
                    }
                }
            }
            else if (t.Equals(DifFigures.tip.Rook))
            {
                int[] Tocki = new int[4];
                Tocki[0] = -1;
                Tocki[1] = -1;
                Tocki[2] = -1;
                Tocki[3] = -1;
                int min = Int16.MinValue;


                for (int i = index / 8 - 1; i >= 0; i--)
                {
                    if (Zafateni.ZafateniMesta[i][index % 8])
                    {
                        if (min < i)
                        {
                            Tocki[0] = i;
                            min      = i;
                        }
                    }
                }
                min = Int32.MaxValue;
                for (int i = index / 8 + 1; i < 8; i++)
                {
                    if (Zafateni.ZafateniMesta[i][index % 8])
                    {
                        if (min > i)
                        {
                            min      = i;
                            Tocki[1] = i;
                        }
                    }
                }
                min = Int32.MinValue;
                for (int j = index % 8 - 1; j >= 0; j--)
                {
                    if (Zafateni.ZafateniMesta[index / 8][j])
                    {
                        if (min < j)
                        {
                            Tocki[2] = j;
                            min      = j;
                        }

                        break;
                    }
                }
                min = Int32.MaxValue;
                for (int j = index % 8 + 1; j < 8; j++)
                {
                    if (Zafateni.ZafateniMesta[index / 8][j])
                    {
                        if (min > j)
                        {
                            min      = j;
                            Tocki[3] = j;
                        }
                    }
                }
                if (Tocki[0] == -1)
                {
                    Tocki[0] = 0;
                }
                if (Tocki[1] == -1)
                {
                    Tocki[1] = 7;
                }
                if (Tocki[2] == -1)
                {
                    Tocki[2] = 0;
                }
                if (Tocki[3] == -1)
                {
                    Tocki[3] = 7;
                }


                if (White)
                {
                    for (int i = Tocki[0]; i <= Tocki[1]; i++)
                    {
                        if (!Zafateni.Whitte[i][index % 8] || !Zafateni.ZafateniMesta[i][index % 8])
                        {
                            Valid[i][index % 8] = true;
                        }
                    }
                    for (int j = Tocki[2]; j <= Tocki[3]; j++)
                    {
                        if (!Zafateni.Whitte[index / 8][j] || !Zafateni.ZafateniMesta[index / 8][j])
                        {
                            Valid[index / 8][j] = true;
                        }
                    }
                }
                else if (!White)
                {
                    for (int i = Tocki[0]; i <= Tocki[1]; i++)
                    {
                        if (Zafateni.Whitte[i][index % 8] || !Zafateni.ZafateniMesta[i][index % 8])
                        {
                            Valid[i][index % 8] = true;
                        }
                    }
                    for (int j = Tocki[2]; j <= Tocki[3]; j++)
                    {
                        if (Zafateni.Whitte[index / 8][j] || !Zafateni.ZafateniMesta[index / 8][j])
                        {
                            Valid[index / 8][j] = true;
                        }
                    }
                }
                Valid[index / 8][index % 8] = false;
            }
            else if (t.Equals(DifFigures.tip.Knight))
            {
                if (White)
                {
                    try
                    {
                        if (!Zafateni.Whitte[(index / 8) - 2][(index % 8) - 1] || !Zafateni.ZafateniMesta[(index / 8) - 2][(index % 8) - 1])
                        {
                            Valid[(index / 8) - 2][(index % 8) - 1] = true;
                        }
                    }
                    catch (Exception e)
                    {
                    }
                    try
                    {
                        if (!Zafateni.Whitte[(index / 8) - 2][(index % 8) + 1] || !Zafateni.ZafateniMesta[(index / 8) - 2][(index % 8) + 1])
                        {
                            Valid[(index / 8) - 2][(index % 8) + 1] = true;
                        }
                    }
                    catch (Exception e)
                    {
                    }
                    try
                    {
                        if (!Zafateni.Whitte[(index / 8) - 1][(index % 8) + 2] || !Zafateni.ZafateniMesta[(index / 8) - 1][(index % 8) + 2])
                        {
                            Valid[(index / 8) - 1][(index % 8) + 2] = true;
                        }
                    }
                    catch (Exception e)
                    {
                    }
                    try
                    {
                        if (!Zafateni.Whitte[(index / 8) - 1][(index % 8) - 2] || !Zafateni.ZafateniMesta[(index / 8) - 1][(index % 8) - 2])
                        {
                            Valid[(index / 8) - 1][(index % 8) - 2] = true;
                        }
                    }
                    catch (Exception e)
                    {
                    }
                    try
                    {
                        if (!Zafateni.Whitte[(index / 8) + 2][(index % 8) - 1] || !Zafateni.ZafateniMesta[(index / 8) + 2][(index % 8) - 1])
                        {
                            Valid[(index / 8) + 2][(index % 8) - 1] = true;
                        }
                    }
                    catch (Exception e)
                    {
                    }
                    try
                    {
                        if (!Zafateni.Whitte[(index / 8) + 2][(index % 8) + 1] || !Zafateni.ZafateniMesta[(index / 8) + 2][(index % 8) + 1])
                        {
                            Valid[(index / 8) + 2][(index % 8) + 1] = true;
                        }
                    }
                    catch (Exception e)
                    {
                    }
                    try
                    {
                        if (!Zafateni.Whitte[(index / 8) + 1][(index % 8) - 2] || !Zafateni.ZafateniMesta[(index / 8) + 1][(index % 8) - 2])
                        {
                            Valid[(index / 8) + 1][(index % 8) - 2] = true;
                        }
                    }
                    catch (Exception e)
                    {
                    }
                    try
                    {
                        if (!Zafateni.Whitte[(index / 8) + 1][(index % 8) + 2] || !Zafateni.ZafateniMesta[(index / 8) + 1][(index % 8) + 2])
                        {
                            Valid[(index / 8) + 1][(index % 8) + 2] = true;
                        }
                    }
                    catch (Exception e)
                    {
                    }
                }
                else if (!White)
                {
                    try
                    {
                        if (Zafateni.Whitte[(index / 8) - 2][(index % 8) - 1] || !Zafateni.ZafateniMesta[(index / 8) - 2][(index % 8) - 1])
                        {
                            Valid[(index / 8) - 2][(index % 8) - 1] = true;
                        }
                    }
                    catch (Exception e)
                    {
                    }
                    try
                    {
                        if (Zafateni.Whitte[(index / 8) - 2][(index % 8) + 1] || !Zafateni.ZafateniMesta[(index / 8) - 2][(index % 8) + 1])
                        {
                            Valid[(index / 8) - 2][(index % 8) + 1] = true;
                        }
                    }
                    catch (Exception e)
                    {
                    }
                    try
                    {
                        if (Zafateni.Whitte[(index / 8) - 1][(index % 8) + 2] || !Zafateni.ZafateniMesta[(index / 8) - 1][(index % 8) + 2])
                        {
                            Valid[(index / 8) - 1][(index % 8) + 2] = true;
                        }
                    }
                    catch (Exception e)
                    {
                    }
                    try
                    {
                        if (Zafateni.Whitte[(index / 8) - 1][(index % 8) - 2] || !Zafateni.ZafateniMesta[(index / 8) - 1][(index % 8) - 2])
                        {
                            Valid[(index / 8) - 1][(index % 8) - 2] = true;
                        }
                    }
                    catch (Exception e)
                    {
                    }
                    try
                    {
                        if (Zafateni.Whitte[(index / 8) + 2][(index % 8) - 1] || !Zafateni.ZafateniMesta[(index / 8) + 2][(index % 8) - 1])
                        {
                            Valid[(index / 8) + 2][(index % 8) - 1] = true;
                        }
                    }
                    catch (Exception e)
                    {
                    }
                    try
                    {
                        if (Zafateni.Whitte[(index / 8) + 2][(index % 8) + 1] || !Zafateni.ZafateniMesta[(index / 8) + 2][(index % 8) + 1])
                        {
                            Valid[(index / 8) + 2][(index % 8) + 1] = true;
                        }
                    }
                    catch (Exception e)
                    {
                    }
                    try
                    {
                        if (Zafateni.Whitte[(index / 8) + 1][(index % 8) - 2] || !Zafateni.ZafateniMesta[(index / 8) + 1][(index % 8) - 2])
                        {
                            Valid[(index / 8) + 1][(index % 8) - 2] = true;
                        }
                    }
                    catch (Exception e)
                    {
                    }
                    try
                    {
                        if (Zafateni.Whitte[(index / 8) + 1][(index % 8) + 2] || !Zafateni.ZafateniMesta[(index / 8) + 1][(index % 8) + 2])
                        {
                            Valid[(index / 8) + 1][(index % 8) + 2] = true;
                        }
                    }
                    catch (Exception e)
                    {
                    }
                }
            }
            else if (t.Equals(DifFigures.tip.Bishop))
            {
                int[][] Tocki = new int[4][];
                for (int i = 0; i < 4; i++)
                {
                    Tocki[i] = new int[2];
                }

                for (int i = 0; i < 4; i++)
                {
                    for (int j = 0; j < 2; j++)
                    {
                        Tocki[i][j] = -1;
                    }
                }
                int  min     = Int16.MinValue;
                bool barEdno = (index / 8 - 1 >= 0 && index % 8 - 1 >= 0);

                for (int a = index / 8 - 1, nesto = index % 8 - 1; a >= 0 && nesto >= 0; a--, nesto--)
                {
                    if (Zafateni.ZafateniMesta[a][nesto])
                    {
                        if (min < a)
                        {
                            Tocki[0][0] = a;
                            Tocki[0][1] = nesto;
                            min         = a;
                        }
                        barEdno = false;
                    }
                    else if (barEdno)
                    {
                        Tocki[0][0] = a;
                        Tocki[0][1] = nesto;
                    }
                }
                barEdno = (index / 8 + 1 < 8 && index % 8 + 1 < 8);
                min     = Int32.MaxValue;
                for (int a = index / 8 + 1, nesto = index % 8 + 1; a < 8 && nesto < 8; a++, nesto++)
                {
                    if (Zafateni.ZafateniMesta[a][nesto])
                    {
                        if (min > a)
                        {
                            Tocki[1][0] = a;
                            Tocki[1][1] = nesto;
                            min         = a;
                        }
                        barEdno = false;
                    }
                    else if (barEdno)
                    {
                        Tocki[1][0] = a;
                        Tocki[1][1] = nesto;
                    }
                }
                barEdno = (index / 8 + 1 < 8 && index % 8 - 1 >= 0);
                min     = Int32.MaxValue;
                for (int a = index / 8 + 1, nesto = index % 8 - 1; a < 8 && nesto >= 0; a++, nesto--)
                {
                    if (Zafateni.ZafateniMesta[a][nesto])
                    {
                        if (min > a)
                        {
                            Tocki[2][0] = a;
                            Tocki[2][1] = nesto;
                            min         = a;
                        }
                        barEdno = false;
                    }
                    else if (barEdno)
                    {
                        Tocki[2][0] = a;
                        Tocki[2][1] = nesto;
                    }
                }
                min     = Int32.MinValue;
                barEdno = (index / 8 - 1 >= 0 && index % 8 + 1 < 8);
                for (int a = index / 8 - 1, nesto = index % 8 + 1; a >= 0 && nesto < 8; a--, nesto++)
                {
                    if (Zafateni.ZafateniMesta[a][nesto])
                    {
                        if (min < a)
                        {
                            Tocki[3][0] = a;
                            Tocki[3][1] = nesto;
                            min         = a;
                        }
                        barEdno = false;
                    }
                    else if (barEdno)
                    {
                        Tocki[3][0] = a;
                        Tocki[3][1] = nesto;
                    }
                }
                if (Tocki[0][0] == -1)
                {
                    Tocki[0][0] = index / 8;
                    Tocki[0][1] = index % 8;
                }
                if (Tocki[1][0] == -1)
                {
                    Tocki[1][0] = index / 8;
                    Tocki[1][1] = index % 8;
                }
                if (Tocki[2][0] == -1)
                {
                    Tocki[2][0] = index / 8;
                    Tocki[2][1] = index % 8;
                }
                if (Tocki[3][0] == -1)
                {
                    Tocki[3][0] = index / 8;
                    Tocki[3][1] = index % 8;
                }
                if (White)
                {
                    for (int i = Tocki[0][0], j = Tocki[0][1]; i <= Tocki[1][0] && j <= Tocki[1][1]; i++, j++)
                    {
                        if (!Zafateni.Whitte[i][j] || !Zafateni.ZafateniMesta[i][j])
                        {
                            Valid[i][j] = true;
                        }
                    }
                    for (int i = Tocki[2][0], j = Tocki[2][1]; i >= Tocki[3][0] && j <= Tocki[3][1]; i--, j++)
                    {
                        if (!Zafateni.Whitte[i][j] || !Zafateni.ZafateniMesta[i][j])
                        {
                            Valid[i][j] = true;
                        }
                    }
                }
                if (!(White))
                {
                    for (int i = Tocki[0][0], j = Tocki[0][1]; i <= Tocki[1][0] && j <= Tocki[1][1]; i++, j++)
                    {
                        if (Zafateni.Whitte[i][j] || !Zafateni.ZafateniMesta[i][j])
                        {
                            Valid[i][j] = true;
                        }
                    }
                    for (int i = Tocki[2][0], j = Tocki[2][1]; i >= Tocki[3][0] && j <= Tocki[3][1]; i--, j++)
                    {
                        if (Zafateni.Whitte[i][j] || !Zafateni.ZafateniMesta[i][j])
                        {
                            Valid[i][j] = true;
                        }
                    }
                }
                Valid[index / 8][index % 8] = false;
            }
            else if (t.Equals(DifFigures.tip.Queen))
            {
                DifFigures Top = new DifFigures();
                Top.t     = DifFigures.tip.Rook;
                Top.White = this.figura.White;
                ValidMoves pom1   = new ValidMoves(Top, this.index, this.Zafateni, Enpassant);
                DifFigures Lamfer = new DifFigures();
                Lamfer.t     = DifFigures.tip.Bishop;
                Lamfer.White = this.figura.White;
                ValidMoves pom2 = new ValidMoves(Lamfer, this.index, this.Zafateni, Enpassant);
                for (int i = 0; i < 8; i++)
                {
                    for (int j = 0; j < 8; j++)
                    {
                        Valid[i][j] = (pom1.Valid[i][j] || pom2.Valid[i][j]);
                    }
                }
                Valid[index / 8][index % 8] = false;
            }
        }