コード例 #1
0
ファイル: PionIA.cs プロジェクト: 16meyrat/IADames
        private void GetMouvementsPossiblesRec(PlateauIA plateau, Stack <Tuple <int, Mouvement> > possibles, ref Coords origine, Mouvement coups, int nbPrises = 0)
        {
            Coords  tmpPos;
            PieceIA tmpPiece;

            Coords[] directions = GetDirections();
            if (coups.Sauts.Count > 0)
            {
                possibles.Push(new Tuple <int, Mouvement>(nbPrises, coups));
            }
            for (int i = 0; i < 4; i++)
            {
                tmpPos = origine + directions[i];
                if (Plateau.EstDansLePlateau(tmpPos))
                {
                    tmpPiece = plateau.Get(tmpPos);
                    if (i < 2 && nbPrises == 0)//si le mouvement est vers l'avant, sans prise
                    {
                        if (tmpPiece == null)
                        {
                            var tmp = new Mouvement(coups);
                            tmp.Sauts.Enqueue(tmpPos);
                            possibles.Push(new Tuple <int, Mouvement>(0, tmp));
                        }
                    }
                    if (tmpPiece != null && tmpPiece.EstBlanc != EstBlanc && !tmpPiece.flag)
                    {
                        tmpPos = tmpPos + directions[i];
                        if (Plateau.EstDansLePlateau(tmpPos) && plateau.Get(tmpPos) == null)
                        {
                            // flag pour ne pas ressauter des pieces
                            var tmp = new Mouvement(coups);
                            tmp.Sauts.Enqueue(tmpPos);
                            tmpPiece.flag = true;
                            GetMouvementsPossiblesRec(plateau, possibles, ref tmpPos, tmp, nbPrises + 1);
                            tmpPiece.flag = false;
                        }
                    }
                }
            }
        }
コード例 #2
0
        private bool EstMinimalementValide(PlateauIA plateau, Coords origine, Coords fin, Coords unitaire, ref int nbPrises, ref PieceIA sautee)
        {
            if (!Plateau.EstDansLePlateau(fin))
            {
                return(false);
            }

            bool    dejaPrise = false;
            var     tmp       = origine;
            PieceIA tmpPiece  = null;

            while (tmp != fin)//on se déplace en diagonale, pas besoin de tout comparer TODO:
            {
                tmp     += unitaire;
                tmpPiece = plateau.Get(tmp);
                if (tmpPiece != null)
                {
                    if (dejaPrise || tmpPiece.flag)
                    {
                        return(false);
                    }
                    else
                    {
                        dejaPrise = true;
                        sautee    = tmpPiece;
                    }
                    if (tmpPiece.EstBlanc == EstBlanc)
                    {
                        return(false);
                    }
                }
            }
            if (tmpPiece == null)
            {
                if (dejaPrise)
                {
                    nbPrises++;
                }
                return(true);
            }
            return(false);
        }