public void Contient_AvecCellulesFixésEtTrouvés() { Cellule[] cells = new Cellule[] { GénérerCellule(valeurFixe: 5, possibilités: new List <int> { 1, 2, 5 }), GénérerCellule(valeurTrouvé: 3, possibilités: new List <int> { 2, 4, 3, 6 }), GénérerCellule(possibilités: new List <int> { 1, 2, 4, 7 }), GénérerCellule(possibilités: new List <int> { 6, 7, 8 }), GénérerCellule(possibilités: new List <int> { 1, 2, 8 }) }; Groupe g = GénérerGroupe(cells); // Cellule Trouvé contenant 3 Assert.IsFalse(g.Contient(3)); // Cellule Fixée contenant 5 Assert.IsFalse(g.Contient(5)); // Cas classiques Assert.IsTrue(g.Contient(1)); Assert.IsTrue(g.Contient(6)); Assert.IsFalse(g.Contient(9)); }
public void InstantiateMap(Grid grid) { if (cellulePrefab != null) { instantiateGrid = new GameObject[grid.MapWidth, grid.MapHeight]; Vector3 bottomLeftCorner = transform.position - Vector3.right * ((grid.MapWidth / 2f) * cellulePrefab.transform.localScale.x * DEFAULT_SIZE) - Vector3.forward * ((grid.MapHeight / 2f) * cellulePrefab.transform.localScale.z * DEFAULT_SIZE); for (int i = 0; i < grid.MapWidth; i++) { for (int j = 0; j < grid.MapHeight; j++) { Cellule cellule = grid.GetCellule(i, j); Color color = GetColorFromHeight(cellule.Height); Vector3 position = bottomLeftCorner + Vector3.right * (i * cellulePrefab.transform.localScale.x * DEFAULT_SIZE) + Vector3.forward * (j * cellulePrefab.transform.localScale.z * DEFAULT_SIZE); instantiateGrid[i, j] = (GameObject)Instantiate(cellulePrefab, position, Quaternion.identity); instantiateGrid[i, j].GetComponent <Renderer>().materials[0].color = color; } } } else { throw new System.InvalidOperationException("No cellule prefabs selected"); } }
public void OperatorPlus_Union() { Cellule[] cells = new Cellule[] { GénérerCellule(valeurFixe: 4, possibilités: new List <int> { 1, 2 }), GénérerCellule(valeurTrouvé: 3, possibilités: new List <int> { 2, 4, 6 }), GénérerCellule(possibilités: new List <int> { 1, 2, 4, 7 }), GénérerCellule(possibilités: new List <int> { 6, 7, 8, 9 }), GénérerCellule(possibilités: new List <int> { 1, 2, 8, 9 }) }; Groupe g1 = GénérerGroupe(cells[0], cells[2], cells[3], cells[4]); Groupe g2 = GénérerGroupe(cells[1], cells[2], cells[3]); Assert.AreEqual(4, g1.Count); Assert.AreEqual(3, g2.Count); Groupe g = g1 + g2; Assert.AreEqual(5, g.Count); foreach (Cellule c in cells) { Assert.IsTrue(g.Contains(c)); } }
public void GetNbCellulesNonTrouvées_ValeurNonNulleEtNulle() { Cellule c = null; Groupe g = GénérerGroupe( c = GénérerCellule(valeurFixe: 3, possibilités: new List <int> { 1, 7, 8, 3 }), GénérerCellule(valeurTrouvé: 2, possibilités: new List <int> { 1, 7, 8, 3 }), GénérerCellule(possibilités: new List <int> { 1, 2, 8, 6, 7 }), GénérerCellule(possibilités: new List <int> { 1, 2, 3 }), GénérerCellule(possibilités: new List <int> { 4, 5, 6 }), GénérerCellule(possibilités: new List <int> { 1, 2, 7, 8 }) ); Assert.AreEqual(4, g.GetNbCellulesNonTrouvées()); }
public async Task CreateBoard(Board board, bool randomBoat = true) { _context.Boards.Add(board); await _context.SaveChangesAsync(); List <Cellule> cellules = new List <Cellule>(); var cellCount = 0; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { Cellule cell = new Cellule(_celluleController.GetUniqueId() + cellCount, board.Id, j, i, false, false); cellules.Add(cell); cellCount++; } } if (randomBoat) { new BoardGeneratorControllerV2().SetRandomBoat(cellules); } foreach (Cellule cell in cellules) { await _celluleController.CreateCellule(cell); } }
private Cellule GénérerCellule(int valeurFixe = Cellule.NONE, int valeurTrouvé = Cellule.NONE, List <int> possibilités = null) { Cellule c = new Cellule(new Ligne(li), new Colonne(co), new Bloc(0)); if (++li > 8) { li = 0; ++co; } if (possibilités != null) { foreach (int n in possibilités) { c.AjouterPossibilité(n); } } if (valeurFixe != Cellule.NONE) { c.FixerValeur(valeurFixe); } else if (valeurTrouvé != Cellule.NONE) { c.ModifierValeur(valeurTrouvé); } return(c); }
public void SafeEditCellule(Cellule cell) { Cellule trackedCellule = _context.Cellules.ToList().Find(c => c.Id == cell.Id); trackedCellule.CopyProps(cell); EditCellule(trackedCellule); }
public void CopyProps(Cellule cell) { IsBoat = cell.IsBoat; BoatIdentificator = cell.BoatIdentificator; Orientation = cell.Orientation; IsDeadBoat = cell.IsDeadBoat; IsHit = cell.IsHit; }
public Cellule ResoudreCellule(int posX, int posY) { Cellule maCellule = new Cellule() { Valeur = 8, EstTrouve = true, EstValeurInitiale = false }; return(maCellule); }
public static Orientation GetCellsOrientation(Cellule first, Cellule second) { if (first.Ycoords != second.Ycoords) { return(Orientation.Vertical); } if (first.Xcoords != second.Xcoords) { return(Orientation.Horizontal); } return(Orientation.Undefined); }
private void LireFichierCarte(string pth) { string[] lines; if (pth == null) { return; } path = pth; #if UNITY_ANDROID #else lines = File.ReadAllLines(path); #endif int nbLines = lines.Length; if (nbLines < 3) { return; } maxX = uint.Parse(lines[0]); maxY = uint.Parse(lines[1]); name = lines[2]; if (maxX < 0 || maxY < 0) { return; } carte = new Cellule[maxX, maxY]; //parseur for (int i = 3; i < nbLines; i++) { string[] str = lines[i].Split(':'); if (str.Length == 5) { uint xcel = uint.Parse(str[0]); uint ycel = uint.Parse(str[1]); int ht = int.Parse(str[2]); int typeElt = int.Parse(str[3]); uint id = uint.Parse(str[4]); ElementGeneric elt = new ElementGeneric((ElementGeneric.TYPE_ELEMENT)typeElt, id); carte[xcel, ycel] = new Cellule(); carte[xcel, ycel].AjouterElement(elt); carte[xcel, ycel].Hauteur = ht; } } }
private Cellule BoatHitNear(Cellule cible, int nearLevel = 1) { var solution = new List <Cellule>(); if (cible.Ycoords + nearLevel <= 4) { solution.Add(_cells[cible.Xcoords][cible.Ycoords + nearLevel]); } if (cible.Ycoords - nearLevel >= 0) { solution.Add(_cells[cible.Xcoords][cible.Ycoords - nearLevel]); } if (cible.Xcoords + nearLevel <= 4) { solution.Add(_cells[cible.Xcoords + nearLevel][cible.Ycoords]); } if (cible.Xcoords - nearLevel >= 0) { solution.Add(_cells[cible.Xcoords - nearLevel][cible.Ycoords]); } if (solution.Any(c => c != null && c.IsHit && c.IsBoat)) { List <Cellule> boatsNear = solution.FindAll(c => c != null && c.IsHit && c.IsBoat); foreach (Cellule boat in boatsNear) { Orientation orientation = Utils.GetCellsOrientation(cible, boat); Cellule result = GetBoatNearByOrientation(new List <Cellule>() { cible, boat }, orientation); if (result != null) { return(result); } } } List <Cellule> solutionNotHit = solution.FindAll(c => c != null && !c.IsHit); // TODO : change this if (solutionNotHit.Count == 0) { return(cible); } return(solutionNotHit[Utils.RandomNumber(0, solutionNotHit.Count - 1)]); }
public Grid(int mapWidth, int mapHeight, float[,] noiseMap) { cellules = new Cellule[mapWidth, mapHeight]; this.MapHeight = mapHeight; this.MapWidth = mapWidth; for (int i = 0; i < mapWidth; i++) { for (int j = 0; j < mapHeight; j++) { cellules[i, j] = new Cellule(i, j, noiseMap[i, j]); } } }
private Cellule FoundRandomRemoteCell(List <Cellule> cellules) { BoardGeneratorControllerV2 boardGeneratorControllerV2 = new BoardGeneratorControllerV2(); var noHitCells = GetNoHitCells(_cells); var maxLength = FindMaxBoat(cellules); List <List <Cellule> > possibilities = boardGeneratorControllerV2.GetBoatPossibility(noHitCells, maxLength); var selectedPossibility = possibilities[Utils.RandomNumber(0, possibilities.Count - 1)]; // some errors here Cellule selectedCell = selectedPossibility[Utils.RandomNumber(0, selectedPossibility.Count - 1)]; var c = cellules.Find(c => c.Id == selectedCell.Id); return(c); }
private Cellule CellByOrientation(Cellule cible, Orientation orientation, int add) { if (orientation == Orientation.Horizontal && cible.Xcoords + add > 4 || cible.Xcoords + add < 0) { return(null); } if (orientation == Orientation.Vertical && cible.Ycoords + add > 4 || cible.Ycoords + add < 0) { return(null); } return(_cells[orientation == Orientation.Horizontal ? cible.Xcoords + add : cible.Xcoords][orientation == Orientation.Vertical ? cible.Ycoords + add : cible.Ycoords]); }
public void HitCellule(Cellule cellule) { cellule.IsHit = true; EditCellule(cellule); List <Cellule> boat = _context.Cellules.ToList().FindAll(c => c.BoatIdentificator == cellule.BoatIdentificator); var isDeadBoat = !boat.Any(c => !c.IsHit); if (isDeadBoat) { foreach (Cellule cell in boat) { cell.IsDeadBoat = true; EditCellule(cell); } } }
/// <summary> /// Permet de générer une figure Acorn qui est susceptible de créer une longue chaine de vie /// </summary> static void RemplissageAcorn() { Random r = new Random(); int positionX = r.Next(10, Program.NbColonnes - 10); int positionY = r.Next(10, Program.NbLignes - 10); MatriceDeJeux[positionY, positionX] = new Cellule(true); MatriceDeJeux[positionY + 1, positionX + 2] = new Cellule(true); MatriceDeJeux[positionY + 2, positionX - 1] = new Cellule(true); MatriceDeJeux[positionY + 2, positionX] = new Cellule(true); MatriceDeJeux[positionY + 2, positionX + 3] = new Cellule(true); MatriceDeJeux[positionY + 2, positionX + 4] = new Cellule(true); MatriceDeJeux[positionY + 2, positionX + 5] = new Cellule(true); Console.ForegroundColor = ConsoleColor.Cyan; WriteLine("\n\n Une Forme Acorn à été généré à la position {0} , {1}\n", positionX, positionY); }
public void EditCellule(Cellule cell) { var result = _context.Cellules.SingleOrDefault(c => c.Id == cell.Id); if (result != null) { try { _context.Cellules.Attach(cell); _context.Entry(cell).State = EntityState.Modified; _context.SaveChanges(); } catch (Exception ex) { throw ex; } } }
public Cellule[][] ResoudreGrille(bool test = false) { Cellule[][] mesCellules = new Cellule[9][]; for (int row = 0; row < 9; row++) { mesCellules[row] = new Cellule[9]; for (int column = 0; column < 9; column++) { mesCellules[row][column] = new Cellule() { Valeur = (1 + new Random().Next(8)), EstTrouve = true, EstValeurInitiale = false }; } } return(mesCellules); }
public bool Init(int[][] value) { Cellule[][] cellules = new Cellule[value.Length][]; for (int i = 0; i < value.Length; i++) { Cellule[] row = new Cellule[value[i].Length]; for (int j = 0; j < value[i].Length; j++) { Cellule cell = new Cellule(value[i][j]); row[j] = cell; } cellules[i] = row; } bool isOk = _sudoku.InitGrille(cellules); return(isOk); }
public Cellule DonnerCellule(int x, int y) { if (x < 0 || y < 0) { return(null); } if (x >= maxX || y >= maxY) { return(null); } if (carte[x, y] == null) { carte[x, y] = new Cellule(); } return(carte[x, y]); }
/// <summary> /// Transforme la matrice du Program().Main() en grille pour le jeu /// </summary> /// <param name="Matrice">Matrice en 2d du Program().Main()</param> static void InitialisationMatrice(char[,] Matrice) { for (int i = 0; i != Matrice.GetLength(0); ++i) { for (int j = 0; j != Matrice.GetLength(1); ++j) { if (Matrice[i, j] == '*') { MatriceDeJeux[i, j] = new Cellule(true); MatriceDeJeuxTemporaire[i, j] = new Cellule(true); } else { MatriceDeJeux[i, j] = new Cellule(false); MatriceDeJeuxTemporaire[i, j] = new Cellule(false); } } } }
public void SupprimerPossibilités3_GroupeNonModifié() { Cellule c1 = null, c2 = null; Groupe g = GénérerGroupe( GénérerCellule(valeurFixe: 3, possibilités: new List <int> { 1, 7, 8, 3 }), GénérerCellule(valeurTrouvé: 2, possibilités: new List <int> { 1, 7, 8, 3 }), c2 = GénérerCellule(possibilités: new List <int> { 1, 2, 8, 6, 7 }), GénérerCellule(possibilités: new List <int> { 1, 2, 3 }), GénérerCellule(possibilités: new List <int> { 4, 5, 6 }), c1 = GénérerCellule(possibilités: new List <int> { 1, 2, 7, 8 }) ); Groupe except = new Groupe { c1, c2 }; Assert.IsFalse(g.SupprimerPossibilité(new int[] { 7, 8, 9 }, except)); foreach (Cellule _c in g) { if (_c.Fixé || _c.Trouvé || except.Contains(_c)) { Assert.IsTrue(_c.Possibilités.Contains(7)); Assert.IsTrue(_c.Possibilités.Contains(8)); } else { Assert.IsFalse(_c.Possibilités.Contains(7)); Assert.IsFalse(_c.Possibilités.Contains(8)); } } }
/// <summary> /// Génére aléatoirement un certain nombre de cellules groupé selon un facteur semi-aléatoire /// </summary> static void RemplissageAléatoire() { Random r = new Random(); int nbCellule = r.Next(100, 1000); int cptCellule = 0; for (int i = 0; i != nbCellule / 4; i++) { int positionX = r.Next(5, Program.NbColonnes - 5); int positionY = r.Next(5, Program.NbLignes - 5); if (i % 2 == 1 && i % 3 != 0) { MatriceDeJeux[positionY, positionX] = new Cellule(true); MatriceDeJeux[positionY + 1, positionX] = new Cellule(true); MatriceDeJeux[positionY + 1, positionX + 1] = new Cellule(true); MatriceDeJeux[positionY, positionX + 1] = new Cellule(true); } if (i % 3 == 0) { MatriceDeJeux[positionY, positionX] = new Cellule(true); MatriceDeJeux[positionY - r.Next(4), positionX + r.Next(4)] = new Cellule(true); MatriceDeJeux[positionY + r.Next(4), positionX - r.Next(4)] = new Cellule(true); MatriceDeJeux[positionY - r.Next(4), positionX + r.Next(4)] = new Cellule(true); } if (i % 2 == 0) { MatriceDeJeux[positionY, positionX] = new Cellule(true); MatriceDeJeux[positionY + r.Next(4), positionX + r.Next(4)] = new Cellule(true); MatriceDeJeux[positionY + r.Next(4), positionX + r.Next(4)] = new Cellule(true); MatriceDeJeux[positionY + r.Next(4), positionX + r.Next(4)] = new Cellule(true); } } foreach (Cellule cellule in MatriceDeJeux) { if (cellule.EstVivante) { ++cptCellule; } } Console.ForegroundColor = ConsoleColor.Cyan; WriteLine("\n\n {0} cellules générées !!!", cptCellule); }
public void GetCellulesContenantAuMoins_GroupeNonNulleEtNulle() { Cellule [] cells = null; Groupe g = GénérerGroupe( cells = new Cellule[] { GénérerCellule(valeurFixe: 3, possibilités: new List <int> { 1, 7, 8, 3 }), GénérerCellule(valeurTrouvé: 2, possibilités: new List <int> { 1, 7, 8, 3 }), GénérerCellule(possibilités: new List <int> { 1, 2, 8, 6, 7 }), GénérerCellule(possibilités: new List <int> { 1, 2, 3 }), GénérerCellule(possibilités: new List <int> { 4, 5, 6 }), GénérerCellule(possibilités: new List <int> { 1, 2, 7, 8 }) } ); Groupe res = g.GetCellulesContenantAuMoins(new int[] { 1, 2 }); // Vérification Assert.AreEqual(3, res.Count); foreach (int i in new int [] { 2, 3, 5 }) { Assert.IsTrue(res.Contains(cells[i])); } foreach (int i in new int[] { 0, 1, 4 }) { Assert.IsFalse(res.Contains(cells[i])); } res = g.GetCellulesContenantAuMoins(new int[] { 1, 2, 4 }); // Vérification Assert.AreEqual(0, res.Count); }
public void CreateConfig() { MainCanvas.Children.Clear(); TableauCellules = new Cellule[Hauteur, Largeur]; //calcul des dimensions int dim1 = (int)MainCanvas.MaxWidth / Largeur; int dim2 = (int)MainCanvas.MaxHeight / Hauteur; int dim = Math.Min(dim1, dim2); //maj des dimensions du canvas MainCanvas.Width = dim * Largeur; MainCanvas.Height = dim * Hauteur; for (int i = 0; i < Hauteur; i++) { for (int j = 0; j < Largeur; j++) { Cellule cel = new Cellule(this, dim, i, j, MainCanvas); TableauCellules[i, j] = cel; } } if (Theme) { foreach (var cel in TableauCellules) { cel.Alive = Brushes.WhiteSmoke; cel.Dead = Brushes.Black; } } else { foreach (var cel in TableauCellules) { cel.Alive = Brushes.Black; cel.Dead = Brushes.WhiteSmoke; } } }
public void OperatorMultiply_Intersection() { Cellule[] cells = new Cellule[] { GénérerCellule(valeurFixe: 4, possibilités: new List <int> { 1, 2 }), GénérerCellule(valeurTrouvé: 3, possibilités: new List <int> { 2, 4, 6 }), GénérerCellule(possibilités: new List <int> { 1, 2, 4, 7 }), GénérerCellule(possibilités: new List <int> { 6, 7, 8, 9 }), GénérerCellule(possibilités: new List <int> { 1, 2, 8, 9 }) }; Groupe g1 = GénérerGroupe(cells[0], cells[2], cells[3], cells[4]); Groupe g2 = GénérerGroupe(cells[1], cells[2], cells[3]); Assert.AreEqual(4, g1.Count); Assert.AreEqual(3, g2.Count); Groupe g = g1 * g2; Assert.AreEqual(2, g.Count); // Appartenance foreach (Cellule c in new Cellule[] { cells[2], cells[3] }) { Assert.IsTrue(g.Contains(c)); } // Non appartenance foreach (Cellule c in new Cellule[] { cells[0], cells[1], cells[4] }) { Assert.IsFalse(g.Contains(c)); } }
public void SupprimerPossibilités_GroupeNonModifié() { Cellule c = null; Groupe g = GénérerGroupe( GénérerCellule(valeurFixe: 3, possibilités: new List <int> { 1, 7, 3 }), GénérerCellule(valeurTrouvé: 2, possibilités: new List <int> { 1, 7, 3 }), GénérerCellule(possibilités: new List <int> { 1, 2, 3 }), GénérerCellule(possibilités: new List <int> { 4, 5, 6 }), c = GénérerCellule(possibilités: new List <int> { 1, 2, 7 }) ); Assert.IsFalse(g.SupprimerPossibilité(7, c)); foreach (Cellule _c in g) { if (_c.Fixé || _c.Trouvé) { Assert.IsTrue(_c.Possibilités.Contains(7)); } else if (object.ReferenceEquals(_c, c)) { Assert.IsTrue(_c.Possibilités.Contains(7)); } else { Assert.IsFalse(_c.Possibilités.Contains(7)); } } }
public void CreateConfig() { MainCanvas.Children.Clear(); TabCellules = new Cellule[Hauteur, Largeur]; //calcul des dimensions int dim1 = (int)MainCanvas.MaxWidth / Largeur; int dim2 = (int)MainCanvas.MaxHeight / Hauteur; int dim = Math.Min(dim1, dim2); //maj des dimensions du canvas MainCanvas.Width = dim * Largeur; MainCanvas.Height = dim * Hauteur; for (int i = 0; i < Hauteur; i++) { for (int j = 0; j < Largeur; j++) { Cellule cel = new Cellule(dim, i, j, MainCanvas); TabCellules[i, j] = cel; } } }
public void ConstructeurParDéfaut_TestGroupesEtEtatDesCellules() { Sudoku sudoku = new Sudoku(); // Test des groupes for (int i = 0; i < 9; ++i) { Assert.IsTrue(sudoku.Groupes.Contains(sudoku.Lignes[i]), $"La ligne {i} devrait appartenir à l'ensemble des groupes"); Assert.IsTrue(sudoku.Groupes.Contains(sudoku.Colonnes[i]), $"La colonne {i} devrait appartenir à l'ensemble des groupes"); Assert.IsTrue(sudoku.Groupes.Contains(sudoku.Blocs[i]), $"Le bloc {i} devrait appartenir à l'ensemble des groupes"); // Test sur les lignes, colonnes, blocs Assert.AreEqual(9, sudoku.Lignes[i].Count, $"La ligne {i} devrait contenir 9 cellules."); Assert.AreEqual(9, sudoku.Colonnes[i].Count, $"La colonne {i} devrait contenir 9 cellules."); Assert.AreEqual(9, sudoku.Blocs[i].Count, $"Le bloc {i} devrait contenir 9 cellules."); } for (int li = 0; li < 9; ++li) { for (int co = 0; co < 9; ++co) { Cellule c = sudoku[li, co]; // Test de l'appartenance aux groupes de la cellule Assert.IsTrue(sudoku.Lignes[li].Contains(c), $"La cellule de la ligne {li}, colonne {co} devrait appartenir à la ligne {li}"); Assert.IsTrue(sudoku.Colonnes[co].Contains(c), $"La cellule de la ligne {li}, colonne {co} devrait appartenir à la colonne {co}"); Assert.IsTrue(sudoku.Blocs[li / 3 * 3 + co / 3].Contains(c), $"La cellule de la ligne {li}, colonne {co} devrait appartenir à la colonne {co}"); // Test des lignes, colonnes et blocs de la cellule Assert.AreEqual(c.Ligne, sudoku.Lignes[li], $"La cellule de la ligne {li}, colonne {co} ne référencie pas la bonne ligne"); Assert.AreEqual(c.Colonne, sudoku.Colonnes[co], $"La cellule de la ligne {li}, colonne {co} ne référencie pas la bonne colonne"); Assert.AreEqual(c.Bloc, sudoku.Blocs[li / 3 * 3 + co / 3], $"La cellule de la ligne {li}, colonne {co} ne référencie pas le bon bloc"); // Test de l'état de la cellule Assert.IsFalse(c.Fixé, $"A l'initialisation la cellule ({li}, {co}) ne devrait pas être fixée."); Assert.IsFalse(c.Trouvé, $"A l'initialisation la cellule ({li}, {co}) ne devrait pas être fixée."); Assert.AreEqual(0, c.Possibilités.Count, $"A l'initialisation, la cellule ({li}, {co}) ne devrait pas contenir de possibilités."); } } }