/// <summary> /// exchanges the content of <paramref name="other"/> and this. /// </summary> public override void Swap(VectorBase other) { if (!m_IsLocked) { throw new ApplicationException("works only in locked mode."); } if (!other.IsLocked) { throw new ArgumentException("other object must be locked.", "other"); } int N = this.m_Part.LocalLength; if (other.Part.LocalLength != N) { throw new ArgumentException("mismatch in vector size."); } //BLAS.dswap(N, (other as RefVector).m_Storage, 1, m_Storage, 1); ilPSP.Threading.Paralleism.For(0, N, delegate(int i0, int iE) { unsafe { //fixed (double* pa = &(other as RefVector).m_Storage[0], pb = &this.m_Storage[0]) { double *pa = (other as MtVector).m_StorageAddr, pb = this.m_StorageAddr; double tmp; for (int i = i0; i < iE; i++) { tmp = pa[i]; pa[i] = pb[i]; pb[i] = tmp; } } }); }
public Hero(Game game, VectorBase pos, HeroSave save, Pronoun pronoun, string name) : base(game, pos.x, pos.y, Option.HeroHealthStart, new Noun("Hero"), pronoun) { HeroClass = save.HeroClass.Clone(); Inventory = save.Inventory.clone(); Equipment = save.Equipment.clone(); BackPack = save.BackPack.clone(); Crucible = save.Crucible.clone(); ExperienceCents = save.ExperienceCents; Gold = save.Gold; // Hero state is cloned so that if they die in the dungeon, they lose // anything they found. RefreshLevel(false); HeroClass.Bind(this); // Give the hero energy so we can act before all of the monsters. Energy.CurrentEnergy = Energy.ActionCost; // Start with some initial ability to rest so we aren't weakest at the very // beginning. Food = save.Food; Health = save.Health; Charge = save.Charge; this.Name = name; }
/// <summary> /// Multiply with other vector element-wise /// </summary> /// <param name="other">Other vector</param> public override void MultiplyElementWise(VectorBase other) { if (!this.IsLocked || !other.IsLocked) { throw new ApplicationException("works only in locked mode"); } clVector _other = other as clVector; if (_other == null) { throw new ArgumentException("other must be of type clVector.", "other"); } if (_other.Part.LocalLength != this.Part.LocalLength) { throw new ArgumentException("mismatch in vector size."); } cl.SetKernelArg(clmew, 0, d_data); cl.SetKernelArg(clmew, 1, _other.GetDevicePointer()); cl.SetKernelArg(clmew, 2, size); int[] global = { globalsize }; int[] local = { localsize }; cl.EnqueueNDRangeKernel(device.cq, clmew, 1, global, local); }
// Starting at [pos], recursively walk along all paths that proceed towards // [start]. private void WalkBack(VectorBase pos, List <VectorBase> walked, List <Direction> directions) { if (walked.Contains(pos)) { return; } walked.Add(pos); foreach (var dir in Direction.All) { var here = pos + dir; var bounds = new Rect(0, 0, _distances.GetUpperBound(0), _distances.GetUpperBound(1)); if (!bounds.Contains(here)) { continue; } if (here == Start - _offset) { // If this step reached the target, mark the direction of the step. directions.Add(dir.rotate180()); } else if (_distances[here.x, here.y] >= 0 && _distances[here.x, here.y] < _distances[pos.x, pos.y]) { WalkBack(here, walked, directions); } } }
private static Actor ConvertFromActorJson(ActorJson source) { Actor result = null; if (source.ActorType == "Monster") { var breed = BreedFactory.Instance.Breeds[source.Properties["BreedName"].ToString()]; var positionJObject = (JObject)source.Properties["Position"]; var position = new VectorBase((int)positionJObject["x"], (int)positionJObject["y"]); var healthJObject = (JObject)source.Properties["Health"]; var health = new Stat((int)healthJObject["Current"], (int)healthJObject["Max"]); var generation = int.Parse(source.Properties["Generation"].ToString()); var monster = new Monster(null, breed, position.x, position.y, (int)health.Max, generation); monster.Health = health; result = monster; } else { throw new ApplicationException("Have not implemented peristance for actor type: " + source.ActorType); } return(result); }
private void _carve(VectorBase pos, TileType type = null) { SetTile(pos, type ?? TileTypeFactory.Instance.Floor); // if non is stated, default is floor //print (pos.x +","+ pos.y); _regions[pos.x, pos.y] = _currentRegion; }
private bool IsValidRangedPosition(VectorBase position) { // Ignore tiles that are out of range. var toHero = position - Game.Hero.Position; if (toHero > maxRange) { return(false); } // TODO: Being near max range reduces damage. Should try to be within // max damage range. // Don't go point-blank. if (toHero.kingLength() <= 2) { return(false); } // Ignore occupied tiles. var actor = Game.CurrentStage.ActorAt(Position); if (actor != null && actor != Monster) { return(false); } // Ignore tiles that don't have a line-of-sight to the hero. return(_hasLosFrom(position)); }
/// Creates a [RayAction] radiating from [_from] centered on [_to] (which /// may be the same as [_from] if the ray is a full circle. It applies /// [_attack] to each touched tile. The rays cover a chord whose width is /// [fraction] which varies from 0 (an infinitely narrow line) to 1.0 (a full /// circle. public RayAction(VectorBase from, VectorBase to, Attack attack, double fraction) { _from = from; _attack = (RangedAttack)attack; _to = to; // Don't hit the creator of the cone. _hitTiles.Add(_from); // We "fill" the cone by tracing a number of rays. We need enough of them // to ensure there are no gaps when the cone is at its maximum extent. var circumference = Math.PI * 2 * _attack.Range; var numRays = Math.Ceiling(circumference * fraction); // Figure out the center angle of the cone. var offset = _to - _from; // TODO: Make atan2 getter on VectorBase? var centerTheta = 0.0; if (_from != _to) { centerTheta = Math.Atan2(offset.x, offset.y); } // Create the rays. for (var i = 0; i < numRays; i++) { var range = (i / (numRays - 1)) - 0.5; _rays.Add(centerTheta + range * (Math.PI * 2 * fraction)); } }
private void TrimRay() { for (var index = _rays.Count - 1; index > 0; index--) { var ray = _rays[index]; var pos = new VectorBase((int)(_from.x + Math.Round(Math.Sin(ray) * _radius)), (int)(_from.y + Math.Round(Math.Cos(ray) * _radius))); // Kill the ray if it's obstructed. if (!Game.CurrentStage[pos].IsTransparent) { _rays.RemoveAt(index); continue; } // Don't hit the same tile twice. if (_hitTiles.Contains(pos)) { continue; } AddEvent(EventType.Cone, null, _attack.Element, pos, null, null); _hitTiles.Add(pos); // See if there is an actor there. var target = Game.CurrentStage.ActorAt(pos); if (target != null && target != Actor) { // TODO: Modify damage based on range? _attack.Perform(this, Actor, target, false); } } }
internal override void SpMV_Local_Start(double alpha, VectorBase a, double beta, VectorBase acc) { if (!m_IsLocked) { throw new ApplicationException("object must be locked."); } clVector _a = a as clVector; clVector _acc = acc as clVector; if (_a == null) { throw new ArgumentException("a must be of type clVector.", "a"); } if (_acc == null) { throw new ArgumentException("acc must be of type clVector.", "acc"); } SetArguments(alpha, _a, beta, _acc); int[] local = { localsize }; int[] global = { globalsize }; localEvent = cl.EnqueueNDRangeKernel(device.cq, clmultiply, 1, global, local); }
/// <summary> /// no operation /// </summary> internal override void SpMV_Local_Middle(double alpha, VectorBase a, double beta, VectorBase acc) { if (!m_IsLocked) { throw new ApplicationException("object must be locked."); } }
/// <summary> /// For each <em>j</em>, <br/> /// this[j] = this[j]*<paramref name="other"/>[j] /// </summary> /// <param name="other"></param> public override void MultiplyElementWise(VectorBase other) { if (!this.IsLocked || !other.IsLocked) { throw new ApplicationException("works only in locked mode"); } CudaVector _other = other as CudaVector; if (_other == null) { throw new ArgumentException("other must be of type CudaVector.", "other"); } if (_other.Part.LocalLength != this.Part.LocalLength) { throw new ArgumentException("mismatch in vector size."); } int offset = 0; cu.ParamSetp(cumew, offset, d_data); offset += sizeof(long); cu.ParamSetp(cumew, offset, _other.GetDevicePointer()); offset += sizeof(long); cu.ParamSeti(cumew, offset, size); offset += sizeof(uint); cu.ParamSetSize(cumew, (uint)offset); cu.FuncSetBlockShape(cumew, blocksize, 1, 1); cu.LaunchGrid(cumew, blockcountfull, 1); }
private void addMaze() { // Fill in all of the empty space with mazes. for (var x = 1; x < _dungeonWidth; x += 2) { for (var y = 1; y < _dungeonHeight; y += 2) { var pos = new VectorBase(x, y); if (GetTile(pos).Type != TileTypeFactory.Instance.Wall) { continue; //ignore already carved spaces } _growMaze(pos); } } _connectRegions(); _removeDeadEnds(); //function Marrt added to streamline corridors if (streamLine) { _streamLineCorridors(); } }
/// <summary> /// For each <em>j</em>, <br/> /// this[j] = this[j]*<paramref name="other"/>[j] /// </summary> /// <param name="other"></param> public override void MultiplyElementWise(VectorBase other) { if (!m_IsLocked) { throw new ApplicationException("works only in locked mode."); } if (!other.IsLocked) { throw new ArgumentException("other object must be locked.", "other"); } int N = this.m_Part.LocalLength; if (other.Part.LocalLength != N) { throw new ArgumentException("mismatch in vector size."); } MtVector o = (other as MtVector); ilPSP.Threading.Paralleism.For(0, N, delegate(int i0, int iE) { for (int i = i0; i < iE; i++) { this.m_Storage[i] *= o.m_Storage[i]; } }); }
public void VectorBaseCount() { tlog.Debug(tag, $"VectorBaseCount START"); using (View view = new View()) { var testingTarget = new VectorBase(view.SwigCPtr.Handle, false); Assert.IsNotNull(testingTarget, "Should be not null!"); Assert.IsInstanceOf <VectorBase>(testingTarget, "Should be an Instance of VectorBase!"); try { var result = testingTarget.Count(); tlog.Debug(tag, "Count : " + result); } catch (Exception e) { tlog.Debug(tag, e.Message.ToString()); Assert.Fail("Caught Exception: Failed!"); } testingTarget.Dispose(); } tlog.Debug(tag, $"VectorBaseCount END (OK)"); }
/// Gets the distance from the starting position to [pos], or `null` if there /// is no path to it. public int?GetDistance(VectorBase pos) { pos -= _offset; var bounds = new Rect(0, 0, _distances.GetUpperBound(0), _distances.GetUpperBound(1)); if (!bounds.Contains(pos)) { return(null); } // Lazily search until we reach the tile in question or run out of paths to // try. while (_open.Count != 0 && _distances[pos.x, pos.y] == _unknown) { ProcessNext(); } // Debugger the distances Debug(_distances, pos); var distance = _distances[pos.x, pos.y]; if (distance == _unknown || distance == _unreachable) { return(null); } return(distance); }
/// Randomly selects an open tile in the stage. Makes [tries] attempts and /// chooses the one most distance from some point. Assumes that [scent2] has /// been filled with the distance information for the target point. /// /// This is used during level creation to place stronger [Monster]s and /// better treasure farther from the [Hero]'s starting location. public VectorBase FindDistantOpenTile(int tries = 0) { RefreshDistances(); var bestDistance = -1; VectorBase best = null; for (var i = 0; i < tries; i++) { var pos = FindOpenTile(); if (pos == null) { } var distance = _heroPaths.GetDistance(pos); if (distance == null) { } if (distance > bestDistance) { best = pos; bestDistance = distance.Value; } } if (best == null) { } return(best); }
public void Debug <T>(T[,] matrix, VectorBase to) { //var mazeDebug = string.Empty; //mazeDebug += "\r\n"; //mazeDebug += "\r\n--------------------------------------------------------------"; //mazeDebug += "\r\n-- Distances : To = [" + to.x + "," + to.y + "]"; //mazeDebug += "\r\n--------------------------------------------------------------"; //mazeDebug += "\r\n"; //mazeDebug += " ++ "; //int width = matrix.GetUpperBound(0); //int height = matrix.GetUpperBound(0); //for (var columnIndex = 0; columnIndex < width; columnIndex++) //{ // mazeDebug += string.Format(" {0,2} ", columnIndex); //} //mazeDebug += "\r\n"; //for (var rowIndex = 0; rowIndex < height; rowIndex++) //{ // mazeDebug += string.Format(" {0,2} ", rowIndex); // for (var columnIndex = 0; columnIndex < width; columnIndex++) // { // var tile = matrix[columnIndex, rowIndex]; // mazeDebug += string.Format(" {0,2} ", tile); // } // mazeDebug += "\r\n"; //} //logger.Info(mazeDebug); }
public override void AddMaze() { // Want to make the maze ? if (true) { // Fill in all of the empty space with mazes. for (var x = 1; x < stage.Width; x += 2) { for (var y = 1; y < stage.Height; y += 2) { var pos = new VectorBase(x, y); if (GetTile(pos).Type != TileTypeFactory.Instance.Wall) { continue; //ignore already carved spaces } _growMaze(pos); } } _connectRegions(); _removeDeadEnds(); foreach (var room in Rooms) { OnDecorateRoom(room); } } //function Marrt added to streamline corridors if (streamLine) { _streamLineCorridors(); } }
public void DrawVisibleItems(BufferContainer buffer, Appearence[,] source, VectorBase heroPosition) { var viewPortMatrix = GetMatrixViewPort(source, heroPosition); var matrixWidth = viewPortMatrix.GetUpperBound(0) + 1; var matrixHeight = viewPortMatrix.GetUpperBound(1) + 1; for (var rowIndex = 0; rowIndex < matrixHeight; rowIndex++) { for (var columnIndex = 0; columnIndex < matrixWidth; columnIndex++) { var currentTile = viewPortMatrix[columnIndex, rowIndex].Clone(); if (!currentTile.IsExplored || currentTile.IsInShadow || currentTile.IsHidden) { buffer.Write($" ", columnIndex, rowIndex, ConsoleColor.DarkRed); } else { var foreGroundColour = currentTile.ForeGroundColor == null ? ConsoleColor.White : ColourUtilities.ConvertToConsoleColor(currentTile.ForeGroundColor); var backGroundColour = currentTile.BackGroundColor == null ? ConsoleColor.Black : ColourUtilities.ConvertToConsoleColor(currentTile.BackGroundColor); buffer.Write(currentTile.Glyph, columnIndex, rowIndex, foreGroundColour, backGroundColour); } } } }
public override VectorBase Add(VectorBase other) { if (other.Length != this.Length) { throw new ArgumentException("Unequal vector lengths"); } CompositeVector ocv = other as CompositeVector; if (ocv != null && ocv._componentLengths() == this._componentLengths()) { return(new CompositeVector( _vectors.Zip( ocv._vectors, (VectorBase a, VectorBase b) => a.Add(b) ) )); } double[] result = new double[Length]; for (int i = 0; i < Length; i++) { result[i] = this[i] + other[i]; } return(new FullVector(result)); }
/// <summary> /// this = this + <paramref name="alpha"/>*<paramref name="other"/>; /// </summary> /// <param name="alpha"></param> /// <param name="other"></param> public override void Acc(double alpha, VectorBase other) { if (!m_IsLocked) { throw new ApplicationException("works only in locked mode."); } if (!other.IsLocked) { throw new ArgumentException("other object must be locked.", "other"); } int N = this.m_Part.LocalLength; if (other.Part.LocalLength != N) { throw new ArgumentException("mismatch in vector size."); } //BLAS.daxpy(N, alpha, (other as RefVector).Storage, 1, this.m_Storage, 1); unsafe { double *p_tis = this.m_StorageAddr, p_oda = (other as MtVector).m_StorageAddr; ilPSP.Threading.Paralleism.For(0, N, delegate(int i0, int iE) { for (int i = i0; i < iE; i++) { p_tis[i] += alpha * p_oda[i]; // } } }); } }
public override VectorBase Add(VectorBase other) { if (other.Length != this.Length) { throw new ArgumentException("Adding vectors of unequal length."); } if (other is ZeroVector) { return(this); } if (other is BasisVector) { return(other.Add(this)); } double[] result = new double[Length]; for (int i = 0; i < Length; i++) { result[i] = this[i] + other[i]; } return(new FullVector(result)); }
public override VectorBase Add(VectorBase other) { if (other.Length != this.Length) { throw new ArgumentException("Unequal vector lengths."); } if (other is ZeroVector) { return(this); } if (other is BasisVector) { BasisVector obv = other as BasisVector; if (obv.Index == this.Index) { return(new BasisVector(obv.Value + this.Value, Index, Length)); } } VectorBase result = other.Copy(); result.SetValueAtIndex(result[Index] + Value, Index); return(result); }
public void ReplaceGenericWallWithDirectionalWalls() { for (var widthIndex = 0; widthIndex < stage.Width; widthIndex++) { for (var heightIndex = 0; heightIndex < stage.Height; heightIndex++) { var pos = new VectorBase(widthIndex, heightIndex); var tile = GetTile(pos); if (tile.Type.Name == "wall") { var numberOfSurroundingWalls = CalculateSurroundingWalls(pos); ReformateWall(numberOfSurroundingWalls, pos); } if (tile.Type.Name == "open door") { var numberOfSurroundingWalls = CalculateSurroundingWalls(pos); ReformateDoor(numberOfSurroundingWalls, pos, true); } if (tile.Type.Name == "closed door") { var numberOfSurroundingWalls = CalculateSurroundingWalls(pos); ReformateDoor(numberOfSurroundingWalls, pos, false); } } } }
public Los(VectorBase start, VectorBase end) { End = end; Start = start; CalculatePoints(); }
/// /// These functions will transform walls into the ascii line art we want /// to use. /// public void CreateSolidTiles(TileType floor, TileType wall) { if (floor == null) { floor = TileTypeFactory.Instance.Floor; } for (var widthIndex = 0; widthIndex < stage.Width; widthIndex++) { for (var heightIndex = 0; heightIndex < stage.Height; heightIndex++) { var connectedToAWall = false; var pos = new VectorBase(widthIndex, heightIndex); foreach (VectorBase dir in Direction.All) { if ((pos + dir).x < 0 || (pos + dir).x >= stage.Width - 1 || (pos + dir).y < 0 || (pos + dir).y >= stage.Height - 1) { continue; } if (GetTile((pos + dir)).Type == floor) { connectedToAWall = true; break; } } if (!connectedToAWall) { SetTile(pos, TileTypeFactory.Instance.Solid); } } } }
public void CarvePath(VectorBase from, VectorBase to, TileType floorTile) { var los = new Los(from, to); foreach (var pos in los) { if (pos == to) { break; } VectorBase position = (VectorBase)pos; // Make slightly wider passages. SetTile(position, floorTile); if (position.x + 1 < stage.Width) { SetTile(position.offsetX(1), floorTile); } if (position.y + 1 < stage.Height) { SetTile(position.offsetY(1), floorTile); } } }
public bool CanOccupy(VectorBase pos) { if (pos.x < 0) { return(false); } if (pos.x >= Game.CurrentStage.Width) { return(false); } if (pos.y < 0) { return(false); } if (pos.y >= Game.CurrentStage.Height) { return(false); } if (Game.CurrentStage[pos].IsPassable) { return(true); } return(Game.CurrentStage[pos].IsTraversable && CanOpenDoors); }
public override void ChangePosition(VectorBase from, VectorBase to) { if (Game != null && Game.CurrentStage != null) { Game.CurrentStage.moveActor(from, to); } }
internal static HandleRef getCPtr(VectorBase obj) { return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr; }