示例#1
0
        //
        // Herstel zet op het bord.
        //
        public void Herstel(Zet zet)
        {
            //Check(zet, true);
            if (zet.naar == null)             // stuk naar doos
            {
                veld[zet.van.x, zet.van.y] = (int)StukType.geen;
                return;
            }
            veld[zet.van.x, zet.van.y]   = setStuk(zet.van.stuk);// ivm promotie veld[zet.naar.x, zet.naar.y];
            veld[zet.naar.x, zet.naar.y] = setStuk(zet.naar.stuk);

            if (zet.promotie)
            {
                Stuk dame = new Stuk(zet.van.stuk.kleur, StukType.Dame);
                evaluatie -= Stuk.Waarde(dame);
                evaluatie += zet.van.stuk.waarde;
            }
            if (zet.castling)             //V105
            {
                bool longCastling = zet.naar.x < 4;
                if (longCastling)
                {
                    veld[0, zet.van.y] = veld[3, zet.van.y];
                    veld[3, zet.van.y] = 0;
                }
                else
                {
                    veld[7, zet.van.y] = veld[5, zet.van.y];
                    veld[5, zet.van.y] = 0;
                }
                evaluatie -= (zet.van.stuk.kleur) ? 1 : -1;
            }
            evaluatie += zet.naar.stuk.waarde;
            //Check(zet,false);
        }
示例#2
0
        private Stuk getStuk(OvalShape selectedShape)
        {
            string name  = selectedShape.Name;
            char   type  = name[6];
            char   kleur = name[7];
            Stuk   stuk  = new Stuk((kleur == 'l'), (StukType)pieces.IndexOf(type) + 1);

            return(stuk);
        }
示例#3
0
        public Veld(string coor, Stuk stuk)
        {
            int p = coor.Length - 2; // last 2 chars = coordinate.

            x = coor[p] - 'a';
            y = 8 - coor[p + 1] + '0';
            if (x < 0 || x > 7 || y < 0 || y > 7)
            {
                throw new Exception("Veld coordinates out of range");
            }
            this.stuk = stuk;
        }
示例#4
0
        private int EvalueerAbsoluut()
        {
            int evaluatie = 0;

            for (int x = 0; x < 8; x++)
            {
                for (int y = 0; y < 8; y++)
                {
                    evaluatie += Stuk.Waarde(getStuk(x, y));
                }
            }
            return(evaluatie);
        }
示例#5
0
        private void DisplayStuk(Stuk stuk, int x, int y)
        {
            //Console.WriteLine("DisplayStuk {0} x,y=({1},{2})",stuk,x,y);
            OvalShape shape = speler.doos.HaalOp(stuk);

            if (shape == null)
            {
                MessageBox.Show(string.Format("stuk {0} niet gevonden in doos", stuk.type));
            }
            else
            {
                shape.Location = speler.getBordLocation(x, y);
            }
        }
示例#6
0
 public int VoerUit(Zet zet)
 {
     //Check(zet,false);
     //
     // Check for Mat.
     //
     zet.mat = zet.naar.stuk.type == StukType.Koning;
     //
     // Voer zet uit op het bord.
     //
     if (zet.van == null)             //Vanuit doos
     {
         veld[zet.naar.x, zet.naar.y] = setStuk(zet.naar.stuk);
     }
     else
     {
         veld[zet.naar.x, zet.naar.y] = veld[zet.van.x, zet.van.y];
         veld[zet.van.x, zet.van.y]   = (int)StukType.geen;
     }
     if (zet.promotie)
     {
         Stuk dame = new Stuk(zet.van.stuk.kleur, StukType.Dame);
         veld[zet.naar.x, zet.naar.y] = setStuk(dame);
         evaluatie += Stuk.Waarde(dame);
         evaluatie -= zet.van.stuk.waarde;
     }
     if (zet.castling)             //V105
     {
         bool longCastling = zet.naar.x < 4;
         if (longCastling)
         {
             veld[3, zet.van.y] = veld[0, zet.van.y];
             veld[0, zet.van.y] = 0;
         }
         else
         {
             veld[5, zet.van.y] = veld[7, zet.van.y];
             veld[7, zet.van.y] = 0;
         }
         evaluatie += (zet.van.stuk.kleur) ? 1 : -1;
     }
     //
     // Bepaal evaluatie.
     //
     evaluatie -= zet.naar.stuk.waarde;
     return(evaluatie); // absolute bordwaarde;
 }
