//----------------------------------------------------------------------------------- // which directions are allowed now? //----------------------------------------------------------------------------------- protected List <Direction> allowedDirections() { // if two or more potential choices are an equal distance from the target, // the decision between them is made in the order of up > left > down (> right) List <Direction> directions = new List <Direction>(); Direction direction = walker.direction(); WaypointNode node = walker.getCurrentNode(); if (node.getFront() != null && !direction.isOpposite(Direction.Front)) { directions.Add(Direction.Front); } if (node.getLeft() != null && !direction.isOpposite(Direction.Left)) { directions.Add(Direction.Left); } if (node.getBack() != null && !direction.isOpposite(Direction.Back)) { directions.Add(Direction.Back); } if (node.getRight() != null && !direction.isOpposite(Direction.Right)) { directions.Add(Direction.Right); } return(directions); }
protected virtual Direction directionFrightened() { // ghosts use a pseudo-random number generator (PRNG) // to pick a way to turn at each intersection when frightened System.Random rnd = new System.Random(); Direction direction = (Direction)rnd.Next(4); if (validDirection(direction)) { return(direction); } // if a wall blocks the chosen direction, // the virus then attempts the remaining directions in this order: // up, left, down, and right, until a passable direction is found WaypointNode node = walker.getCurrentNode(); if (node.getFront() != null) { return(Direction.Front); } if (node.getLeft() != null) { return(Direction.Left); } if (node.getBack() != null) { return(Direction.Back); } if (node.getRight() != null) { return(Direction.Right); } return(Direction.None); }
//----------------------------------------------------------------------------------- // find out if we the virus can move in the specified direction //----------------------------------------------------------------------------------- protected bool validDirection(Direction direction) { WaypointNode node = walker.getCurrentNode(); if (direction == Direction.Front) { return(node.getFront() != null); } if (direction == Direction.Back) { return(node.getBack() != null); } if (direction == Direction.Left) { return(node.getLeft() != null); } if (direction == Direction.Right) { return(node.getRight() != null); } return(false); }