public static void Add(string key, System.Action<NetworkingPlayer, NetworkingStream> action) { if(Networking.PrimarySocket != null) { Debug_Console.i.add("RPC dump adding: " + key + ", with id: " + EventHelper.GetEventId(key)); Networking.PrimarySocket.AddCustomDataReadEvent(EventHelper.GetEventId(key), action); } else { pair combined = new pair(); combined.key = key; combined.action = action; rpc_events.Add(combined); } }
bool isBallOur(int i, bal[] data, pair ball) { return(data[i].x == ball.x && data[i].y == ball.y); }
private static unsafe ulong Hash64UO(byte *s, uint len) { const ulong seed0 = 81; const ulong seed1 = 0; unchecked { // For strings over 64 bytes we loop. Internal state consists of // 64 bytes: u, v, w, x, y, and z. ulong x = seed0; ulong y = (seed1 * k2) + 113; ulong z = ShiftMix(y * k2) * k2; pair v = make_pair(seed0, seed1); pair w = make_pair(0, 0); ulong u = x - z; x *= k2; ulong mul = k2 + (u & 0x82); // Set end so that after the loop we have 1 to 64 bytes left to process. byte *end = s + ((len - 1) / 64 * 64); byte *last64 = end + ((len - 1) & 63) - 63; do { ulong a0 = Fetch64(s); ulong a1 = Fetch64(s + 8); ulong a2 = Fetch64(s + 16); ulong a3 = Fetch64(s + 24); ulong a4 = Fetch64(s + 32); ulong a5 = Fetch64(s + 40); ulong a6 = Fetch64(s + 48); ulong a7 = Fetch64(s + 56); x += a0 + a1; y += a2; z += a3; v.first += a4; v.second += a5 + a1; w.first += a6; w.second += a7; x = Rotate64(x, 26); x *= 9; y = Rotate64(y, 29); z *= mul; v.first = Rotate64(v.first, 33); v.second = Rotate64(v.second, 30); w.first ^= x; w.first *= 9; z = Rotate64(z, 32); z += w.second; w.second += z; z *= 9; swap(ref u, ref y); z += a0 + a6; v.first += a2; v.second += a3; w.first += a4; w.second += a5 + a6; x += a1; y += a7; y += v.first; v.first += x - y; v.second += w.first; w.first += v.second; w.second += x - y; x += w.second; w.second = Rotate64(w.second, 34); swap(ref u, ref z); s += 64; }while (s != end); // Make s point to the last 64 bytes of input. s = last64; u *= 9; v.second = Rotate64(v.second, 28); v.first = Rotate64(v.first, 20); w.first += (len - 1) & 63; u += y; y += u; x = Rotate64(y - x + v.first + Fetch64(s + 8), 37) * mul; y = Rotate64(y ^ v.second ^ Fetch64(s + 48), 42) * mul; x ^= w.second * 9; y += v.first + Fetch64(s + 40); z = Rotate64(z + w.first, 33) * mul; v = WeakHashLen32WithSeeds(s, v.second * mul, x + w.first); w = WeakHashLen32WithSeeds(s + 32, z + w.second, y + Fetch64(s + 16)); return(H( HashLen16(v.first + x, w.first ^ y, mul) + z - u, H(v.second + y, w.second + z, k2, 30) ^ x, k2, 31)); } }
public static List <int> Pathfind(Dungeon d, int start, int end, int mode = 1) { /* initialize datastructs * open: list of open nodes, potential to be visited * closed: set of closed nodes, done visiting * nodes: Dictionary of all nodes for easy reference */ List <pair> open = new List <pair>(); Dictionary <int, node> nodes = new Dictionary <int, node>(); HashSet <int> closed = new HashSet <int>(); // create and add the starting node to the open list node first = new node(0, Manhattan(start, end, d.width), start); nodes.Add(start, first); open.Add(new pair(first.G + first.H, start)); // Loop until we have reached the end, or we have run out of nodes int current = start; while (current != end && open.Count > 0) { // Check the node with the lowest F-Value current = open.First().idx; node currentNode = nodes[current]; open.RemoveAt(0); closed.Add(current); // Check all the current node's neighbors foreach (int n in neighbors(current, d, mode)) { int neighbor = current + n; if (!closed.Contains(neighbor)) { // calculate neighbor's G value int G = currentNode.G + d.GetTile(current + n).Cost(); // If the neighbor is not in open, add it to open int openidx = open.FindIndex(e => e.idx == neighbor); if (openidx < 0) { int H = Manhattan(current, end, d.width); nodes[neighbor] = new node(G, H, current); open.Add(new pair(G + H, neighbor)); } // Otherwise, check if the path from the new parent is shorter else { node neighborNode = nodes[neighbor]; if (G < neighborNode.G) { // Update the neighbor node since hte new path is shorter neighborNode.G = G; neighborNode.Parent = current; open[openidx] = new pair(neighborNode.G + neighborNode.H, neighbor); open.Sort(); } } } } } // Check if we reached the end List <int> path = new List <int>(); if (current == end) { // Start from the end node and construct the path to the start int next = end; while (next != start) { path.Add(next); next = nodes[next].Parent; } } return(path); }
static invertedList GetandCreateList(Hashtable ht, int i, int len) { invertedList L = GetList(ht, i, len); if (L != null) return L; else { L = new invertedList(); pair x = new pair(); x.l = len; x.i = i; ht.Add(x, L); //add the list to hashtable ArrayList LL = (ArrayList)invlist_length[len]; if (LL == null) { LL = new ArrayList(); LL.Add(L); invlist_length.Add(len, LL); } else { LL.Add(L); } //--- } return L; }
void makelevel(int level) { UpdateLevel(); int jumlahvertex = level + 2; if (jumlahvertex >= 25) { jumlahvertex = 25; } vertexnya = new GameObject[jumlahvertex]; edgenya = new GameObject[3 + (2 * level - 1)]; graph = new Dictionary <int, List <int> >(); List <pair> mypair = new List <pair>(); List <int> counting = new List <int>(); for (int i = 0; i < 25; i++) { counting.Add(i); } for (int i = 0; i < vertexnya.Length; i++) { int coba, temp2; coba = UnityEngine.Random.Range(0, counting.Count); temp2 = counting[coba]; counting.Remove(temp2); int linex = temp2 % 5; int liney = temp2 / 5; spawnvalue = new Vector2(UnityEngine.Random.Range(koorx[linex], (koorx[linex + 1] - 0.2F)), UnityEngine.Random.Range(koory[liney] + 0.1F, (koory[liney + 1]))); spawnrotation = new Quaternion(0, 0, 0, 0); vertexnya[i] = Instantiate(vertexku, spawnvalue, spawnrotation); vertexnya[i].SendMessage("SetNumber", i); graph[i] = new List <int>(); } spawnvalue = new Vector2(0, 0); spawnrotation = new Quaternion(0, 0, 0, 0); int u, v; for (int i = 0; i < vertexnya.Length - 1; i++) { for (int j = i + 1; j < vertexnya.Length; j++) { u = i; v = j; pair temp = new pair(u, v); mypair.Add(temp); } } for (int i = 0; i < edgenya.Length; i++) { pair temp2 = new pair(); int coba; while (true) { coba = UnityEngine.Random.Range(0, mypair.Count); temp2 = mypair[coba]; if (graph[temp2.a].Count >= 7 || graph[temp2.b].Count >= 7) { mypair.Remove(temp2); } else { break; } } edgenya[i] = Instantiate(edgeku, spawnvalue, spawnrotation); Vector2 foo = vertexnya[temp2.a].GetComponent <Transform>().position; Vector2 bar = vertexnya[temp2.b].GetComponent <Transform>().position; graph[temp2.a].Add(temp2.b); graph[temp2.b].Add(temp2.a); edgenya[i].GetComponent <LineRenderer>().SetPosition(0, foo); edgenya[i].GetComponent <LineRenderer>().SetPosition(1, bar); mypair.Remove(temp2); } }
static invertedList GetList(Hashtable ht, int i, int len) { pair x = new pair(); x.l = len; x.i = i; invertedList L = null; if (ht.ContainsKey(x)) L = (invertedList)ht[x]; return L; }
public int CompareTo(pair <T, U> a) => v1.CompareTo(a.v1) != 0 ? v1.CompareTo(a.v1) : v2.CompareTo(a.v2);
public fact(pair p = default, relation r = default) { this.p = p; this.r = r; }
public void insert(K key, V value) { pair <K, V> p = new pair <K, V>(key, value); insert_td(p); }
int System.IComparable <pair <F, S> > .CompareTo(pair <F, S> obj) { return(_cmp(obj)); }
public int CompareTo(pair <F, S> obj) { return(_cmp(obj)); }
public static bool operator <(period p1, period p2) { // special cases if (p1.length == 0) { return(p2.length > 0); } if (p2.length == 0) { return(p1.length < 0); } // exact comparisons if (p1.unit == p2.unit) { return(p1.length < p2.length); } if (p1.unit == timeUnit.quarters && p2.unit == timeUnit.years) { return(p1.length < 4 * p2.length); } if (p1.unit == timeUnit.years && p2.unit == timeUnit.quarters) { return(4 * p1.length < p2.length); } if (p1.unit == timeUnit.quarters && p2.unit == timeUnit.months) { return(3 * p1.length < p2.length); } if (p1.unit == timeUnit.months && p2.unit == timeUnit.quarters) { return(p1.length < 3 * p2.length); } if (p1.unit == timeUnit.months && p2.unit == timeUnit.years) { return(p1.length < 12 * p2.length); } if (p1.unit == timeUnit.years && p2.unit == timeUnit.months) { return(12 * p1.length < p2.length); } if (p1.unit == timeUnit.days && p2.unit == timeUnit.weeks) { return(p1.length < 7 * p2.length); } if (p1.unit == timeUnit.weeks && p2.unit == timeUnit.days) { return(7 * p1.length < p2.length); } // inexact comparisons (handled by converting to days and using limits) pair p1lim = new pair(p1), p2lim = new pair(p2); if (p1lim.hi < p2lim.lo || p2lim.hi < p1lim.lo) { return(p1lim.hi < p2lim.lo); } else { throw new ArgumentException("Undecidable comparison between " + p1.ToString() + " and " + p2.ToString()); } }
public bool shouldSkip(Type type, string fieldName) { var pair = new pair <Type, string>(type, fieldName); return(_skipMap.Contains(pair)); }
private int kuncijawaban() { pair[] arr = new pair[graph.Count]; int[] dipake = new int[graph.Count]; bool[] visit = new bool[graph.Count]; int current = 0; for (int i = 0; i < arr.Length; i++) { arr[i] = new pair(i, graph[i].Count); dipake[i] = 0; visit[i] = false; } Array.Sort <pair>(arr, (x, y) => y.b.CompareTo(x.b)); for (int i = 0; i < arr.Length; i++) { Debug.Log(arr[i].a + " " + arr[i].b); } for (int i = 0; i < arr.Length; i++) { if (visit[arr[i].a] == true) { continue; } else { current++; List <int> pakewarnaini = new List <int>(); dipake[arr[i].a] = current; visit[arr[i].a] = true; pakewarnaini.Add(arr[i].a); for (int j = 0; j < arr.Length; j++) { bool hehe; if (visit[arr[j].a] == true) { continue; } else { hehe = true; for (int k = 0; k < pakewarnaini.Count; k++) { if (graph[pakewarnaini[k]].Contains(arr[j].a)) { hehe = false; } } if (hehe == true) { pakewarnaini.Add(arr[j].a); dipake[arr[j].a] = current; visit[arr[j].a] = true; } } } } } Debug.Log("current" + current); return(current); }
public int CompareTo(pair <T, U> a) { return(v1.CompareTo(a.v1) != 0 ? v1.CompareTo(a.v1) : v2.CompareTo(a.v2)); }
int FindMinSequence(int[,] infoAmountMatrix) { int minIndex = 0; int[,] infoMatrix = new int[6, 6]; for (int i = 0; i < infoAmountMatrix.GetLength(0); i++) { for (int j = 0; j < infoAmountMatrix.GetLength(1); j++) { infoMatrix[i, j] = infoAmountMatrix[i, j]; } } List <pair> timesOfTrials = new List <pair>(); foreach (sequence c in variants) { //Переставляем матрицу количества передач for (int i = 0; i < infoAmountMatrix.GetLength(0); i++) { for (int j = 0; j < infoAmountMatrix.GetLength(1); j++) { infoMatrix[i, j] = infoAmountMatrix[i, j]; } } // int[,] priorityMatrix = GetPrioritiesMatrix(c); int firstMagStationsToParallel = 0; int secondMagStationsToParallel = 0; for (int i = 0; i < 6; i++) { for (int j = 0; j < 6; j++) { if (priorityMatrix[i, j] == 1 && c.firstMag.Contains(i + 1)) { firstMagStationsToParallel++; } else if (priorityMatrix[i, j] == 1 && c.secondMag.Contains(i + 1)) { secondMagStationsToParallel++; } } } bool sended = false; pair firstMagMaxInd = new pair(0, 0); pair secondMagMaxInd = new pair(0, 0); int firstMagMaxTrans = 0; int secondMagMaxTrans = 0; bool firstFrozen = false; bool secondFrozen = false; //Список для теста, составлять для каждой ситуации - слишком жирно по производительности //List<magistralPiece> firstMagistralOut = new List<magistralPiece>(); //List<magistralPiece> secondMagistralOut = new List<magistralPiece>(); // int checker = 0; int time = 0; while (!sended) { if (!firstFrozen) { firstMagMaxTrans = 0; } if (!secondFrozen) { secondMagMaxTrans = 0; } checker = 0; if (secondMagStationsToParallel == 0 || firstMagStationsToParallel == 0) { break; } for (int i = 0; i < 6; i++) //Проходим по массиву в поисках подходящих для передачи элементов { for (int j = 0; j < 6; j++) { if (priorityMatrix[i, j] == 1 && infoMatrix[i, j] != 0) { if (c.firstMag.Contains(i + 1) && !firstFrozen) { if (infoMatrix[i, j] > firstMagMaxTrans) { firstMagMaxTrans = infoMatrix[i, j]; firstMagMaxInd.first = i; firstMagMaxInd.second = j; checker++; } } else if (c.secondMag.Contains(i + 1) && !secondFrozen) { if (infoMatrix[i, j] > secondMagMaxTrans) { secondMagMaxTrans = infoMatrix[i, j]; secondMagMaxInd.first = i; secondMagMaxInd.second = j; checker++; } } } } } if (secondMagMaxTrans > firstMagMaxTrans && infoMatrix[firstMagMaxInd.first, firstMagMaxInd.second] > 0) { infoMatrix[secondMagMaxInd.first, secondMagMaxInd.second] -= firstMagMaxTrans; infoMatrix[firstMagMaxInd.first, firstMagMaxInd.second] -= firstMagMaxTrans; secondMagMaxTrans -= firstMagMaxTrans; firstMagStationsToParallel--; time += firstMagMaxTrans; //secondMagistralOut.Add(new magistralPiece(secondMagMaxInd.first + 1, secondMagMaxInd.second + 1, firstMagMaxTrans)); //firstMagistralOut.Add(new magistralPiece(firstMagMaxInd.first + 1, firstMagMaxInd.second + 1, firstMagMaxTrans)); secondFrozen = true; firstFrozen = false; } else if (secondMagMaxTrans < firstMagMaxTrans && infoMatrix[secondMagMaxInd.first, secondMagMaxInd.second] > 0) { infoMatrix[firstMagMaxInd.first, firstMagMaxInd.second] -= secondMagMaxTrans; infoMatrix[secondMagMaxInd.first, secondMagMaxInd.second] -= secondMagMaxTrans; firstMagMaxTrans -= secondMagMaxTrans; secondMagStationsToParallel--; time += secondMagMaxTrans; //firstMagistralOut.Add(new magistralPiece(firstMagMaxInd.first + 1, firstMagMaxInd.second + 1, secondMagMaxTrans)); //secondMagistralOut.Add(new magistralPiece(secondMagMaxInd.first + 1, secondMagMaxInd.second + 1, secondMagMaxTrans)); secondFrozen = false; firstFrozen = true; } else if (secondMagMaxTrans == firstMagMaxTrans && infoMatrix[secondMagMaxInd.first, secondMagMaxInd.second] > 0) { infoMatrix[firstMagMaxInd.first, firstMagMaxInd.second] -= firstMagMaxTrans; infoMatrix[secondMagMaxInd.first, secondMagMaxInd.second] -= secondMagMaxTrans; secondMagStationsToParallel--; firstMagStationsToParallel--; time += secondMagMaxTrans; //firstMagistralOut.Add(new magistralPiece(firstMagMaxInd.first + 1, firstMagMaxInd.second + 1, firstMagMaxTrans)); //secondMagistralOut.Add(new magistralPiece(secondMagMaxInd.first + 1, secondMagMaxInd.second + 1, secondMagMaxTrans)); secondFrozen = false; firstFrozen = false; } if (checker == 0) { sended = true; } } //Добавляем оставшиеся передачи по одной магистрали,а затем полные передачи bool over = false; while (!over) { checker = 0; for (int i = 0; i < 6; i++) { for (int j = 0; j < 6; j++) { if (priorityMatrix[i, j] == 1 && infoMatrix[i, j] != 0) { if (c.firstMag.Contains(i + 1)) { time += infoMatrix[i, j]; infoMatrix[i, j] = 0; checker++; } else if (c.secondMag.Contains(i + 1)) { time += infoMatrix[i, j]; infoMatrix[i, j] = 0; checker++; } } } } if (checker == 0) { over = true; } } for (int i = 0; i < 6; i++) { for (int j = 0; j < 6; j++) { if (priorityMatrix[i, j] == 2 && infoMatrix[i, j] != 0) { time += infoMatrix[i, j]; infoMatrix[i, j] = 0; } } } timesOfTrials.Add(new pair(time, c.num)); } int minTime = timesOfTrials.First <pair>().first; foreach (pair p in timesOfTrials) { if (minTime > p.first) { minIndex = p.second; minTime = p.first; } } return(minIndex); }
static invertedList GetList(int i, int len) { pair x = new pair(); x.l = len; x.i = i; invertedList L = null; if (invertedlists.ContainsKey(x)) L = (invertedList)invertedlists[x]; return L; }
static invertedList GetandCreateList(Hashtable ht, int i, int len) { invertedList L = GetList(ht, i, len); if (L != null) return L; else { L = new invertedList(); pair x = new pair(); x.l = len; x.i = i; ht.Add(x, L); } return L; }
static invertedList getList(int i, int len) { pair x = new pair(); x.l = len; x.i = i; invertedList L = null; if (invertedlists.ContainsKey(x)) L = (invertedList)invertedlists[x]; else { L = new invertedList(); invertedlists.Add(x, L); } //added to the inverted by the length if (invertedlists_by_length.ContainsKey(len)) { ArrayList l = (ArrayList)invertedlists_by_length[len]; l.Add(L); } else { ArrayList l = new ArrayList(); l.Add(L); invertedlists_by_length.Add(len, l); } return L; }
public static bool operator <(Period p1, Period p2) { // special cases if (p1.length() == 0) return (p2.length() > 0); if (p2.length() == 0) return (p1.length() < 0); // exact comparisons if (p1.units() == p2.units()) return p1.length() < p2.length(); if (p1.units() == TimeUnit.Months && p2.units() == TimeUnit.Years) return p1.length() < 12 * p2.length(); if (p1.units() == TimeUnit.Years && p2.units() == TimeUnit.Months) return 12 * p1.length() < p2.length(); if (p1.units() == TimeUnit.Days && p2.units() == TimeUnit.Weeks) return p1.length() < 7 * p2.length(); if (p1.units() == TimeUnit.Weeks && p2.units() == TimeUnit.Days) return 7 * p1.length() < p2.length(); // inexact comparisons (handled by converting to days and using limits) pair p1lim = new pair(p1), p2lim = new pair(p2); if (p1lim.hi < p2lim.lo || p2lim.hi < p1lim.lo) return p1lim.hi < p2lim.lo; else throw new ArgumentException("Undecidable comparison between " + p1.ToString() + " and " + p2.ToString()); }
/// добавление слова и всех его форм в словарь /// wordBase - marshaled-слово /// morphoType - морфотип /// nounType - тип сущетсвительного public void AddWord(char *wordBase, MorphoTypeNative morphoType, ref MorphoAttributePair?nounType) { var baseMorphoForm = new BaseMorphoFormNative(wordBase, morphoType); for (TreeDictionaryNative _this = this, _this_next; ;) { var first_char = _UPPER_INVARIANT_MAP[*wordBase]; #region [.сохранение характеристик if end-of-word.] if (first_char == '\0') { // sort & merge after insert - may be faster/better (30.04.2014)!!!! //* var len = morphoType.MorphoFormEndingUpperAndMorphoAttributes.Length; SortedListIntPtrKey <pair[]> .Tuple[] tuples; int tuplesOffset; if (!_this.HasEndings()) { tuplesOffset = 0; tuples = new SortedListIntPtrKey <pair[]> .Tuple[len]; } else { tuplesOffset = _this._Endings.Count; tuples = new SortedListIntPtrKey <pair[]> .Tuple[len + tuplesOffset]; for (int i = 0; i < tuplesOffset; i++) { tuples[i] = _this._Endings.Array[i]; } } for (int i = 0; i < len; i++) { var p = morphoType.MorphoFormEndingUpperAndMorphoAttributes[i]; var pairs_current_len = p.MorphoAttributes.Length; var pairs_current = new pair[pairs_current_len]; for (int j = 0; j < pairs_current_len; j++) { var ma = MorphoAttributePair.GetMorphoAttribute(morphoType, p.MorphoAttributes[j], ref nounType); pairs_current[j] = new pair(baseMorphoForm, ma); } tuples[i + tuplesOffset] = new SortedListIntPtrKey <pair[]> .Tuple() { Key = p.EndingUpper, Value = pairs_current }; } ShellSortAscending(tuples); MergeSorted(ref tuples); _this._Endings.SetArray(tuples); //*/ return; } #endregion if (!_this._Slots.TryGetValue(first_char, out _this_next)) { /// добавление новой буквы _this_next = new TreeDictionaryNative(); _this._Slots.Add(first_char, _this_next); } _this = _this_next; wordBase++; } }
.Select((pair, i) => CalculateRound(pair, i, rounds)) .Take(ROUNDS)
public void Generate() { grid = new bool[width + 1, width + 1]; maze = new Tile[width + 1, width + 1]; List <pair> frontiers = new List <pair>(); //cells to visit //starting tile int pos = width / 2 + 1; grid[pos, pos] = true; //frontiers.Add(new pair(1, width - 3)); //frontiers.Add(new pair(3, width - 1)); frontiers.Add(new pair(pos - 2, pos)); frontiers.Add(new pair(pos + 2, pos)); frontiers.Add(new pair(pos, pos - 2)); frontiers.Add(new pair(pos, pos + 2)); while (frontiers.Count > 0) { int index = UnityEngine.Random.Range(0, frontiers.Count); //get random cell from list pair coords = frontiers[index]; List <pair> neighbors = getNeighbors(coords.a, coords.b); //get random neighbor int index2 = UnityEngine.Random.Range(0, neighbors.Count); //Debug.Log(index2); pair neighbor = neighbors[index2]; int dx = (neighbor.a - coords.a) / 2; int dy = (neighbor.b - coords.b) / 2; //Debug.Log("dx: " + dx); //Debug.Log("dy: " + dy); grid[coords.a, coords.b] = true; grid[coords.a + dx, coords.b + dy] = true; //passage between selected frontier cell and selected neighbor if (valid(coords.a + 2, coords.b)) //add chosen cell's frontier cells { if (!grid[coords.a + 2, coords.b]) { //Debug.Log(grid[coords.a + 2, coords.b]); pair p1 = new pair(coords.a + 2, coords.b); if (!frontiers.Contains(p1)) { frontiers.Add(new pair(coords.a + 2, coords.b)); } } } if (valid(coords.a, coords.b + 2)) { if (!grid[coords.a, coords.b + 2]) { // Debug.Log(grid[coords.a, coords.b + 2]); pair p2 = new pair(coords.a, coords.b + 2); if (!frontiers.Contains(p2)) { frontiers.Add(new pair(coords.a, coords.b + 2)); } } } if (valid(coords.a - 2, coords.b)) { if (!grid[coords.a - 2, coords.b]) { // Debug.Log(grid[coords.a - 2, coords.b]); pair p3 = new pair(coords.a - 2, coords.b); if (!frontiers.Contains(p3)) { frontiers.Add(new pair(coords.a - 2, coords.b)); } } } if (valid(coords.a, coords.b - 2)) { if (!grid[coords.a, coords.b - 2]) { // Debug.Log(grid[coords.a, coords.b - 2]); pair p4 = new pair(coords.a, coords.b - 2); if (!frontiers.Contains(p4)) { frontiers.Add(new pair(coords.a, coords.b - 2)); } } } frontiers.Remove(coords); //remove chosen cell from list of frontier cells } //positions of start and end rooms (along top and bottom rows) int start = 2 * UnityEngine.Random.Range(1, width / 2) - 1; int end = 2 * UnityEngine.Random.Range(1, width / 2) - 1; grid[0, start] = true; //passage from start room to maze grid[width, end] = true; //passage from maze to end room (use width not width-1 because grid is actually width+1 wide) startRoom = Instantiate(startRoomPrefab) as StartRoom; startRoom.name = "Start Room"; startRoom.transform.parent = transform; startRoom.transform.localPosition = new Vector3(0f, 0f, 0f); endRoom = Instantiate(endRoomPrefab) as EndRoom; endRoom.name = "End Room"; endRoom.transform.parent = transform; endRoom.transform.localPosition = new Vector3(StartRoom.WIDTH / 2 + width + 2f + EndRoom.WIDTH / 2, 0, end + 1f - EndRoom.WIDTH / 2 - start + 1f); int catX = 2 * UnityEngine.Random.Range(1, width / 2 + 1) - 3; int catZ = 2 * UnityEngine.Random.Range(1, width / 2 + 1) - 3; cat = Instantiate(catPrefab) as Cat; cat.name = "Cat"; cat.transform.parent = transform; cat.transform.localPosition = new Vector3(catX + 1f + StartRoom.WIDTH / 2, 0f, catZ + 1f - start + 1f); for (int z = 0; z < width + 1; ++z) { for (int x = 0; x < width + 1; ++x) { if (grid[x, z]) //if a passage { Passage pass = Instantiate(passagePrefab) as Passage; maze[x, z] = pass; pass.name = "Tile " + x + ", " + z; pass.transform.parent = transform; pass.transform.localPosition = new Vector3(x + 1f + StartRoom.WIDTH / 2, 0f, z - start); //want tile at (1,1) to be at position x = 0 z = 0 so player starts in top left } else //else a wall { Wall wall = Instantiate(wallPrefab) as Wall; maze[x, z] = wall; wall.name = "Tile " + x + ", " + z; wall.transform.parent = transform; wall.transform.localPosition = new Vector3(x + 1f + StartRoom.WIDTH / 2, 0f, z - start); //want tile at (1,1) to be at position x = 0 z = 0 so player starts in top left } } } }
private void addPiece() { pair pos = generateUnoccupiedPosition(); m[pos.first, pos.second] = 2; }
public node(double a, pair b) { x = a; y = b; }
public static void ParseMessage(UserMessage message) { switch (message.type) { case 1: //上线 { pair <int, byte[]> data = (pair <int, byte[]>)message.data; Friend f = App.data.FriendList[data.Key]; f.ip = new System.Net.IPAddress(data.Value); f.isOnline = true; f.Father.Dispatcher.Invoke(() => { f.Father.Updata(); }); } break; case 2: //下线 { int id = (int)message.data; Friend f = App.data.FriendList[id]; f.isOnline = false; f.Father.Dispatcher.Invoke(() => { f.Father.Updata(); }); } break; case 3: //邀请运行某插件 { MessageBox.Show("收到邀请"); List <int> data = message.data as List <int>; int plugin_id = data[0]; int user_id = data[1]; var m = new MessageInvite(user_id, plugin_id); m.id = message.id; string name = App.data.FriendList[user_id].nickname; string p_name = AppData.plugin_dic[plugin_id].Name; m.message = string.Format("{0} 邀请您一同使用 {1}", name, p_name); App.data.MessageList.Add(m); } break; case 4: //好友添加请求 { User friend = message.data as User; var m = new MessageAddFriend(friend); m.type = 1; m.id = message.id; m.message = string.Format("{0} 请求加您为好友", friend.nickname); App.data.MessageList.Add(m); } break; case 5: //资料更新 { User F = message.data as User; Friend friend = App.data.FriendList[F.user_id]; friend.UpdatabyUser(F); friend.Father.Dispatcher.Invoke(() => { friend.Father.Updata(); }); } break; case 6: //对好友申请的表态 { List <object> data = (List <object>)message.data; var m = new MessageInformShow(message.id); m.id = message.id; m.type = 2; String temp = "拒绝"; if ((int)data[1] == 1) { temp = "同意"; } m.message = string.Format("{0} {1}加您为好友", ((User)data[0]).name, temp); App.data.MessageList.Add(m); } break; default: break; } }
public node() { x = -1; y = new pair(); }
void goToPos(bal[] mine, bal[] wher, pair ball)//определяет куда бежать { int d; pairr[] poss; if (ENgols % 2 == 0) { poss = topPos; d = 5; } else { poss = botPos; d = -5; } int[] whithout = new int[4]; whithout[0] = -1; whithout[1] = -1; whithout[2] = -1; whithout[3] = -1; //****************************************** farer = clos(mine, poss[1].x, poss[1].y, whithout); whithout[0] = farer; wher[farer].x = poss[1].x; wher[farer].y = poss[1].y; if (isBallnear(farer, mine, ball)) { wher[farer].x = ball.x; wher[farer].y = ball.y; } //****************************************** closer = clos(mine, poss[2].x, poss[2].y, whithout); whithout[1] = closer; wher[closer].x = poss[2].x; wher[closer].y = poss[2].y; if (isBallnear(closer, mine, ball)) { wher[closer].x = ball.x; wher[closer].y = ball.y; } //****************************************** attaker1 = clos(mine, ball.x, ball.y, whithout); whithout[2] = attaker1; wher[attaker1].x = ball.x; wher[attaker1].y = ball.y; //****************************************** golkeep = clos(mine, poss[0].x, poss[0].y, whithout); whithout[3] = golkeep; wher[golkeep].x = poss[0].x; wher[golkeep].y = ball.y; if (isBallnear(golkeep, mine, ball)) { wher[golkeep].x = ball.x; wher[golkeep].y = ball.y; } //****************************************** attaker2 = clos(mine, ball.x, ball.y, whithout); wher[attaker2].x = wher[attaker1].x; wher[attaker2].y = wher[attaker1].y + d; }
public async Task <IEnumerable <Users> > GetUsers([FromBody] pair p) { return(await _usersRepository.GetByID(p.username, p.password)); }
bool isBallnear(int i, bal[] data, pair ball) { double d = Math.Sqrt((data[i].x - ball.x) * (data[i].x - ball.x) + (data[i].y - ball.y) * (data[i].y - ball.y)); return(Math.Abs(d) <= 7 && Math.Abs(d) >= 0.1); }
bool SamecolorErase(int y, int x, int color) { Queue <int> qy = new Queue <int>(); Queue <int> qx = new Queue <int>(); int[] dx = new int[4] { 0, 1, 0, -1 }; int[] dy = new int[4] { 1, 0, -1, 0 }; qy.Enqueue(y); qx.Enqueue(x); int cnt = 0; int[,] qm = new int[maxY, maxX]; for (int i = 0; i < maxY; i++) { for (int j = 0; j < maxX; j++) { if (mapGenerateScript.getMap(i, j) == color) { qm[i, j] = (int)1e5; } //else if (mapGenerateScript.getMap(i, j) == color) qm[i, j] = 1; else { qm[i, j] = -1; } //qm[i, j] = (int)1e5; } } while (qy.Count > 0) { pair p = new pair(); p.first = qy.Peek(); p.second = qx.Peek(); qy.Dequeue(); qx.Dequeue(); for (int i = 0; i < 4; i++) { int ny = p.first + dy[i], nx = p.second + dx[i]; // int _color = mapGenerateScript.getMap(ny, nx); if (nx >= 0 && nx < maxX && 0 <= ny && ny < maxY && mapGenerateScript.getMap(ny, nx) == color && qm[ny, nx] == 1e5) { Debug.Log("x,y" + x + " " + y); qy.Enqueue(ny); qx.Enqueue(nx); qm[ny, nx] = 0; cnt++; } } } if (cnt >= 4) { foreach (GameObject obj in UnityEngine.Object.FindObjectsOfType(typeof(GameObject))) { // シーン上に存在するオブジェクトならば処理. if (obj.activeInHierarchy) { Debug.Log(obj.name); string eraseObject = ""; switch (color) { case (int)Puyo.red: eraseObject = rp; break; case (int)Puyo.blue: eraseObject = bp; break; case (int)Puyo.green: eraseObject = gp; break; case (int)Puyo.yellow: eraseObject = yp; break; case (int)Puyo.purple: eraseObject = pp; break; default: break; } // GameObjectの名前を表示. if (obj.name == eraseObject) { int xx = CalcError(obj.transform.position.x); int yy = CalcError(obj.transform.position.y); Debug.Log("yy,xx,qm" + yy + " " + xx + " " + qm[yy, xx]); //if (qm[yy, xx] == 0) obj.tag = "erase"; if (qm[yy, xx] == 0) { Destroy(obj); mapGenerateScript.setMap(yy, xx, 0); } } } } return(true); } return(false); }
/// <summary> /// returns the item in the list closest to the selected pair /// </summary> /// <param name="pairlist"></param> /// <param name="_pair"></param> /// <returns></returns> static int closest_less(List<pair> pairlist, pair _pair) { int shortest = 0; int dist = select_dist(pairlist[0], _pair); for (int i = 1; i < pairlist.Count; i++) { int k = select_dist(pairlist[i], _pair); if (k < dist) { dist = k; shortest = i; } } return shortest; }
/// <summary> /// finds the node within an island that has the shortest manhattan distance to another node /// </summary> /// <param name="target"></param> /// <param name="nodes"></param> /// <returns></returns> static pair q_closest(pair target, ArrayList nodes) { pair closest = (nodes[0] as pair); int dist = Math.Abs(closest.x - target.x) + Math.Abs(closest.y - target.y); for (int i = 1; i < nodes.Count; i += 5) { int dist2 = Math.Abs((nodes[i] as pair).x - target.x) + Math.Abs((nodes[i] as pair).y - target.y); if (dist2 < dist) { dist = dist2; closest = (nodes[i] as pair); } } return closest; }
void SetOutputData(int[,] infoAmountMatrix, sequence top) { int[,] infoMatrix = new int[6, 6]; for (int i = 0; i < infoAmountMatrix.GetLength(0); i++) { for (int j = 0; j < infoAmountMatrix.GetLength(1); j++) { infoMatrix[i, j] = infoAmountMatrix[i, j]; } } sequence c = top; //Переставляем матрицу количества передач for (int i = 0; i < infoAmountMatrix.GetLength(0); i++) { for (int j = 0; j < infoAmountMatrix.GetLength(1); j++) { infoMatrix[i, j] = infoAmountMatrix[i, j]; } } // int[,] priorityMatrix = GetPrioritiesMatrix(c); int firstMagStationsToParallel = 0; int secondMagStationsToParallel = 0; for (int i = 0; i < 6; i++) { for (int j = 0; j < 6; j++) { if (priorityMatrix[i, j] == 1 && c.firstMag.Contains(i + 1)) { firstMagStationsToParallel++; } else if (priorityMatrix[i, j] == 1 && c.secondMag.Contains(i + 1)) { secondMagStationsToParallel++; } } } bool sended = false; pair firstMagMaxInd = new pair(0, 0); pair secondMagMaxInd = new pair(0, 0); int firstMagMaxTrans = 0; int secondMagMaxTrans = 0; bool firstFrozen = false; bool secondFrozen = false; //Список для теста, составлять для каждой ситуации - слишком жирно по производительности // int checker = 0; int time = 0; while (!sended) { if (!firstFrozen) { firstMagMaxTrans = 0; } if (!secondFrozen) { secondMagMaxTrans = 0; } checker = 0; if (secondMagStationsToParallel == 0 || firstMagStationsToParallel == 0) { break; } for (int i = 0; i < 6; i++) //Проходим по массиву в поисках подходящих для передачи элементов { for (int j = 0; j < 6; j++) { if (priorityMatrix[i, j] == 1 && infoMatrix[i, j] != 0) { if (c.firstMag.Contains(i + 1) && !firstFrozen) { if (infoMatrix[i, j] > firstMagMaxTrans) { firstMagMaxTrans = infoMatrix[i, j]; firstMagMaxInd.first = i; firstMagMaxInd.second = j; checker++; } } else if (c.secondMag.Contains(i + 1) && !secondFrozen) { if (infoMatrix[i, j] > secondMagMaxTrans) { secondMagMaxTrans = infoMatrix[i, j]; secondMagMaxInd.first = i; secondMagMaxInd.second = j; checker++; } } } } } if (secondMagMaxTrans > firstMagMaxTrans && infoMatrix[firstMagMaxInd.first, firstMagMaxInd.second] > 0) { infoMatrix[secondMagMaxInd.first, secondMagMaxInd.second] -= firstMagMaxTrans; infoMatrix[firstMagMaxInd.first, firstMagMaxInd.second] -= firstMagMaxTrans; secondMagMaxTrans -= firstMagMaxTrans; firstMagStationsToParallel--; time += firstMagMaxTrans; secondMagistralOut.Add(new magistralPiece(secondMagMaxInd.first + 1, secondMagMaxInd.second + 1, firstMagMaxTrans)); firstMagistralOut.Add(new magistralPiece(firstMagMaxInd.first + 1, firstMagMaxInd.second + 1, firstMagMaxTrans)); secondFrozen = true; firstFrozen = false; } else if (secondMagMaxTrans < firstMagMaxTrans && infoMatrix[secondMagMaxInd.first, secondMagMaxInd.second] > 0) { infoMatrix[firstMagMaxInd.first, firstMagMaxInd.second] -= secondMagMaxTrans; infoMatrix[secondMagMaxInd.first, secondMagMaxInd.second] -= secondMagMaxTrans; firstMagMaxTrans -= secondMagMaxTrans; secondMagStationsToParallel--; time += secondMagMaxTrans; firstMagistralOut.Add(new magistralPiece(firstMagMaxInd.first + 1, firstMagMaxInd.second + 1, secondMagMaxTrans)); secondMagistralOut.Add(new magistralPiece(secondMagMaxInd.first + 1, secondMagMaxInd.second + 1, secondMagMaxTrans)); secondFrozen = false; firstFrozen = true; } else if (secondMagMaxTrans == firstMagMaxTrans && infoMatrix[secondMagMaxInd.first, secondMagMaxInd.second] > 0) { infoMatrix[firstMagMaxInd.first, firstMagMaxInd.second] -= firstMagMaxTrans; infoMatrix[secondMagMaxInd.first, secondMagMaxInd.second] -= secondMagMaxTrans; secondMagStationsToParallel--; firstMagStationsToParallel--; time += secondMagMaxTrans; firstMagistralOut.Add(new magistralPiece(firstMagMaxInd.first + 1, firstMagMaxInd.second + 1, firstMagMaxTrans)); secondMagistralOut.Add(new magistralPiece(secondMagMaxInd.first + 1, secondMagMaxInd.second + 1, secondMagMaxTrans)); secondFrozen = false; firstFrozen = false; } if (checker == 0) { sended = true; } } //Добавляем оставшиеся передачи по одной магистрали,а потом полные передачи bool over = false; while (!over) { checker = 0; for (int i = 0; i < 6; i++) { for (int j = 0; j < 6; j++) { if (priorityMatrix[i, j] == 1 && infoMatrix[i, j] != 0) { if (c.firstMag.Contains(i + 1)) { firstMagistralOut.Add(new magistralPiece(i + 1, j + 1, infoMatrix[i, j])); secondMagistralOut.Add(new magistralPiece(0, 0, infoMatrix[i, j])); infoMatrix[i, j] = 0; checker++; } else if (c.secondMag.Contains(i + 1)) { secondMagistralOut.Add(new magistralPiece(i + 1, j + 1, infoMatrix[i, j])); firstMagistralOut.Add(new magistralPiece(0, 0, infoMatrix[i, j])); infoMatrix[i, j] = 0; checker++; } } } } if (checker == 0) { over = true; } } for (int i = 0; i < 6; i++) { for (int j = 0; j < 6; j++) { if (priorityMatrix[i, j] == 2 && infoMatrix[i, j] != 0) { firstMagistralOut.Add(new magistralPiece(i + 1, j + 1, infoMatrix[i, j])); secondMagistralOut.Add(new magistralPiece(i + 1, j + 1, infoMatrix[i, j])); infoMatrix[i, j] = 0; checker++; } } } SetCurrentTime(); pictureBox1.Invalidate(); }
/// <summary> /// Concatenates all individual islands on the map into a single tree /// </summary> /// <param name="width"></param> /// <param name="height"></param> /// <param name="mod"></param> /// <returns></returns> static int[,] q_get_islands_2(int width, int height, int[,] mod) { //NEXT ITERATION: USE A LIST OF CENTERS PER ISLAND, AND SELECT FROM THE CLOSEST IN THAT LIST! Console.WriteLine("Making islands"); ArrayList islandList = q_islandGet(mod, width, height); Console.WriteLine(islandList.Count + " islands found"); List<pair> centers = new List<pair>(); List<int> sizes = new List<int>(); for (int i = 0; i < islandList.Count; i++) { centers.Add(q_center(islandList[i] as ArrayList)); sizes.Add((islandList[i] as ArrayList).Count); } Console.WriteLine("Centers determined for all islands"); while (islandList.Count > 3) { //declare four islands, pick one int[] islandstouse = new int[] { rand.Next(islandList.Count), -1, -1, -1 }; //array of places in list to use //pick the three closest islands for (int i = 0; i < islandList.Count; i++) if (islandstouse.Contains(i)) continue; else { mod_rythm++; for (int change = 0; change < 3; change++) if (islandstouse[(change + mod_rythm) % 3 + 1] == -1) { islandstouse[(change + mod_rythm) % 3 + 1] = i; break; } else if (Math.Abs(centers[i].x - centers[islandstouse[0]].x) + Math.Abs(centers[i].y - centers[islandstouse[0]].y) < Math.Abs(centers[(change + mod_rythm) % 3 + 1].x - centers[islandstouse[0]].x) + Math.Abs(centers[(change + mod_rythm) % 3 + 1].y - centers[islandstouse[0]].y)) { islandstouse[(change + mod_rythm) % 3 + 1] = i; break; } } #region r //select the center of each of these islands pair centerA = centers[islandstouse[0]]; pair centerB = centers[islandstouse[1]]; pair centerC = centers[islandstouse[2]]; pair centerD = centers[islandstouse[3]]; //determine shortest path between each of these islands and the target island pair ACloseB = q_closest(centerB, islandList[islandstouse[0]] as ArrayList); pair BCloseA = q_closest(ACloseB, islandList[islandstouse[1]] as ArrayList); int length_AB = Math.Abs(ACloseB.x - BCloseA.x) + Math.Abs(ACloseB.y - BCloseA.y) + (int)Math.Sqrt(Math.Pow(ACloseB.x - BCloseA.x, 2) + Math.Pow(ACloseB.y - BCloseA.y, 2)); pair ACloseC = q_closest(centerC, islandList[islandstouse[0]] as ArrayList); pair CCloseA = q_closest(ACloseC, islandList[islandstouse[2]] as ArrayList); int length_AC = Math.Abs(ACloseC.x - CCloseA.x) + Math.Abs(ACloseC.y - CCloseA.y) + (int)Math.Sqrt(Math.Pow(ACloseC.x - CCloseA.x, 2) + Math.Pow(ACloseC.y - CCloseA.y, 2)); pair ACloseD = q_closest(centerD, islandList[islandstouse[0]] as ArrayList); pair DCloseA = q_closest(ACloseD, islandList[islandstouse[3]] as ArrayList); int length_AD = Math.Abs(ACloseD.x - DCloseA.x) + Math.Abs(ACloseD.y - DCloseA.y) + (int)Math.Sqrt(Math.Pow(ACloseD.x - DCloseA.x, 2) + Math.Pow(ACloseD.y - DCloseA.y, 2)); List<int> sel = new List<int> { length_AB, length_AC, length_AD }; int shortest = Shortest(sel); if (shortest == 0) { //join the hallways Hallway_2(ACloseB.x, ACloseB.y, BCloseA.x, BCloseA.y, mod); //add item B to our base island (islandList[islandstouse[0]] as ArrayList).AddRange(islandList[islandstouse[1]] as ArrayList); //adjust center points - this isn't perfect, it just averages the centers //maybe later I will make it take size into account - would mean I'd have to actually list size again :) centers[islandstouse[0]] = new pair((centers[islandstouse[0]].x * sizes[islandstouse[0]] + centers[islandstouse[1]].x * sizes[islandstouse[1]]) / 2 * (sizes[islandstouse[1]] + sizes[islandstouse[0]]), (centers[islandstouse[0]].y * sizes[islandstouse[0]] + centers[islandstouse[1]].y * sizes[islandstouse[1]]) / 2 * (sizes[islandstouse[1]] + sizes[islandstouse[0]])); //remove items from lists islandList.RemoveAt(islandstouse[1]); centers.RemoveAt(islandstouse[1]); sizes.RemoveAt(1); } else if (shortest == 1) { //join the hallways Hallway_2(ACloseC.x, ACloseC.y, CCloseA.x, CCloseA.y, mod); //add item C to our base island (islandList[islandstouse[0]] as ArrayList).AddRange(islandList[islandstouse[2]] as ArrayList); //adjust center points - this isn't perfect, it just averages the centers //maybe later I will make it take size into account - would mean I'd have to actually list size again :) centers[islandstouse[0]] = new pair((centers[islandstouse[0]].x * sizes[islandstouse[0]] + centers[islandstouse[2]].x * sizes[islandstouse[2]]) / 2 * (sizes[islandstouse[2]] + sizes[islandstouse[0]]), (centers[islandstouse[0]].y * sizes[islandstouse[0]] + centers[islandstouse[2]].y * sizes[islandstouse[2]]) / 2 * (sizes[islandstouse[2]] + sizes[islandstouse[0]])); //remove items from lists islandList.RemoveAt(islandstouse[2]); centers.RemoveAt(islandstouse[2]); sizes.RemoveAt(2); } else if (shortest == 2) { //join the hallways Hallway_2(ACloseD.x, ACloseD.y, DCloseA.x, DCloseA.y, mod); //add item D to our base island (islandList[islandstouse[0]] as ArrayList).AddRange(islandList[islandstouse[3]] as ArrayList); //adjust center points - this isn't perfect, it just averages the centers //maybe later I will make it take size into account - would mean I'd have to actually list size again :) centers[islandstouse[0]] = new pair((centers[islandstouse[0]].x * sizes[islandstouse[0]] + centers[islandstouse[3]].x * sizes[islandstouse[3]]) / 2 * (sizes[islandstouse[3]] + sizes[islandstouse[0]]), (centers[islandstouse[0]].y * sizes[islandstouse[0]] + centers[islandstouse[3]].y * sizes[islandstouse[3]]) / 2 * (sizes[islandstouse[3]] + sizes[islandstouse[0]])); //remove items from lists islandList.RemoveAt(islandstouse[3]); centers.RemoveAt(islandstouse[3]); sizes.RemoveAt(3); } } for (int i = 1; i < islandList.Count; i++) {//(islandList.Count > 1) { pair centerA = centers[0]; pair centerB = centers[i]; pair AClose = q_closest(centerB, islandList[0] as ArrayList); pair BClose = q_closest(AClose, islandList[i] as ArrayList); Hallway_2(AClose.x, AClose.y, BClose.x, BClose.y, mod); (islandList[0] as ArrayList).AddRange(islandList[i] as ArrayList);//(islandList[0] as ArrayList).AddRange(islandList[i] as ArrayList); } Console.WriteLine("Connected all islands"); #endregion return mod; }
public int CompareTo(pair <T, U> a) { int c = Comparer <T> .Default.Compare(v1, a.v1); return(c != 0 ? c : Comparer <U> .Default.Compare(v2, a.v2)); }
static int[,] q_get_islands_3(int width, int height, int[,] mod) { Console.WriteLine("Making islands"); ArrayList islandList = q_islandGet(mod, width, height); Console.WriteLine(islandList.Count + " islands found"); List<pair> centers = new List<pair>(); List<int> sizes = new List<int>(); for (int i = 0; i < islandList.Count; i++) { centers.Add(q_center(islandList[i] as ArrayList)); sizes.Add((islandList[i] as ArrayList).Count); } Console.WriteLine("Centers determined for all islands"); while (islandList.Count > 1) { //pick an islands int island = rand.Next(islandList.Count); int compar = -1; for (int i = 0; i < islandList.Count; i++) { if (i == island) //match case continue; if (compar == -1) { //base case compar = i; //now we need to select indices continue; } //check to see if lower distance: if (select_dist(centers[compar], centers[island]) > select_dist(centers[island], centers[i])) compar = i; } pair centerA = centers[island]; pair centerB = centers[compar]; pair AClose = q_closest(centerB, islandList[island] as ArrayList); pair BClose = q_closest(AClose, islandList[compar] as ArrayList); Hallway_2(AClose.x, AClose.y, BClose.x, BClose.y, mod); centers[island] = new pair((centers[island].x + centers[compar].x) / 2, (centers[island].y + centers[compar].y) / 2); (islandList[island] as ArrayList).AddRange(islandList[compar] as ArrayList); centers.RemoveAt(compar); islandList.RemoveAt(compar); } return mod; }
private static List<pair> sort(Primitive array) { bNumber = true; List<pair> values = new List<pair>(); Type PrimitiveType = typeof(Primitive); Dictionary<Primitive, Primitive> _arrayMap; array = Utilities.CreateArrayMap(array); _arrayMap = (Dictionary<Primitive, Primitive>)PrimitiveType.GetField("_arrayMap", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase | BindingFlags.Instance).GetValue(array); foreach (KeyValuePair<Primitive, Primitive> kvp in _arrayMap) { pair _pair = new pair(kvp.Key, kvp.Value); values.Add(_pair); } values.Sort(); return values; }
/// <summary> /// uses scanfill to run through an island identifying it's exact bounds !WOAH -this one seems to have variable speeds - sometimes faster, sometimes /// slower than q_scanIsland_3 /// </summary> /// <param name="width"></param> /// <param name="height"></param> /// <param name="map"></param> /// <param name="xs"></param> /// <param name="ys"></param> /// <returns></returns> static ArrayList q_scanIsland_3(int width, int height, int[,] map, int xs, int ys) { Queue<pair> q = new Queue<pair>(); ArrayList beacon = new ArrayList(); pair pr = new pair(xs, ys); q.Enqueue(pr); while (q.Count != 0) { pair p = q.Dequeue(); int x = p.x; int y = p.y; bool topClosed = true; bool botClosed = true; if (!beacon.Contains(p) && map[x, y] == 1) { //Console.WriteLine(q.Count); beacon.Add(p); int ct = 0; while (map[x + ct, y] == 1) ct--; ct++; if (y - 1 >= 0) q.Enqueue(new pair(x, y - 1)); if (y + 1 >= 0) q.Enqueue(new pair(x, y + 1)); while (x + ct < width && map[x + ct, y] == 1) { beacon.Add(new pair(x + ct, y)); if (map[x + ct, y + 1] == 0) topClosed = true; else if (topClosed) { q.Enqueue(new pair(x + ct, y + 1)); topClosed = false; } if (map[x + ct, y - 1] == 0) botClosed = true; else if (botClosed) { q.Enqueue(new pair(x + ct, y - 1)); botClosed = false; } ct++; } } } return beacon; }
static invertedList getList(Hashtable ht, int i, int len) { pair x = new pair(); x.l = len; x.i = i; invertedList L = null; if (ht.ContainsKey(x)) L = (invertedList)ht[x]; else { L = new invertedList(); ht.Add(x, L); } return L; }
//applies distance calculation to a pair static int select_dist(pair x, pair y) { int dist = Math.Abs(x.x - y.x) + Math.Abs(x.y - y.y); dist += (int)Math.Sqrt(Math.Pow(x.x - y.x, 2) + Math.Pow(x.y - y.y, 2)); return dist / 2; }
private void generateBloc(Vector2 translation, int x, int y, Direction dir) { if (x >= 9 || y >= 9 || x <= 0 || y <= 0 || map[y][x] == true) return; List<bloc> list = new List<bloc> (); int size = 0; if (dir == Direction.UP) { foreach (bloc w in this.tuples) { if (w.up == true && w.nbtime > 0) { ++size; list.Add (w); } } } else if (dir == Direction.DOWN) { foreach (bloc w in this.tuples) { if (w.down == true && w.nbtime > 0) { ++size; list.Add (w); } } } else if (dir == Direction.LEFT) { foreach (bloc w in this.tuples) { if (w.left == true && w.nbtime > 0) { ++size; list.Add (w); } } } else if (dir == Direction.RIGHT) { foreach (bloc w in this.tuples) { if (w.right == true && w.nbtime > 0) { ++size; list.Add (w); } } } if (size == 0) { return; } map [y] [x] = true; int j = Random.Range (0, size); bloc a = list [j]; for (int i = 0; i != this.tuples.Length; ++i) { if (this.tuples[i].name == a.name) { this.tuples[i].nbtime -= 1; } } pair ed = new pair(); print (a.name); GameObject zez = Instantiate (a.name); ed.gameobject = zez; ed.pos = new Vector2 (translation.x, translation.y); this.level.Add (ed); if (a.up == true) { Vector2 newPosition = new Vector2 (translation.x, translation.y); newPosition.y += 10; generateBloc(newPosition, x, y - 1, Direction.UP); } if (a.down == true) { Vector2 newPosition = new Vector2 (translation.x, translation.y); newPosition.y -= 10; generateBloc(newPosition, x, y + 1, Direction.DOWN); } if (a.right == true) { Vector2 newPosition = new Vector2 (translation.x, translation.y); newPosition.x += 21; generateBloc(newPosition, x + 1, y, Direction.RIGHT); } if (a.left == true) { Vector2 newPosition = new Vector2 (translation.x, translation.y); newPosition.x -= 21; generateBloc(newPosition, x - 1, y, Direction.LEFT); } }
// Use this for initialization void Start() { cardState = STATE.FRONT; currentPair = front; cost = 50; }