/// <summary> /// Adds a new Space to the repository, identified by the specified parameter. /// </summary> public void AddSpace(string identifier, ISpace tuplespace) { if (!this.spaces.ContainsKey(identifier)) { this.spaces.Add(identifier, tuplespace); } }
public Game(ISpace ts) { this.rng = new Random(Environment.TickCount); this.ts = ts; this.view = new View(ts); this.food = new FoodDispenser(ts); }
public Direction ChangeDirection(ISnake snake, ISpace space, IReadOnlyCollection <ISnake> snakes) { // Si no me choco adelante, sigo igual IPosition pos = snake.MoveNew(); if (pos.IsValid(space.TopX, space.TopY) && (space[pos.X, pos.Y] == 0)) { return(snake.Direction); } //Busco nueva dirección clockwise para no chocarme foreach (Direction dir in new[] { 0, 1, 2, 3 }) { pos = snake.MoveNew(dir); if (!pos.IsValid(space.TopX, space.TopY)) { continue; } if (space[pos.X, pos.Y] > 0) { continue; } return(dir); } return(snake.Direction); //TODO: no meterse en callejones }
public ISpace <double> GetInverseSpace(ISpace <double> space) { var matrix = DenseMatrix.OfArray(space.Storage); var inverse = matrix.Inverse(); return(new MdnnDoubleSpace(inverse.Storage.ToArray())); }
public void OnAdditionToSpace(ISpace newSpace) { foreach(OperationalMachine o in machines) newSpace.Add(o); foreach(BaseModel m in models) newSpace.Add(m); }
public static void TransitLocation(string name) { IGame.buffer.MoveToLocation(name); int index = SceneUtility.GetBuildIndexByScenePath("Assets/Scenes/Locations/" + name + ".unity"); ISpace.LoadLevel(index); }
private void LoadGameFromSlot(int index) { if (IGame.Exist(index)) { ISpace.LoadGameFromIndex(index); } }
/// <summary> /// Sets the collision information of the entity to another collidable. /// </summary> /// <param name="newCollisionInformation">New collidable to use.</param> public void SetCollisionInformation(EntityCollidable newCollisionInformation) { //Temporarily remove the object from the space. //The reset process will update any systems that need to be updated. //This is not thread safe, but this operation should not be performed mid-frame anyway. ISpace space = Space; if (space != null) { Space.Remove(this); } CollisionInformation.Entity = null; if (isDynamic) { Initialize(newCollisionInformation, mass); } else { Initialize(newCollisionInformation); } if (space != null) { space.Add(this); } }
public override void Initialise(ISpace space) { SpaceOccupied = space; transform.name = "BishopPiece"; CanMove = true; MovementRules = new BishopMovementRules(); }
//public override byte Width { get; set; } #endregion #region Constructors public LightShip(ISpace game, int coordX, int coordY, bool active, uint speed, uint counter, byte hitpoints, byte lifes, SpaceObject source = SpaceObject.LightShip) : base(game, coordX, coordY, active, speed, counter, hitpoints, lifes, source) { SetPosition(); }
/// <summary> /// Called after the object is added to a space. /// </summary> /// <param name="newSpace"></param> public override void OnAdditionToSpace(ISpace newSpace) { for (int i = 0; i < solverUpdateables.Count; i++) { solverUpdateables[i].OnAdditionToSpace(newSpace); } }
private void ResetSpace() { _counter = 0; //_list = new List<TestTuple>(); _space = SpaceFactory.UnsafeLocal(); _spaceProxy = _space.CreateProxy(); }
public ChatSender(string user, ISpace space, CancellationTokenSource source, Chat chat) { LoggedInUser = user; ChatSpace = space; CancelTokenSource = source; Chat = chat; }
public SpaceField(ISpace space, int x, int y, bool multipleAnchorsAllowed) { Space = space; X = x; Y = y; MultipleAnchorsAllowed = multipleAnchorsAllowed; }
public void SetInitialValues(ISpace <TKey> initialValuesCollection) { foreach (KeyValuePair <TKey, IPossible> valuePair in initialValuesCollection) { TKey k = valuePair.Key; if (Puzzle.Space[k].Values != valuePair.Value) { if (valuePair.Value.SetEquals(Puzzle.Space.DefaultValue)) { Puzzle.Space[k].Locked = false; } else { Puzzle.Space[k].Locked = true; } if (Puzzle.Space[k].SetValues(valuePair.Value)) { Puzzle.Space[k].AcceptChanges(); Keys <TKey> keysChanged = new Keys <TKey>() { k }; IJob <TKey> job = new JobSearch <TKey>("Initial", keysChanged); this.Add(job); } } } }
private IEnumerable <ISpace> GetDiagonalSpaces(IBoard board, ISpace space, Func <int, int> incrementX, Func <int, int> incrementY) { var spaces = new List <ISpace>(); var x = space.X; var y = space.Y; var piece = board.Pieces[x, y]; x = incrementX(x); y = incrementY(y); while (board.IsInBounds(x, y)) { if (board.Pieces[x, y] == null) { spaces.Add(board.Spaces[x, y]); } else { if (!board.Pieces[x, y].Team.Equals(piece.Team)) { spaces.Add(board.Spaces[x, y]); } break; } x = incrementX(x); y = incrementY(y); } return(spaces); }
public bool TryGetSpace(IEntity entity, ISpace dreamPosition) { var res = FullSpaces.Any(s => s.Area.Intersects(dreamPosition.Area)); if (!res) entitiesSpaces.Add(Tuple.Create(entity, dreamPosition)); return !res; }
public void FreeSpace(IEntity entity, ISpace space) { int index = entitiesSpaces.FindIndex(t => t.Item1 == entity && t.Item2 == space); if(index == -1 ) throw new InvalidOperationException("Record is not in collection."); entitiesSpaces.RemoveAt(index); }
/// <summary> /// Gets a value that indicates whether a move has any captures in a particular direction /// on the specified game board. /// </summary> /// <param name="board">The game board.</param> /// <param name="player">The player whose turn it is for the specified board.</param> /// <param name="move">The move to assess.</param> /// <param name="direction">The direction to assess (as a space with a relative position).</param> /// <returns>True if the move has any captures in the given direction; otherwise, false.</returns> private static bool DoesMoveHaveCaptureInDirection( IList <IList <State> > board, State player, ISpace move, ISpace direction) { bool isFirstState = true; // Check the spaces in the given direction looking for a capture // or for conditions indicating that no capture is possible. // Halting the iteration as early as possible avoids the full // enumeration of GetStatesInDirection, saving some time. foreach (var state in GetStatesInDirection(board, move, direction)) { // Found an empty space, so there is no capture. if (state == State.None) { return(false); } // Found a space with the player's piece. If it's the first space, // then there is no capture; otherwise, there is a capture. if (state == player) { return(!isFirstState); } isFirstState = false; } // All the spaces in the direction are occupied by the opponent's pieces. return(false); }
void Awake() { int[,] boardArr; var spaceArr = new ISpace<Tiles>[dims, dims]; board = new TileSudokuBoard((int) dims, spaceArr); switch (SceneManager.GetActiveScene().name) { case "Tutorial": boardArr = tutorialBoard; board.EndPos = new int[] {2, 2}; break; case "MainGame": default: Debug.Log ("name is " + SceneManager.GetActiveScene().name); boardArr = normalBoard; break; } if (prefab==null) throw new System.Exception("missing spacewrapper prefab"); //var spaceArr = new ISpace<Tiles>[dims, dims]; for (var i = 0; i < dims; ++i) for (var j = 0; j < dims; ++j) { spaceArr [i, j] = CreateSpaceWrapper (i, j, (Tiles)boardArr [i, j]); Debug.Log ("Set Tile " + boardArr [i, j].ToString () + " at position" + i.ToString () + ", " + j.ToString()); } }
/// <summary> /// Performs a move. /// </summary> /// <param name="move">The move.</param> /// <returns>A list of the spaces affected by the move, starting with the space /// of the move and including the spaces of all the pieces captured by the move.</returns> private IList <ISpace> Move(ISpace move) { var changedSpaces = new List <ISpace>(); // If move is a pass, return an empty list. if (move != null) { var newBoard = (IList <IList <State> >)Move( Board, CurrentPlayer == State.One, move); for (int row = 0; row < newBoard.Count; ++row) { for (int column = 0; column < newBoard[row].Count; ++column) { if (newBoard[row][column] != Board[row][column]) { changedSpaces.Add(new Space(row, column)); } } } changedSpaces.Remove(move); changedSpaces.Insert(0, move); Board = newBoard; } Moves.Add(move); return(changedSpaces); }
public override void OnAdditionToSpace(ISpace newSpace) { //Add any supplements to the space too. newSpace.Add(Body); //This character controller requires the standard implementation of Space. ((Space)newSpace).BoundingBoxUpdater.Finishing += ExpandBoundingBox; }
public SpaceGui(ISpace space, Color color, SpaceRegion spaceRegion, Rectangle bounds = new Rectangle()) { this.Space = space; this.Color = color; this.Bounds = bounds; this.SpaceRegion = spaceRegion; }
public ISpace GetOffsetSpace(ISpace initialSpace, int offset) { var initialSpaceIndex = _spaces.IndexOf(initialSpace); var finalSpaceIndex = GetOffsetSpaceIndex((uint)initialSpaceIndex, offset); return(_spaces[(int)finalSpaceIndex]); }
/// <summary> /// Sets a peice on the space. /// </summary> /// <param name="peice">The peice prefab to be set.</param> /// <param name="space">The space where the peice will be set.</param> /// <returns>The set peice.</returns> public GameObject SetPiece(GameObject peice, ISpace space) { GameObject pieceGo = null; try { pieceGo = Instantiate(peice, space.GetWorldCoords(), Quaternion.Euler(0, 0, 0)); var piece = pieceGo.GetComponent <IPiece>(); if (pieceLayout[space.X, space.Y].StartsWith("W")) { piece.Team = "W"; piece.Rotation = Rotation.South; } else { piece.Team = "B"; piece.Rotation = Rotation.North; } piece.Initialise(space); //piece.MoveableSpaces = piece.MovementRules.GetLegalMoves(Board, piece); } catch (Exception e) { Debug.LogError("Error setting piece at " + space.X + ", " + space.Y); } return(pieceGo); }
public void FillSpace( ISpace <int> space, ISpace <int> prevSpace, ISpace <int> prevPrevSpace ) { var nr = spaceNeighbourhoodRadius; var ss = space.spaceSize; var n1 = 0; var c = prevSpace[nr - 1]; var n2 = prevSpace[nr]; for (var x = nr; x < ss - nr; x++) { n1 = c; c = n2; n2 = prevSpace[x + 1]; var pc = prevPrevSpace[x]; var combinedState = 0; combinedState = combinedState * stateCount + pc; combinedState = combinedState * stateCount + n2; combinedState = combinedState * stateCount + c; combinedState = combinedState * stateCount + n1; space[x] = table[combinedState]; } }
/// <summary> /// Called before an object is removed from its space. /// </summary> public override void OnRemovalFromSpace(ISpace oldSpace) { for (int i = 0; i < solverUpdateables.Count; i++) { solverUpdateables[i].OnRemovalFromSpace(oldSpace); } }
/// <summary> /// This method is looking for a subset that contains values that /// the outer set does not contain /// </summary> /// <param name="outerSet"></param> /// <param name="space"></param> /// <returns></returns> public IPossible ReducedSetValues(IEnumerable <TKey> outerSet, ISpace <TKey> space) { Keys <TKey> oSet = new Keys <TKey>(outerSet); oSet.ExceptWith(this); IPossible reducedValues = space.AllValuesAt(this); // Get all values in subset combination foreach (TKey keyInner in this) { Possible innerValues = new Possible(space[keyInner]); foreach (TKey keyOuter in oSet) { innerValues.FilterOut(space[keyOuter]); } // Each innerKey must have an exclusive value not in the outer set if (innerValues.Count > 0) { reducedValues.IntersectPossible(innerValues); } else { reducedValues.Clear(); break; } } return(reducedValues); }
private static ISpace[] GetAdjacentSpaces(IBoard board, ISpace targetSpace) { var spaces = new ISpace[4]; int index = 0; for (int i = -1; i < 2; i++) { if (i != 0) { if (board.IsInBounds(targetSpace.X + i, targetSpace.Y)) { spaces[index] = board.Spaces[targetSpace.X + i, targetSpace.Y]; } if (board.IsInBounds(targetSpace.X, targetSpace.Y + i)) { spaces[index + 1] = board.Spaces[targetSpace.X, targetSpace.Y + i]; } index += 2; } } return(spaces); }
private static ISpace[] GetDiagonalSpaces(IBoard board, ISpace targetSpace) { var spaces = new ISpace[4]; int index = 0; for (int x = -1; x < 2; x++) { if (x != targetSpace.X) { for (int y = -1; y < 2; y++) { if (y != targetSpace.Y) { if (board.IsInBounds(x, y)) { spaces[index] = board.Spaces[x, y]; } index++; } } } } return(spaces); }
public override void Expand(ISpace space, Point markedPoint, Point unmarkedPoint) { Point prev = markedPoint; Point cur = unmarkedPoint; ScreenConstructionParameters scp = new ScreenConstructionParameters(cur, TerminalName, m_fractalCreator); space.AddScreen(scp, this.MissionNodeID); space.ConnectTwoWay(prev, cur, (Connection)space.GetConnection(prev, cur)); if (m_objectPopulators.Count >= 1) scp.ObjectPopulator = m_objectPopulators[0]; if (m_postProcessors.Count >= 1) scp.PostProcessor = m_postProcessors[0]; for (int i = 1; i < m_length; ++i) { prev = cur; cur = DirectionUtils.Move(cur, m_bestEvaledDirection); scp = new ScreenConstructionParameters(cur, TerminalName, m_fractalCreator); space.AddScreen(scp, this.MissionNodeID); space.ConnectTwoWay(prev, cur, Connection.Open); if (m_objectPopulators.Count > i) scp.ObjectPopulator = m_objectPopulators[i]; if (m_postProcessors.Count > i) scp.PostProcessor = m_postProcessors[i]; } prev = cur; space.ConnectOneWay(prev, m_bestEvaledDirection.Move(prev), Connection.Door); space.ConnectOneWay(prev, m_bestEvaledDirection.RotationCW.Move(prev), Connection.Door); space.ConnectOneWay(prev, m_bestEvaledDirection.RotationCCW.Move(prev), Connection.Door); }
public View(ISpace ts) : base("view", ts) { this.width = TerminalInfo.GameboardColumns; this.height = TerminalInfo.GameboardRows; this.screenBuffer = new char[this.width, this.height]; Console.CursorVisible = false; Console.SetWindowSize(this.width + 1, this.height + 1); }
public ISpace AddSpaceToRightAndAdvance(ISpace activeSpace, ISpace newSpace) { activeSpace.Right = newSpace; newSpace.Left = activeSpace; activeSpace = activeSpace.Right; return(activeSpace); }
public static void SaveText(ISpace <TKey> space) { Stream stream = new FileStream("MyFile.txt", FileMode.Create, FileAccess.Write, FileShare.None); StreamWriter writer = new StreamWriter(stream); writer.Close(); stream.Close(); }
internal void OnAdditionToSpace(ISpace space) { //Make sure it doesn't collide with anything. shape.OnAdditionToSpace(space); shape.UpdateDetectorPosition(); //Need to put the detectors in appropriate locations before adding since otherwise overloads the broadphase space.Add(shape.detector); }
void Awake() { if (prefab==null) throw new System.Exception("missing spacewrapper prefab"); var spaceArr = new ISpace<Tiles>[dims, dims]; for (var i=0; i<dims; ++i) for (var j=0; j<dims; ++j) spaceArr[i,j] = CreateSpaceWrapper(i,j); board = new TileSudokuBoard((int) dims, spaceArr); }
private IEnumerable<ISpaceRouteElement> GetToSpace(IEntity entity, Tile currentTile, ISpace destSpace) { bool found = false; ISpace currentSpace = entity.Location.Space; //currentTile.LayoutManager.FindCurrentSpace(entity); if (currentSpace == destSpace) return new FourthSpaceRouteElement(currentSpace, currentTile).ToEnumerable(); searcher.LayoutManager = currentTile.LayoutManager; searcher.StartSearch(AllSpaces.First(), currentSpace, 1, (space, layer, bundle) => { if (space == destSpace) { searcher.StopSearch(); found = true; } }); return found ? searcher.GetShortestRoute(destSpace).Select(s => new FourthSpaceRouteElement(s, currentTile)) : null; }
public override float Evaluate(ISpace space, Point markedPoint, Point unmarkedPoint) { // walk m_length tiles and verify they are all free Point cur = unmarkedPoint; for (int i = 0; i < m_length; ++i) { if (!space.IsAreaFree(cur)) return float.PositiveInfinity; cur = DirectionUtils.Move(cur, m_direction); } // went one too far, so back up to last tile in the dealio cur = DirectionUtils.Move(cur, m_direction.Opposite); int blockedCount = 0; if (!space.IsAreaFree(cur)) blockedCount++; if (!space.IsAreaFree(DirectionUtils.Move(cur, m_exitDir.RotationCW))) blockedCount++; if (!space.IsAreaFree(DirectionUtils.Move(cur, m_exitDir.RotationCCW))) blockedCount++; if (!space.IsAreaFree(DirectionUtils.Move(cur, m_exitDir))) blockedCount++; return blockedCount / 4.0f; }
public override float Evaluate(ISpace space, Point markedPoint, Point unmarkedPoint) { float bestCost = float.PositiveInfinity; // worst possible, best possible is 0 foreach (Direction dir in m_directions) { // walk m_length tiles and verify they are all free Point cur = unmarkedPoint; int counter = 0; int blockedCounter = 0; for (int i = 0; i < m_length; ++i) { if (!space.IsAreaFree(cur)) { blockedCounter = Int32.MaxValue - 5; break; } counter += 2; if (!space.IsAreaFree(dir.RotationCW.Move(cur))) blockedCounter++; if (!space.IsAreaFree(dir.RotationCCW.Move(cur))) blockedCounter++; cur = dir.Move(cur); } counter++; if (!space.IsAreaFree(cur)) blockedCounter++; // one past the end float score = (float)blockedCounter / counter; if (score < bestCost) { bestCost = score; m_bestEvaledDirection = dir; } } return bestCost; }
public override void Expand(ISpace space, Point markedPoint, Point unmarkedPoint) { Point prev = markedPoint; Point cur = unmarkedPoint; ScreenConstructionParameters scp = new ScreenConstructionParameters(cur, TerminalName, m_fractalCreator); space.AddScreen(scp, this.MissionNodeID); space.ConnectTwoWay(prev, cur, Connection.Door); for (int i = 1; i < m_length; ++i) { prev = cur; cur = DirectionUtils.Move(cur, m_direction); scp = new ScreenConstructionParameters(cur, TerminalName, m_fractalCreator); space.AddScreen(scp, this.MissionNodeID); space.ConnectTwoWay(prev, cur, Connection.Open); if (i != m_length - 1) { Point side = DirectionUtils.Move(cur, m_direction.RotationCW); space.ConnectOneWay(cur, side, Connection.Door); side = DirectionUtils.Move(cur, m_direction.RotationCCW); space.ConnectOneWay(cur, side, Connection.Door); } } prev = cur; //cur = m_direction.Move(cur, m_exitDir); space.ConnectOneWay(prev, m_direction.Move(prev), Connection.Door); space.ConnectOneWay(prev, m_direction.RotationCW.Move(prev), Connection.Door); space.ConnectOneWay(prev, m_direction.RotationCCW.Move(prev), Connection.Door); //space.ConnectOneWay(prev, cur, Connection.Door); }
void ISpaceObject.OnAdditionToSpace(ISpace newSpace) { }
public void OnRemovalFromSpace(ISpace oldSpace) { oldSpace.Remove(Model); oldSpace.Remove(joint); Model.Ent.CollisionInformation.Events.PairTouching -= onCollision; }
public void OnAdditionToSpace(ISpace newSpace) { newSpace.Add(Model); newSpace.Add(joint); Model.Ent.CollisionInformation.Events.PairTouching += onCollision; }
public override void OnAdditionToSpace(ISpace newSpace) { //Add any supplements to the space too. newSpace.Add(Body); newSpace.Add(HorizontalMotionConstraint); newSpace.Add(VerticalMotionConstraint); //This character controller requires the standard implementation of Space. ((Space)newSpace).BoundingBoxUpdater.Finishing += ExpandBoundingBox; Body.AngularVelocity = new Vector3(); Body.LinearVelocity = new Vector3(); }
public Plan(ITile tile, ISpace space) { Tile = tile; Space = space; Arguments = new List<object>(); Worths = new Dictionary<IPlayer, int>(); }
private int GetSpaceWorth(ISpace space, IPlayer player) { int worth; lock (_lock) if (_spaceWorths.TryGetValue(new Tuple<ISpace, IPlayer>(space, player), out worth)) return worth; var visited = new HashSet<ITile>(); if (space.Tile != null) visited.Add(space.Tile); var groups = new List<List<ITile>>(); foreach (ITile tile in space.AdjacentTiles.Where(t => t.HasToken(player) && !visited.Contains(t))) { var group = new List<ITile>(); var queue = new Queue<ITile>(new[] {tile}); while (queue.Count>0) { ITile query = queue.Dequeue(); visited.Add(query); group.Add(query); foreach (ITile adj in query.Space.AdjacentTiles.Where(t => t.HasToken(player) && !visited.Contains(t))) queue.Enqueue(adj); } groups.Add(group); } int[] sizes = groups.Select(g => g.Count).ToArray(); if (sizes.Length == 0 || sizes.Sum()<GameState.SmallestScoringGroup-1) worth = 0; else worth = 1+sizes.Where(i => i<GameState.SmallestScoringGroup).Sum(); lock (_lock) _spaceWorths[new Tuple<ISpace, IPlayer>(space, player)] = worth; return worth; }
private int GetSpaceWorth(ISpace space) { return GetSpaceWorth(space, Player); }
public FourthSpaceRouteElement(ISpace space, Tile parentTile) { Space = space; Tile = parentTile; }
public override void OnRemovalFromSpace(ISpace oldSpace) { //Remove any supplements from the space too. oldSpace.Remove(Body); oldSpace.Remove(HorizontalMotionConstraint); oldSpace.Remove(VerticalMotionConstraint); //This character controller requires the standard implementation of Space. ((Space)oldSpace).BoundingBoxUpdater.Finishing -= ExpandBoundingBox; SupportFinder.ClearSupportData(); Body.AngularVelocity = new Vector3(); Body.LinearVelocity = new Vector3(); }
void ISpaceObject.OnRemovalFromSpace(ISpace oldSpace) { }
internal void OnAdditionToSpace(ISpace space) { detector.CollisionInformation.collisionRules.Specific.Add(wheel.vehicle.Body.CollisionInformation.collisionRules, CollisionRule.NoBroadPhase); detector.CollisionInformation.collisionRules.Personal = CollisionRule.NoNarrowPhaseUpdate; detector.CollisionInformation.collisionRules.group = CollisionRules.DefaultDynamicCollisionGroup; }
internal void OnRemovalFromSpace(ISpace space) { space.Remove(shape.detector); shape.OnRemovalFromSpace(space); }
void ISpaceObject.OnRemovalFromSpace(ISpace oldSpace) { if(/*Ent != null &&*/ Ent.Space != null) oldSpace.Remove(Ent); //else if(mesh != null) // oldSpace.Remove(mesh); }
protected virtual void OnRemovalFromSpace(ISpace oldSpace) { }
void ISpaceObject.OnAdditionToSpace(ISpace newSpace) { //if(Ent != null) newSpace.Add(Ent); //else // newSpace.Add(mesh); }
internal void OnRemovalFromSpace(ISpace space) { detector.CollisionInformation.CollisionRules.Specific.Remove(wheel.vehicle.Body.CollisionInformation.collisionRules); }
public SpaceCandidate(IMissionQueue mission) { m_space = new SpaceImpl(new Point(0,0)); m_mission = mission; }