示例#7
0
        /// <summary>
        /// Haal stuk uit doos.
        /// </summary>
        /// <param name="stuk"></param>
        /// <returns></returns>
        public OvalShape HaalOp(Stuk stuk)
        {
            OvalShape shape = null;
            string    key   = string.Format("Chess_{0}{1}", pieces[(int)stuk.type - 1], stuk.kleur ? "l" : "d");

            foreach (OvalShape item in inDoos)
            {
                if (item.Name.Contains(key))
                {
                    shape = item;
                    break;
                }
            }
            Console.WriteLine("HaalStukUitDoos {0}", shape == null ? "nothing" : shape.Name);
            inDoos.Remove(shape);
            return(shape);
        }
示例#8
0
        public Veld(string coor)
        {
            int p = coor.Length - 2; // last 2 chars = coordinate.

            x = coor[p] - 'a';
            y = 8 - coor[p + 1] + '0';
            if (x < 0 || x > 7 || y < 0 || y > 7)
            {
                throw new Exception("Veld coordinates out of range");
            }
            //
            // bepaal kleur en stuk
            //
            bool kleur = coor[0] != '-';
            char c     = coor[kleur ? 0 : 1];

            this.stuk = new Stuk(kleur, c);
        }
示例#9
0
        internal static int Waarde(Stuk stuk)
        {
            int waarde;

            switch (stuk.type)
            {
            case StukType.Koning:   waarde = 100; break;

            case StukType.Dame:     waarde = 9; break;

            case StukType.Toren:    waarde = 5; break;

            case StukType.Loper:    waarde = 3; break;

            case StukType.Paard:    waarde = 3; break;

            case StukType.pion:     waarde = 1; break;

            case StukType.geen:     waarde = 0; break;

            default: throw new ArgumentException();
            }
            return((stuk.kleur)?waarde:-waarde);
        }
示例#10
0
        /// <summary>
        /// Voer grafisch de zet uit op schaakbord.
        /// </summary>
        /// <param name="zet"></param>
        public void VoerUit(Zet zet)
        {
            OvalShape shape = null;

            if (zet.van != null)
            {
                shape = getShape(zet.van); // shape != null when pressing notation arrows.
            }
            if (shape == null)
            {
                shape = selectedShape;               // Shape is null when dragged.
            }
            if (animate)
            {
                Animate(shape, getBordLocation(zet.naar.x, zet.naar.y)); //V145
            }
            //
            // Berg geslagen stuk op in doos.
            //
            doos.BergOp(getShape(zet.naar)); //V129
            if (zet.promotie)
            {
                doos.BergOp(shape); // Pion
                Stuk dame = new Stuk(zet.van.stuk.kleur, StukType.Dame);
                shape = doos.HaalOp(dame);
            }
            shape.Location = getBordLocation(zet.naar.x, zet.naar.y);
            if (zet.castling)
            {
                Zet  toren        = new Zet();
                bool longCastling = zet.naar.x < 4;
                toren.van  = new Veld((longCastling) ? 0 : 7, zet.van.y);
                toren.naar = new Veld((longCastling) ? 3 : 5, zet.van.y);//V105++
                VoerUit(toren);
            }
        }
