// Implemented form the interface, get the direction that the smell // is increasing the most as a unit vector in 2D space. public Vector2 directionOfSmell(Vector2 location, Smell[, ] smells, SmellType type) { // Loop over all the cells adjacent to the smell follower and determine // the direction that the smell is strongest Vector2 smellDirection = new Vector2(0, 0); for (int xOffset = -1; xOffset < 2; xOffset++) { for (int yOffset = -1; yOffset < 2; yOffset++) { int curX = (int)location.x + xOffset; int curY = (int)location.y + yOffset; if (curX >= 0 && curX < smells.GetLength(0) && curY >= 0 && curY < smells.GetLength(0)) { double curSmellVal = smells[curX, curY].getSmell(type); Vector2 curSmellCell = new Vector2(curX, curY); Vector2 curDirection = curSmellCell - location; smellDirection = smellDirection + (curDirection * (float)curSmellVal); } } } smellDirection.Normalize(); return(smellDirection); }
// Helper / debugging method to display the value for the given type of smell // at each cell on the board. Shouldn't be used in actual game private void displaySmells(SmellType type) { // Render on the canvas the smell values for (int x = 0; x < GameManager.SIZE; x++) { for (int y = 0; y < GameManager.SIZE; y++) { GameObject newGO = new GameObject("Some Text"); newGO.transform.SetParent(textHolder.transform); Text newText = newGO.AddComponent <Text>(); newText.text = (smellArray[x, y].getSmell(type)).ToString(); newGO.transform.localScale = new Vector3(0.02f, 0.02f, 1); Font ArialFont = (Font)Resources.GetBuiltinResource(typeof(Font), "Arial.ttf"); newText.font = ArialFont; newText.material = ArialFont.material; newText.color = new Color(0, 0, 0); RectTransform textTransform = newText.GetComponent <RectTransform>(); textTransform.sizeDelta = new Vector2(36, 25); textTransform.anchorMin = new Vector2(0, 0); textTransform.anchorMax = new Vector2(0, 0); textTransform.pivot = new Vector2(0, 0); newText.transform.position = new Vector3(x * GameManager.CELL_SIZE - 0.05f, y * GameManager.CELL_SIZE - 0.05f, 0); } } }
private string strSmellType(SmellType st) { switch (st) { case SmellType.一般刺鼻: return("一般刺鼻"); case SmellType.刺鼻: return("不刺鼻"); case SmellType.刺鼻: return("刺鼻"); } return(""); }
// ACTION METHOD: Returns the main steering vector to accomplish this action, // allong with setting this.action to null and updating insistances when the // action is finished public Vector2 seekTile(BoardManager.TileType tileType, SmellType smellType) { Vector2 goalSteering = new Vector2(-1, -1); // If we've seen the tile and stored its location, just arrive at the tile // (If we don't have a target to arrive at the vector is (-1, -1)) if (this.target.x >= 0 && this.target.y >= 0) { goalSteering = arriveAt(new Vector2(this.target.x * CELL_SIZE, this.target.y * CELL_SIZE)); // If we have arrived at the target, the agent should execute the action BoardManager.TileType currentCellType = GameManager.instance.getBoardArray()[(int)currentCell.x, (int)currentCell.y]; if (this.target.x == this.currentCell.x && this.target.y == this.currentCell.y || currentCellType == BoardManager.TileType.Water) { this.goal.apply(this.insistance); this.goal = null; this.target = new Vector2(-1, -1); } } else { // If we haven't seen tile yet, check if we see one // Check if within 3 blocks of the tile (represents the agent seeing the tile and going) Vector2 closeTile = getCloseTile(tileType, 3, currentCell, GameManager.instance.getBoardArray()); if (closeTile.x >= 0 && closeTile.y >= 0) { this.target = closeTile; goalSteering = arriveAt(new Vector2(closeTile.x * CELL_SIZE, closeTile.y * CELL_SIZE)); } else { // If we still can't see a bush, just follow the smell goalSteering = directionOfSmell(currentCell, GameManager.instance.getSmellArray(), smellType) * MAX_ACCEL; } } return(goalSteering); }
// ACTION METHOD: Returns the main steering vector to accomplish this action, // allong with setting this.action to null and updating insistances when the // action is finished public Vector2 seekFood(BoardManager.Food foodType, SmellType smellType) { Vector2 goalSteering = new Vector2(-1, -1); // If we've seen the food and stored its location, just arrive at the location // (If we don't have a target to arrive at the vector is (-1, -1)) if (this.target.x >= 0 && this.target.y >= 0) { goalSteering = arriveAt(new Vector2(this.target.x * CELL_SIZE, this.target.y * CELL_SIZE)); // If we have arrived at the location, apply the current goal to the insistances if (this.target.x == this.currentCell.x && this.target.y == this.currentCell.y) { this.goal.apply(this.insistance); this.goal = null; this.target = new Vector2(-1, -1); } } else { // If we haven't seen any food yet, check if we see one // Check if within 3 blocks of food type (represents the agent seeing the food) Vector2 closeBush = getCloseFood(foodType, 3, currentCell, GameManager.instance.getFoodArray()); if (closeBush.x >= 0 && closeBush.y >= 0) { this.target = closeBush; goalSteering = arriveAt(new Vector2(closeBush.x * CELL_SIZE, closeBush.y * CELL_SIZE)); } else { // If we still can't see a bush, just follow the smell goalSteering = this.directionOfSmell(currentCell, GameManager.instance.getSmellArray(), smellType) * MAX_ACCEL; } } return(goalSteering); }
public SmellInfo(SmellType type, int strength) { Type = type; Strength = strength; }
public SmellInfo() { Type = SmellType.FromHome; Strength = -1; }
public Rule(string DOI, Criteria criteria, SmellType smellType) { _DOI = DOI; _criteria = criteria; _smellType = smellType; }
/// <summary> /// Find coordinates of the most far smell from self, that is also the most strong /// </summary> /// <param name="field">Field for seraching</param> /// <param name="radius">Radius</param> /// <param name="type">Type of smell to search</param> /// <returns>Coordinates of desirable smell</returns> protected (Vector2i position, bool found) FindFarSmell(Field <Cell> field, int radius, SmellType type) { float dist = -1; var pos = new Vector2i(0, 0); int str = -1; Predicate <SmellInfo> pred; pred = (SmellInfo s) => s.Type == type; for (int i = -radius; i < radius; i++) { for (int j = -radius; j < radius; j++) { var smell = field[i, j].Smells.Find(pred); var curDist = Math.Abs(Position.X - i) + Math.Abs(Position.Y - j); if (smell != null && (dist < curDist || smell.Strength > str)) { pos.X = i; pos.Y = j; dist = curDist; str = smell.Strength; } } } return(pos, dist >= 0); }
public double getSmell(SmellType type) { return(this.smells[type]); }
// Set the given type of smell to 0 public void setSmellToZero(SmellType type) { this.smells[type] = 0; }
// adds the given value to the smell of the given type public void addToSmell(SmellType type, double toAdd) { double curVal = getSmell(type); this.smells[type] = curVal + toAdd; }
public Issue(SmellType issueType, string codeSnippetId) { IssueType = issueType; CodeSnippetId = codeSnippetId; }
/* * BEHAVIOR METHODS: The methods from the Behavior Interfeces that this agent * implements. */ public Vector2 directionOfSmell(Vector2 location, Smell[, ] smells, SmellType type) { return(smellFollower.directionOfSmell(location, smells, type)); }
// Propogate the smell from a single object radiating the smell of the given // type throughout the whole map. Allows for the given smell not to be able // to pass through tile-types from the given "impassable" list public void propagateSmellFromRoot(Vector2 root, SmellType type, List <TileType> impassable) { Queue <PropagatingSmell> openList = new Queue <PropagatingSmell>(); HashSet <Vector2> closedList = new HashSet <Vector2>(); openList.Enqueue(new PropagatingSmell(1, root)); while (openList.Count > 0) { PropagatingSmell current = openList.Dequeue(); // If we've already reached this cell, move on if (closedList.Contains(current.location)) { continue; } // Set the smell in this cell, add it to closed list int curX = (int)current.location.x; int curY = (int)current.location.y; float smellValue = 1.0f / (current.cellsAway * current.cellsAway); //Debug.Log("Setting at : " + curX + ", " + curY); smellArray[curX, curY].addToSmell(type, smellValue); closedList.Add(new Vector2(curX, curY)); // Add the neighbors of this cell if they aren't in the impassable list // Up Neieghbor if (curY < GameManager.SIZE - 1) { TileType neighborType = boardArray[curX, curY + 1]; if (!impassable.Contains(neighborType)) { openList.Enqueue(new PropagatingSmell(current.cellsAway + 1, new Vector2(curX, curY + 1))); } } // Right Neighbor if (curX < GameManager.SIZE - 1) { TileType neighborType = boardArray[curX + 1, curY]; if (!impassable.Contains(neighborType)) { openList.Enqueue(new PropagatingSmell(current.cellsAway + 1, new Vector2(curX + 1, curY))); } } // Down Neighbor if (curY > 0) { TileType neighborType = boardArray[curX, curY - 1]; if (!impassable.Contains(neighborType)) { openList.Enqueue(new PropagatingSmell(current.cellsAway + 1, new Vector2(curX, curY - 1))); } } // Left Neighbor if (curX > 0) { TileType neighborType = boardArray[curX - 1, curY]; if (!impassable.Contains(neighborType)) { openList.Enqueue(new PropagatingSmell(current.cellsAway + 1, new Vector2(curX - 1, curY))); } } } }