avent modif algo recherche ter
This commit is contained in:
		
							
								
								
									
										303
									
								
								go01/Goban.cs
									
									
									
									
									
								
							
							
						
						
									
										303
									
								
								go01/Goban.cs
									
									
									
									
									
								
							@@ -15,6 +15,15 @@ namespace go01
 | 
			
		||||
        public Form Fenetre;
 | 
			
		||||
        public int dim;
 | 
			
		||||
        Label LabelPlayerTurn;
 | 
			
		||||
        struct carrefour_S
 | 
			
		||||
        {
 | 
			
		||||
            public Point pointCourant, pointSuivant;
 | 
			
		||||
            public carrefour_S(Point pointCourant, Point pointSuivant)
 | 
			
		||||
            {
 | 
			
		||||
                this.pointCourant = pointCourant;
 | 
			
		||||
                this.pointSuivant = pointSuivant;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        string playerWName, playerBName;
 | 
			
		||||
        enum Occupant_E { Vide, Blanc, Noir, LAST}
 | 
			
		||||
        public enum Joueur_E { Blanc, Noir, LAST}
 | 
			
		||||
@@ -40,7 +49,7 @@ namespace go01
 | 
			
		||||
                    SizeF stringSize = new SizeF();
 | 
			
		||||
                    stringSizebg = gr.MeasureString((tour == Joueur_E.Blanc) ? playerWName : playerBName, fbg);
 | 
			
		||||
                    stringSize = gr.MeasureString((tour == Joueur_E.Blanc) ? playerWName : playerBName, f);
 | 
			
		||||
                    
 | 
			
		||||
 | 
			
		||||
                    gr.DrawString((tour == Joueur_E.Blanc) ? playerWName : playerBName, fbg, new SolidBrush(Color.Black), new Point((int)(Conteneur.Location.X + Conteneur.Width + ((Fenetre.ClientSize.Width - Conteneur.Location.X - Conteneur.Width - stringSizebg.Width) / 2)), Conteneur.Location.Y));
 | 
			
		||||
                    gr.DrawString((tour == Joueur_E.Blanc) ? playerWName : playerBName, f, new SolidBrush(Color.White), new Point((int)(Conteneur.Location.X + Conteneur.Width + ((Fenetre.ClientSize.Width - Conteneur.Location.X - Conteneur.Width - stringSizebg.Width) / 2) + (stringSizebg.Width - stringSize.Width) / 2), (int)(Conteneur.Location.Y + ((stringSizebg.Height - stringSize.Height) / 2))));
 | 
			
		||||
                }*/
 | 
			
		||||
@@ -58,7 +67,7 @@ namespace go01
 | 
			
		||||
 | 
			
		||||
            playerWName = playerW;
 | 
			
		||||
            playerBName = playerB;
 | 
			
		||||
            
 | 
			
		||||
 | 
			
		||||
            //label qui indique à qui le tour
 | 
			
		||||
            LabelPlayerTurn = new System.Windows.Forms.Label();
 | 
			
		||||
            this.LabelPlayerTurn.AutoSize = true;
 | 
			
		||||
@@ -119,33 +128,39 @@ namespace go01
 | 
			
		||||
            PictureBox pb = (PictureBox)sender;
 | 
			
		||||
            String[] xy = ((PictureBox)sender).Name.Split(';');
 | 
			
		||||
            Console.WriteLine($"{xy[0]};{xy[1]}");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            if (tableauOccupation[int.Parse(xy[0]), int.Parse(xy[1])] == Occupant_E.Vide)
 | 
			
		||||
            {
 | 
			
		||||
                tableauOccupation[int.Parse(xy[0]), int.Parse(xy[1])] = (Tour == Joueur_E.Blanc) ? Occupant_E.Blanc : Occupant_E.Noir;
 | 
			
		||||
                Tour = (Tour+1 == Joueur_E.LAST) ? Joueur_E.Blanc : Tour+1;
 | 
			
		||||
            }
 | 
			
		||||
                
 | 
			
		||||
 | 
			
		||||
            using (Graphics gr = Graphics.FromHwnd((pb.Handle)))
 | 
			
		||||
            {
 | 
			
		||||
                SolidBrush b = null;
 | 
			
		||||
                switch(tableauOccupation[int.Parse(xy[0]), int.Parse(xy[1])])
 | 
			
		||||
                //Tour = (Tour+1 == Joueur_E.LAST) ? Joueur_E.Blanc : Tour+1;
 | 
			
		||||
                using (Graphics gr = Graphics.FromHwnd((pb.Handle)))
 | 
			
		||||
                {
 | 
			
		||||
                    case Occupant_E.Blanc:
 | 
			
		||||
                        b = new SolidBrush(Color.White);
 | 
			
		||||
                        break;
 | 
			
		||||
                    case Occupant_E.Noir:
 | 
			
		||||
                        b = new SolidBrush(Color.Black);
 | 
			
		||||
                        break;
 | 
			
		||||
                    case Occupant_E.Vide:
 | 
			
		||||
                        b = null;
 | 
			
		||||
                        break;
 | 
			
		||||
                    SolidBrush b = null;
 | 
			
		||||
                    switch (tableauOccupation[int.Parse(xy[0]), int.Parse(xy[1])])
 | 
			
		||||
                    {
 | 
			
		||||
                        case Occupant_E.Blanc:
 | 
			
		||||
                            b = new SolidBrush(Color.White);
 | 
			
		||||
                            break;
 | 
			
		||||
                        case Occupant_E.Noir:
 | 
			
		||||
                            b = new SolidBrush(Color.Black);
 | 
			
		||||
                            break;
 | 
			
		||||
                        case Occupant_E.Vide:
 | 
			
		||||
                            b = null;
 | 
			
		||||
                            break;
 | 
			
		||||
                    }
 | 
			
		||||
                    if (b != null)
 | 
			
		||||
                        gr.FillEllipse(b, 1, 0, pb.ClientSize.Width - 2, pb.ClientSize.Height - 1);
 | 
			
		||||
                    else
 | 
			
		||||
                        gr.DrawImage(pb.Image, 0, 0, pb.Width, pb.Height);
 | 
			
		||||
                }
 | 
			
		||||
                if (b != null)
 | 
			
		||||
                    gr.FillEllipse(b, 1,0, pb.ClientSize.Width-2, pb.ClientSize.Height-1);
 | 
			
		||||
                else
 | 
			
		||||
                    gr.DrawImage(pb.Image, 0, 0, pb.Width, pb.Height);
 | 
			
		||||
 | 
			
		||||
                RechercheTeritoir(int.Parse(xy[0]), int.Parse(xy[1]));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
        private int[] GetXY(int i)
 | 
			
		||||
        {
 | 
			
		||||
@@ -167,47 +182,235 @@ namespace go01
 | 
			
		||||
 | 
			
		||||
        void RechercheTeritoir(int x, int y)
 | 
			
		||||
        {
 | 
			
		||||
            List<Point> carrefour = new List<Point>();
 | 
			
		||||
            List<carrefour_S> carrefour = new List<carrefour_S>();
 | 
			
		||||
            Point origine = new Point(x, y);
 | 
			
		||||
            Point pointCourant = new Point(x, y);
 | 
			
		||||
            Point pointPrecedent;
 | 
			
		||||
            Point pointSuivant, pointPrec;
 | 
			
		||||
            Point min = new Point(x, y), max = new Point(x, y);
 | 
			
		||||
            bool[,] tmpParcour = new bool[dim, dim];
 | 
			
		||||
            tmpParcour[origine.X, origine.Y] = true;
 | 
			
		||||
            pointSuivant = RecherchePointSuivant(pointCourant, new Point(-1,-1), tmpParcour, carrefour);
 | 
			
		||||
            pointPrec = pointCourant;
 | 
			
		||||
            pointCourant = pointSuivant;
 | 
			
		||||
            if (pointSuivant.X != -1)
 | 
			
		||||
            {
 | 
			
		||||
                tmpParcour[pointCourant.X, pointCourant.Y] = true;
 | 
			
		||||
                while ((pointSuivant = RecherchePointSuivant(pointCourant, pointPrec, tmpParcour, carrefour)).X != -1 || carrefour.Count > 0)
 | 
			
		||||
                {
 | 
			
		||||
                    using (Graphics gr = Graphics.FromHwnd((pboxList[xyToi(pointCourant.X, pointCourant.Y)].Handle)))
 | 
			
		||||
                    {
 | 
			
		||||
                        SolidBrush b = new SolidBrush(Color.Red);
 | 
			
		||||
 | 
			
		||||
                        if (b != null)
 | 
			
		||||
                            gr.FillEllipse(b, 1, 0, pboxList[xyToi(pointCourant.X, pointCourant.Y)].ClientSize.Width - 2, pboxList[xyToi(pointCourant.X, pointCourant.Y)].ClientSize.Height - 1);
 | 
			
		||||
                        else
 | 
			
		||||
                            gr.DrawImage(pboxList[xyToi(pointCourant.X, pointCourant.Y)].Image, 0, 0, pboxList[xyToi(pointCourant.X, pointCourant.Y)].Width, pboxList[xyToi(pointCourant.X, pointCourant.Y)].Height);
 | 
			
		||||
                    }
 | 
			
		||||
                    foreach(carrefour_S c in carrefour)
 | 
			
		||||
                    {
 | 
			
		||||
                        using (Graphics gr = Graphics.FromHwnd((pboxList[xyToi(c.pointSuivant.X, c.pointSuivant.Y)].Handle)))
 | 
			
		||||
                        {
 | 
			
		||||
                            SolidBrush b = new SolidBrush(Color.Orange);
 | 
			
		||||
 | 
			
		||||
                            if (b != null)
 | 
			
		||||
                                gr.FillEllipse(b, 1, 0, pboxList[xyToi(c.pointSuivant.X, c.pointSuivant.Y)].ClientSize.Width - 2, pboxList[xyToi(c.pointSuivant.X, c.pointSuivant.Y)].ClientSize.Height - 1);
 | 
			
		||||
                            else
 | 
			
		||||
                                gr.DrawImage(pboxList[xyToi(pointCourant.X, pointCourant.Y)].Image, 0, 0, pboxList[xyToi(pointCourant.X, pointCourant.Y)].Width, pboxList[xyToi(pointCourant.X, pointCourant.Y)].Height);
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    System.Threading.Thread.Sleep(500);
 | 
			
		||||
                    Console.WriteLine("Debut Boucle");
 | 
			
		||||
                    printTab(tmpParcour);
 | 
			
		||||
                    if (pointSuivant.X == -1)
 | 
			
		||||
                    {
 | 
			
		||||
                        pointSuivant = new Point(carrefour[carrefour.Count - 1].pointSuivant.X, carrefour[carrefour.Count - 1].pointSuivant.Y);
 | 
			
		||||
                        tmpParcour[pointSuivant.X, pointSuivant.Y] = true;
 | 
			
		||||
                        pointPrec = new Point(carrefour[carrefour.Count - 1].pointCourant.X, carrefour[carrefour.Count - 1].pointCourant.Y);
 | 
			
		||||
                        pointCourant = pointSuivant;
 | 
			
		||||
                        carrefour.RemoveAt(carrefour.Count - 1);
 | 
			
		||||
                    }
 | 
			
		||||
                    else if (tmpParcour[pointSuivant.X, pointSuivant.Y] || ptEgal(pointSuivant, pointPrec))
 | 
			
		||||
                    {
 | 
			
		||||
                        if (carrefour.Count > 0 && !ptEgal(pointSuivant, origine))
 | 
			
		||||
                        {
 | 
			
		||||
                            pointSuivant = new Point(carrefour[carrefour.Count - 1].pointSuivant.X, carrefour[carrefour.Count - 1].pointSuivant.Y);
 | 
			
		||||
                            tmpParcour[pointSuivant.X, pointSuivant.Y] = true;
 | 
			
		||||
                            pointPrec = new Point(carrefour[carrefour.Count - 1].pointCourant.X, carrefour[carrefour.Count - 1].pointCourant.Y);
 | 
			
		||||
                            pointCourant = pointSuivant;
 | 
			
		||||
                            carrefour.RemoveAt(carrefour.Count - 1);
 | 
			
		||||
                            
 | 
			
		||||
                            if (ptEgal(pointSuivant, origine))
 | 
			
		||||
                                break;
 | 
			
		||||
                        }
 | 
			
		||||
                        else if (ptEgal(pointSuivant, origine))
 | 
			
		||||
                        {
 | 
			
		||||
                            Console.WriteLine("teritoir trouver");
 | 
			
		||||
                            printTab(tmpParcour);
 | 
			
		||||
                            break;
 | 
			
		||||
                        }
 | 
			
		||||
                        else
 | 
			
		||||
                        {
 | 
			
		||||
                            Console.WriteLine("teritoir non trouver");
 | 
			
		||||
                            printTab(tmpParcour);
 | 
			
		||||
                            break;
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    else
 | 
			
		||||
                    {
 | 
			
		||||
                        tmpParcour[pointSuivant.X, pointSuivant.Y] = true;
 | 
			
		||||
                        pointPrec = pointCourant;
 | 
			
		||||
                        pointCourant = pointSuivant;
 | 
			
		||||
                    }
 | 
			
		||||
                    printTab(tmpParcour);
 | 
			
		||||
 | 
			
		||||
                }
 | 
			
		||||
                redrawAllpb();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        Point RecherchePointSuivant(Point p, ref List<Point> carrefour)
 | 
			
		||||
        Point RecherchePointSuivant(Point p, Point ptPrec, bool[,] parcout, List<carrefour_S> carrefour)
 | 
			
		||||
        {
 | 
			
		||||
            Occupant_E occupant = (Tour == Joueur_E.Blanc)?Occupant_E.Blanc:Occupant_E.Noir;
 | 
			
		||||
            bool trouver = false;
 | 
			
		||||
            if ()
 | 
			
		||||
            Point pRet = new Point(-1, -1);
 | 
			
		||||
            if (tableauOccupation[p.X,p.Y-1] == occupant)
 | 
			
		||||
            {
 | 
			
		||||
           
 | 
			
		||||
                if(trouver && !parcout[p.X,p.Y-1])
 | 
			
		||||
                    carrefour.Add(new carrefour_S(new Point(p.X,p.Y), new Point(p.X,p.Y-1)));
 | 
			
		||||
                else if(!ptEgal(ptPrec, new Point(p.X,p.Y-1)))
 | 
			
		||||
                {
 | 
			
		||||
                    pRet = new Point(p.X,p.Y-1);
 | 
			
		||||
                    trouver = true;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            if ()
 | 
			
		||||
            if (tableauOccupation[p.X+1,p.Y-1] == occupant)
 | 
			
		||||
            {
 | 
			
		||||
                if(trouver && !parcout[p.X+1,p.Y-1])
 | 
			
		||||
                    carrefour.Add(new carrefour_S(new Point(p.X, p.Y), new Point(p.X+1,p.Y-1)));
 | 
			
		||||
                else if(!ptEgal(ptPrec, new Point(p.X+1,p.Y-1)))
 | 
			
		||||
                {
 | 
			
		||||
                    pRet = new Point(p.X+1,p.Y-1);
 | 
			
		||||
                    trouver = true;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            if (tableauOccupation[p.X+1,p.Y] == occupant)
 | 
			
		||||
            {
 | 
			
		||||
                if(trouver && !parcout[p.X+1,p.Y])
 | 
			
		||||
                    carrefour.Add(new carrefour_S(new Point(p.X, p.Y), new Point(p.X+1,p.Y)));
 | 
			
		||||
                else if(!ptEgal(ptPrec, new Point(p.X+1,p.Y)))
 | 
			
		||||
                {
 | 
			
		||||
                    pRet = new Point(p.X+1,p.Y);
 | 
			
		||||
                    trouver = true;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            if (tableauOccupation[p.X+1,p.Y+1] == occupant)
 | 
			
		||||
            {
 | 
			
		||||
                if(trouver && !parcout[p.X+1,p.Y+1])
 | 
			
		||||
                    carrefour.Add(new carrefour_S(new Point(p.X, p.Y), new Point(p.X+1,p.Y+1)));
 | 
			
		||||
                else if(!ptEgal(ptPrec, new Point(p.X+1,p.Y+1)))
 | 
			
		||||
                {
 | 
			
		||||
                    pRet = new Point(p.X+1,p.Y+1);
 | 
			
		||||
                    trouver = true;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            if (tableauOccupation[p.X,p.Y+1] == occupant)
 | 
			
		||||
            {
 | 
			
		||||
                if(trouver && !parcout[p.X,p.Y+1])
 | 
			
		||||
                    carrefour.Add(new carrefour_S(new Point(p.X, p.Y), new Point(p.X,p.Y+1)));
 | 
			
		||||
                else if(!ptEgal(ptPrec, new Point(p.X,p.Y+1)))
 | 
			
		||||
                {
 | 
			
		||||
                    pRet = new Point(p.X,p.Y+1);
 | 
			
		||||
                    trouver = true;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            if (tableauOccupation[p.X-1,p.Y+1] == occupant)
 | 
			
		||||
            {
 | 
			
		||||
                if(trouver && !parcout[p.X-1,p.Y+1])
 | 
			
		||||
                    carrefour.Add(new carrefour_S(new Point(p.X, p.Y), new Point(p.X-1,p.Y+1)));
 | 
			
		||||
                else if(!ptEgal(ptPrec, new Point(p.X-1,p.Y+1)))
 | 
			
		||||
                {
 | 
			
		||||
                    pRet = new Point(p.X-1,p.Y+1);
 | 
			
		||||
                    trouver = true;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            if (tableauOccupation[p.X-1,p.Y] == occupant)
 | 
			
		||||
            {
 | 
			
		||||
                if(trouver && !parcout[p.X-1,p.Y])
 | 
			
		||||
                    carrefour.Add(new carrefour_S(new Point(p.X, p.Y), new Point(p.X-1,p.Y)));
 | 
			
		||||
                else if(!ptEgal(ptPrec, new Point(p.X-1,p.Y)))
 | 
			
		||||
                {
 | 
			
		||||
                    pRet = new Point(p.X-1,p.Y);
 | 
			
		||||
                    trouver = true;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            if (tableauOccupation[p.X-1,p.Y-1] == occupant)
 | 
			
		||||
            {
 | 
			
		||||
                if(trouver && !parcout[p.X-1,p.Y-1])
 | 
			
		||||
                    carrefour.Add(new carrefour_S(new Point(p.X, p.Y), new Point(p.X-1,p.Y-1)));
 | 
			
		||||
                else if(!ptEgal(ptPrec, new Point(p.X-1,p.Y-1)))
 | 
			
		||||
                {
 | 
			
		||||
                    pRet = new Point(p.X-1,p.Y-1);
 | 
			
		||||
                    trouver = true;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            return pRet;
 | 
			
		||||
        }
 | 
			
		||||
        Boolean ptEgal(Point pt1, Point pt2)
 | 
			
		||||
        {
 | 
			
		||||
            return pt1.X == pt2.X && pt1.Y == pt2.Y;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
            if ()
 | 
			
		||||
        void printTab(bool[,] Tab)
 | 
			
		||||
        {
 | 
			
		||||
            for(int y = 0;y<dim;y++)
 | 
			
		||||
            {
 | 
			
		||||
 | 
			
		||||
                for (int x = 0; x < dim; x++)
 | 
			
		||||
                {
 | 
			
		||||
                    Console.ForegroundColor = Tab[x, y] ? ConsoleColor.Green : ConsoleColor.White;
 | 
			
		||||
                    Console.Write(Tab[x, y] ? '1' : '0');
 | 
			
		||||
                }
 | 
			
		||||
                Console.WriteLine();
 | 
			
		||||
            }
 | 
			
		||||
            if ()
 | 
			
		||||
            Console.WriteLine();
 | 
			
		||||
            Console.WriteLine();
 | 
			
		||||
            Console.WriteLine();
 | 
			
		||||
        }
 | 
			
		||||
        int xyToi(int x, int y)
 | 
			
		||||
        {
 | 
			
		||||
            return x + dim* y;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        void redrawAllpb()
 | 
			
		||||
        {
 | 
			
		||||
            for(int i=0;i<dim*dim;i++)
 | 
			
		||||
            {
 | 
			
		||||
                if (tableauOccupation[GetX(i), GetY(i)] != Occupant_E.Vide)
 | 
			
		||||
                {
 | 
			
		||||
                    
 | 
			
		||||
                    //Tour = (Tour+1 == Joueur_E.LAST) ? Joueur_E.Blanc : Tour+1;
 | 
			
		||||
                    using (Graphics gr = Graphics.FromHwnd((pboxList [i].Handle)))
 | 
			
		||||
                    {
 | 
			
		||||
                        SolidBrush b = null;
 | 
			
		||||
                        switch (tableauOccupation[GetX(i), GetY(i)])
 | 
			
		||||
                        {
 | 
			
		||||
                            case Occupant_E.Blanc:
 | 
			
		||||
                                b = new SolidBrush(Color.White);
 | 
			
		||||
                                break;
 | 
			
		||||
                            case Occupant_E.Noir:
 | 
			
		||||
                                b = new SolidBrush(Color.Black);
 | 
			
		||||
                                break;
 | 
			
		||||
                            case Occupant_E.Vide:
 | 
			
		||||
                                b = null;
 | 
			
		||||
                                break;
 | 
			
		||||
                        }
 | 
			
		||||
                        if (b != null)
 | 
			
		||||
                            gr.FillEllipse(b, 1, 0, pboxList[i].ClientSize.Width - 2, pboxList[i].ClientSize.Height - 1);
 | 
			
		||||
                        else
 | 
			
		||||
                            gr.DrawImage(pboxList[i].Image, 0, 0, pboxList[i].Width, pboxList[i].Height);
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            if ()
 | 
			
		||||
            {
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
            if ()
 | 
			
		||||
            {
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
            if ()
 | 
			
		||||
            {
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
            if ()
 | 
			
		||||
            {
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
            return p;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
		Reference in New Issue
	
	Block a user