示例#11
0
        public IEnumerable <Zet> DoeEenZet(Veld huidigveld)
        {
            Zet zet = new Zet();

            zet.van = huidigveld;
            Stuk stuk = huidigveld.stuk;

            Point[] direction = DirectionTable[(stuk.type == StukType.pion && stuk.kleur == Kleur.ZWART)?0:(int)stuk.type];
            int     steps     = (stuk.type == StukType.Dame ||
                                 stuk.type == StukType.Toren ||
                                 stuk.type == StukType.Loper)? 8 : 1; // 7 is voldoende.

            //
            // Herhaal voor iedere zetrichting tot bezet veld of buiten bord.
            //
            for (int richting = 0; richting < direction.Length; richting++)
            {
                for (int step = 1; step <= steps; step++)
                {
                    int x = zet.van.x + step * direction[richting].X;
                    int y = zet.van.y + step * direction[richting].Y;
                    if (BuitenBord(x, y))
                    {
                        break;
                    }
                    #region Pion en Koning
                    if (stuk.type == StukType.pion)
                    {
                        zet.promotie = (y == 0 || y == 7);
                        if (zet.van.y != 1 && zet.van.y != 6 && richting == 3)
                        {
                            yield break;                                                    // Pion alleen 2 vooruit vanaf rij 1 of 6
                        }
                    }
                    if (stuk.type == StukType.Koning && richting < 2)                     //V105 Castling.
                    {
                        if (zet.van.x != 4 || (zet.van.y != ((stuk.kleur)?7:0)))
                        {
                            break;
                        }
                        bool longCastling = x < 4;
                        if (longCastling)
                        {
                            if (Bord.veld[0, y] != ((int)StukType.Toren) * ((stuk.kleur) ? 1 : -1))
                            {
                                break;
                            }
                            if (Bord.veld[1, y] != 0)
                            {
                                break;
                            }
                            if (Bord.veld[2, y] != 0)
                            {
                                break;
                            }
                            if (Bord.veld[3, y] != 0)
                            {
                                break;
                            }
                        }
                        else
                        {
                            if (Bord.veld[5, y] != 0)
                            {
                                break;
                            }
                            if (Bord.veld[6, y] != 0)
                            {
                                break;
                            }
                            if (Bord.veld[7, y] != ((int)StukType.Toren) * ((stuk.kleur) ? 1 : -1))
                            {
                                break;
                            }
                        }
                        //
                        // Staat koning schaak? --> Dan geen roccade.
                        //
                        if (IsSchaak(stuk.kleur))
                        {
                            break;                       //V139
                        }
                        zet.naar     = new Veld(x, y);
                        zet.castling = true;
                        yield return(zet);

                        zet.castling = false;
                        break;
                    }
                    #endregion
                    if (Bord.veld[x, y] == 0)
                    {
                        if (stuk.type == StukType.pion && richting < 2)
                        {
                            break;
                        }
                        zet.naar = new Veld(x, y);
                        yield return(zet);
                    }
                    else // Naar veld bevat een stuk.
                    {
                        if (stuk.type == StukType.pion && richting >= 2)
                        {
                            yield break;                                  // V104 Zoek niet verder in andere richtingen.
                        }
                        if (huidigveld.stuk.kleur == Bord.veld[x, y] < 0) //SLAG
                        {
                            zet.naar = new Veld(x, y);
                            yield return(zet);
                        }
                        break;
                    }
                }
            }
        }
示例#12
0
 internal bool IsEqual(Stuk stuk)
 {
     return(kleur == stuk.kleur && type == stuk.type);
 }
示例#13
0
 public Veld(int x, int y, bool kleur, StukType stukType)
 {
     this.x    = x;
     this.y    = y;
     this.stuk = new Stuk(kleur, stukType);
 }
示例#14
0
 public Veld(int x, int y)
 {
     this.x    = x;
     this.y    = y;
     this.stuk = Bord.getStuk(x, y);
 }
示例#15
0
 private int setStuk(Stuk stuk)
 {
     return((stuk.kleur)?(int)stuk.type:-(int)stuk.type);
 }