private void ImporterDepuisUnFichier(string path) { string nom, date, symbole; char[,] tab; using (StreamReader reader = new StreamReader(fileNameImport)) { while ((reader.ReadLine()) != null) { nom = reader.ReadLine(); date = reader.ReadLine(); symbole = reader.ReadLine(); tab = new char[symbole.Length, symbole.Length]; for (int i = 0; i < symbole.Length; i++) { char[] ligne = reader.ReadLine().ToCharArray(); int j = 0; foreach (char c in ligne) { tab[i, j] = c; j++; // Console.WriteLine(c); } } Grille g = new Grille(nom, date, symbole, tab); GrilleList.Add(g); } } }
private void AjouteLigColGrid(Grille g) { for (int i = 0; i < g.size; i++) { AfficheGrid.ColumnDefinitions.Add(new ColumnDefinition()); AfficheGrid.RowDefinitions.Add(new RowDefinition()); } }
private void InitialiserGrille() { InitialiserLesComposants(); Grille g = App.SudokuViewModels.GrilleSelect; AjouteLigColGrid(g); CréerLesComposantsDeGrille(g); EtatButtonResoluUnHypo(); EtatButtonResoluDeuxHypo(); EtatButtonResoluGrille(); }
private void ResoluGrilleButton_Click(object sender, RoutedEventArgs e) { //MessageBox.Show("ok"); Grille gr = App.SudokuViewModels.GrilleSelect; Boolean grilleResolu = false; while (!grilleResolu) { first : while (gr.numberCaseUnHypo != 0) { for (int i = 0; i < gr.size; i++) { for (int j = 0; j < gr.size; j++) { if (gr.TabCase[i, j].Valeur.Equals('.') && gr.TabCase[i, j].NbHypothese == 1) { if (ResolutionUnHypothese(gr)) { } } } } } if (gr.numberCaseResoluer != 0 && gr.numberCaseUnHypo == 0) { while (gr.numberCaseDeuxHypo != 0 && gr.numberCaseUnHypo == 0) { for (int i = 0; i < gr.size; i++) { for (int j = 0; j < gr.size; j++) { if (gr.TabCase[i, j].Valeur.Equals('.') && gr.TabCase[i, j].NbHypothese == 2) { if (ResolutionDeuxHypotheses(gr)) { } } } } } } if (gr.numberCaseResoluer != 0 && gr.numberCaseUnHypo != 0) { goto first; } if (gr.numberCaseResoluer == 0 || gr.numberCaseUnHypo == 0) { grilleResolu = true; } } }
private void CréerLesComposantsDeGrille(Grille g) { for (int i = 0; i < g.size; i++) { string s = ""; for (int j = 0; j < g.size; j++) { string TextToolTip = App.SudokuViewModels.GrilleSelect.TabCase[j, i].HypothesesToString; // Ajouter le text sur griille TextBlock tb = new TextBlock(); tb.ToolTip = TextToolTip; tb.HorizontalAlignment = HorizontalAlignment.Center; tb.VerticalAlignment = VerticalAlignment.Center; tb.FontWeight = FontWeights.UltraBold; tb.Text = g.TabCase[j, i].Valeur.ToString(); // lbl.Parent = AfficheGrid; if (g.TabGrille[j, i] == '.') { if (TextToolTip.Length == 1) { tb.Foreground = new SolidColorBrush(Colors.YellowGreen); } else if (TextToolTip.Length == 2) { tb.Foreground = new SolidColorBrush(Colors.SeaGreen); } else { tb.Foreground = new SolidColorBrush(Colors.Red); } } Grid.SetColumn(tb, i); Grid.SetRow(tb, j); AfficheGrid.Children.Add(tb); s += g.TabGrille[i, j].ToString(); } // Ajouter le grille à resoluer AjouterSodukoàResolu(s); } }
private Boolean ResolutionDeuxHypotheses(Grille g) { Boolean caseResolu = false; Grille gr = g; for (int i = 0; i < gr.size; i++) { for (int j = 0; j < gr.size; j++) { if (gr.TabCase[i, j].NbHypothese == 2 && (!gr.TabCase[i, j].ColonneJumeauDéjaFait) && gr.Aunjumeau(i, j)) { //MessageBox.Show("On va changer la valeur de [" + (i + 1) + "," + (j + 1) + "];"); InitialiserGrille(); caseResolu = true; goto Exit; } /* * else if (gr.TabCase[i, j].NbHypothese == 2) * { * MessageBox.Show(i + "-" + j + " n a pas un jumeau dans carré "); * goto Exit; * } * / * /* * gr.TabGrille[i, j] = gr.TabCase[i, j].Valeur; * gr.ChangerLaValeurDuTab(i, j, gr.TabCase[i, j].Hypotheses[0]); * gr.GrilleMiseàjour(); * RepaintGrille(); */ } } Exit :; return(caseResolu); }
private void CréerLesComposantsDeGrille(Grille g) { for (int i = 0; i < g.size; i++) { string s = ""; for (int j = 0; j < g.size; j++) { string TextToolTip = App.SudokuViewModels.GrilleSelect.TabCase[j, i].HypothesesToString; // Ajouter le text sur griille TextBlock tb = new TextBlock(); tb.ToolTip = TextToolTip; tb.HorizontalAlignment = HorizontalAlignment.Center; tb.VerticalAlignment = VerticalAlignment.Center; tb.FontWeight = FontWeights.UltraBold; tb.Text = g.TabCase[j, i].Valeur.ToString(); // lbl.Parent = AfficheGrid; if (g.TabGrille[j, i] == '.') { if (TextToolTip.Length == 1) tb.Foreground = new SolidColorBrush(Colors.YellowGreen); else if (TextToolTip.Length == 2) tb.Foreground = new SolidColorBrush(Colors.SeaGreen); else tb.Foreground = new SolidColorBrush(Colors.Red); } Grid.SetColumn(tb, i); Grid.SetRow(tb, j); AfficheGrid.Children.Add(tb); s += g.TabGrille[i, j].ToString(); } // Ajouter le grille à resoluer AjouterSodukoàResolu(s); } }
private Boolean ResolutionUnHypothese(Grille g) { Boolean caseResolu = false; Grille gr = g; for (int i = 0; i < gr.size; i++) { for (int j = 0; j < gr.size; j++) { if (gr.TabCase[i, j].NbHypothese == 1 && gr.TabCase[i, j].Valeur.Equals('.')) { // MessageBox.Show("On va changer la valeur de [" + (i + 1) + "," + (j + 1) + "];"); gr.TabGrille[i, j] = gr.TabCase[i, j].Valeur; gr.ChangerLaValeurDuTab(i, j, gr.TabCase[i, j].Hypotheses[0]); gr.GrilleMiseàjour(); InitialiserGrille(); caseResolu = true; goto Exit; } } } Exit : return(caseResolu); }
private void ImporterDepuisUnFichier(string path) { string nom, date, symbole; char[,] tab; using (StreamReader reader = new StreamReader(fileNameImport)) { while ((reader.ReadLine()) != null) { nom = reader.ReadLine(); date = reader.ReadLine(); symbole = reader.ReadLine(); tab = new char[symbole.Length, symbole.Length]; for (int i = 0; i < symbole.Length; i++) { char[] ligne = reader.ReadLine().ToCharArray(); int j = 0; foreach (char c in ligne) { tab[i, j] = c; j++; // Console.WriteLine(c); } } Grille g = new Grille(nom,date,symbole,tab); GrilleList.Add(g); } } }
private Boolean ResolutionUnHypothese(Grille g) { Boolean caseResolu = false; Grille gr = g; for (int i = 0; i < gr.size; i++) { for (int j = 0; j < gr.size; j++) { if (gr.TabCase[i, j].NbHypothese == 1 && gr.TabCase[i, j].Valeur.Equals('.')) { // MessageBox.Show("On va changer la valeur de [" + (i + 1) + "," + (j + 1) + "];"); gr.TabGrille[i, j] = gr.TabCase[i, j].Valeur; gr.ChangerLaValeurDuTab(i, j, gr.TabCase[i, j].Hypotheses[0]); gr.GrilleMiseàjour(); InitialiserGrille(); caseResolu = true; goto Exit; } } } Exit: return caseResolu; }
private Boolean ResolutionDeuxHypotheses(Grille g) { Boolean caseResolu = false; Grille gr = g; for (int i = 0; i < gr.size; i++) { for (int j = 0; j < gr.size; j++) { if (gr.TabCase[i, j].NbHypothese == 2 && (!gr.TabCase[i, j].ColonneJumeauDéjaFait) && gr.Aunjumeau(i, j)) { //MessageBox.Show("On va changer la valeur de [" + (i + 1) + "," + (j + 1) + "];"); InitialiserGrille(); caseResolu = true; goto Exit; } /* else if (gr.TabCase[i, j].NbHypothese == 2) { MessageBox.Show(i + "-" + j + " n a pas un jumeau dans carré "); goto Exit; } * / /* * gr.TabGrille[i, j] = gr.TabCase[i, j].Valeur; gr.ChangerLaValeurDuTab(i, j, gr.TabCase[i, j].Hypotheses[0]); gr.GrilleMiseàjour(); RepaintGrille(); */ } } Exit: ; return caseResolu; }
public void boucle() { while (true) { int direction = Grille.r.Next() % 4; Grille.bouger(direction, this); if (porte == null) { //reflechir si on prend ou pas for (int i = -1; i < 2; i++) { for (int j = -1; j < 2; j++) { if (x + i >= 0 && x + i < Grille.getMap().Length&& y + j >= 0 && y + j < Grille.getMap()[x].Length && Grille.getMap()[x + i][y + j].contenu != null && !Grille.getMap()[x + i][y + j].contenu.affichage().Contains("Agent")) { //on regarde si on prend ou pas double probaprise = (Grille.kplus / Math.Pow(Grille.kplus + historique.Where(x1 => x1.Equals(Grille.getMap()[x + i][y + j].contenu.affichage())).Count() / 20, 2)); double chance = (double)Grille.r.Next(1000) / (double)1000; if (chance < probaprise) { porte = Grille.getMap()[x + i][y + j].contenu; Grille.getMap()[x + i][y + j].contenu = null; break; } } } if (porte != null) { break; } } if (porte != null) { historique.Add(porte.affichage()[0]); } else { historique.Add('0'); } if (historique.Count > 10) { historique.RemoveAt(0); } } else { double freq = 0; int xlibre = -1, ylibre = -1; for (int i = -1; i < 2; i++) { for (int j = -1; j < 2; j++) { if (x + i >= 0 && x + i < Grille.getMap().Length&& y + j >= 0 && y + j < Grille.getMap()[x].Length && Grille.getMap()[x + i][y + j].contenu != null && Grille.getMap()[x + i][y + j].contenu.affichage() == porte.affichage()) { freq++; } else if (x + i >= 0 && x + i < Grille.getMap().Length&& y + j >= 0 && y + j < Grille.getMap()[x].Length && Grille.getMap()[x + i][y + j].contenu == null) { if (xlibre == -1) { xlibre = x + i; ylibre = y + j; } } } } freq /= 8; if (xlibre != -1) { double probaprise = Math.Pow((freq) / (Grille.kmoins + freq), 2); double chance = (double)Grille.r.Next(1000) / (double)1000; if (chance < probaprise) { Grille.getMap()[xlibre][ylibre].contenu = porte; porte = null; } } } System.Threading.Thread.Sleep((int)(10)); } }