public Polyomino(HashBitArray a, int n) { Minos = new HashSet<Vector2>(); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (a[i * n + j]) { Minos.Add(new Vector2(j, i)); } } } }
public static SolidColorBrush assignColor( Polyomino p_ ) { Polyomino p = new Polyomino( p_.Minos); HashBitArray h = p.toBitArray(); if (p.Minos.Count == 4) { // i bool[] x = { true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false }; HashBitArray b = new HashBitArray(x); if (h.Equals(b)) return Brushes.Cyan; // o bool[] x1 = { true, true, false, false, true, true, false, false, false, false, false, false, false, false, false, false }; HashBitArray b1 = new HashBitArray(x1); if (h.Equals(b1)) return Brushes.Yellow; // t bool[] x2 = { true, true, true, false, false, true, false, false, false, false, false, false, false, false, false, false }; HashBitArray b2 = new HashBitArray(x2); if (h.Equals(b2)) return Brushes.Purple; // s bool[] x3 = { true, true, false, false, false, true, true, false, false, false, false, false, false, false, false, false }; HashBitArray b3 = new HashBitArray(x3); if (h.Equals(b3)) return Brushes.Green; // z bool[] x4 = { false, true, true, false, true, true, false, false, false, false, false, false, false, false, false, false }; HashBitArray b4 = new HashBitArray(x4); if (h.Equals(b4)) return Brushes.Red; // j bool[] x5 = { true, true, true, false, true, false, false, false, false, false, false, false, false, false, false, false }; HashBitArray b5 = new HashBitArray(x5); if (h.Equals(b5)) return Brushes.Blue; // l bool[] x6 = { true, true, true, false, false, false, true, false, false, false, false, false, false, false, false, false }; HashBitArray b6 = new HashBitArray(x6); if (h.Equals(b6)) return Brushes.Orange; } //int hash = h.GetHashCode(); //if (hash < 0) //{ // hash = -(hash + 1); //} //double hue = (hash + 0.0) / int.MaxValue; //hue *= 360; //int red; //int green; //int blue; //HsvToRgb(hue, .5, .5, out red, out green, out blue); //Color c = new Color(); //c.R = (byte)red; //c.G = (byte)green; //c.B = (byte)blue; return Brushes.Black; }
public void generatePolyominos(int n) { if (!polyominoList.ContainsKey(n)) { HashSet<HashBitArray> toAdd = new HashSet<HashBitArray>(); if (n == 1) { HashBitArray b = new HashBitArray(1); b[0] = true; toAdd.Add(b); } else { generatePolyominos(n - 1); foreach (HashBitArray prev in polyominoList[n - 1]) { Polyomino prevPoly = new Polyomino(prev, n - 1); foreach (Vector2 adj in prevPoly.getAdj()) { Polyomino next = new Polyomino(prevPoly, adj); HashBitArray nextBits = next.toBitArray(); Boolean isNew = !toAdd.Contains(nextBits); for (int i = 0; i < 3 && isNew; i++) { next.rotate90CC(); nextBits = next.toBitArray(); isNew = !toAdd.Contains(nextBits); } if (isNew) { toAdd.Add(nextBits); } } } } polyominoList[n] = toAdd; } }
public HashBitArray toBitArray() { translateToOrigin(); int n = Minos.Count; HashBitArray ret = new HashBitArray(n * n); foreach (Vector2 v in Minos) { ret[v.Y * n + v.X] = true; } return ret; }