public SmartCPUBehaviour(IGrid grid, ISetting setting, CPUMode difficulty) { _grid = grid; _gridSimulator = new GridSimulator(grid, setting); _outputter = new OutputBestMovement(_gridSimulator); _grid.OnGroupAdd += new OnGroupAddEventHandler(OnGroupAddEvent); Debug.Log("difficulty " + difficulty + "set"); switch(difficulty) { case CPUMode.Easy: timeBeforeAction = 0.5f; timeBetweenActions = 0.5f; break; case CPUMode.Normal: timeBeforeAction = 0.5f; timeBetweenActions = 0.3f; break; case CPUMode.Hard: timeBeforeAction = 0.2f; timeBetweenActions = 0.1f; break; case CPUMode.Kusotuyo: timeBeforeAction = 0f; timeBetweenActions = 0f; break; } }
public Scene(float bandLambda, float breakingThreshold, float timeStep, int stepSize, IGrid grid) { TimeStep = timeStep; StepSize = stepSize; Stopwatch = new Stopwatch(); var center = new Vector2(grid.Width, grid.Height) / 2; var offset = -center; Nodes = grid.Vertices.Select(v => new Node(v + offset)).ToArray(); var edges = grid.Edges; Bands = new Band[edges.Count]; for (int i = 0; i < edges.Count; i++) { var edge = edges[i]; float length = Vector2.Distance(Nodes[edge.Index1].Position, Nodes[edge.Index2].Position); float restLength = 0.95f * length; Bands[i] = new Band(edge.Index1, edge.Index2, bandLambda, restLength, restLength * breakingThreshold); } BandCount = edges.Count; Impulses = new Vector2[Nodes.Length]; PreviousImpulses = new Vector2[Nodes.Length]; }
public void Init() { dims_4321_789 = new GridDimensions(4321, 789); grid_4321_789 = new Grid(dims_4321_789); grid_22_55555 = new Grid(22, 55555); iGrid_22_55555 = grid_22_55555; }
/// <summary> /// Prints the labyrinth to the console /// </summary> /// <param name="grid">the playfield</param> public void PrintLabirynth(IGrid grid) { Console.ForegroundColor = ConsoleColor.DarkCyan; Console.WriteLine(" " + new string('\u2593', (grid.TotalRows * 2) + 3)); for (int row = 0; row < grid.TotalRows; row++) { Console.Write("{0,2}", "\u2593"); for (int col = 0; col < grid.TotalCols; col++) { var currentCell = grid.GetCell(row, col); if (currentCell == GlobalConstants.PlayerSignSymbol) { Console.ForegroundColor = ConsoleColor.Green; } else { Console.ForegroundColor = ConsoleColor.DarkCyan; } Console.Write("{0,2}", currentCell); } Console.Write("{0,2}", "\u2593"); Console.WriteLine(); } Console.WriteLine(" " + new string('\u2593', (grid.TotalCols * 2) + 3)); }
public void plant_mines_on(IGrid grid) { var coordinates = _random_coordinate_picker.pick_coordinates_from(_game_difficulty.minefield_size, _game_difficulty.number_of_mines); foreach(var coordinate in coordinates) grid.plant_mine_at(coordinate); }
public Game(IGrid grid, ISetting setting) { _setting = setting; _grid = grid; currentControl = _grid; }
public Piece GetWinner(IGrid grid) { foreach (var p in new[] { Piece.X, Piece.O }) if (GetWinnableLines(grid.Size).Any(line => line.All(pos => p == grid[pos].Content))) return p; return null; }
private static void MoveRover(IGrid grid, string locationLine, string movesLine) { IDirectionParser directionParser = (IDirectionParser)container[typeof(IDirectionParser)]; ILocationParser locationParser = (ILocationParser)container[typeof(ILocationParser)]; Direction direction = directionParser.GetDirection(locationLine); Point location = locationParser.GetLocation(locationLine); IMoveSupplier supplier = (IMoveSupplier)container[typeof(IMoveSupplier)]; supplier.Init(movesLine); Rover rover = new Rover(direction, location, grid, supplier); try { rover.ExecuteMoves(); } catch (InvalidLocationException ex) { Console.WriteLine(MarsRover.IllegalLocation); } Console.WriteLine(String.Format("{0} {1} {2}", rover.Location.X, rover.Location.Y, rover.Direction)); container.Release(supplier); container.Release(directionParser); container.Release(locationParser); }
public void Run(ref IGrid grid) { var current = grid.GetRandomCell; while(current != null) { var unvisitedNeighbors = current.Neighbors.Where(x => x.Links.Count == 0); // get all neighbors of cell that does not have any links (yet) if (unvisitedNeighbors.Count() > 0) { var neighbor = unvisitedNeighbors.Sample<Cell>(); current.Link(neighbor); current = neighbor; } else { current = null; } foreach(var cell in grid) { var visitedNeighbors = cell.Neighbors.Where(x => x.Links.Count() > 0); if ((cell.Links.Count == 0 || cell.Links== null) && visitedNeighbors.Count() > 0) { current = cell; var neighbor = visitedNeighbors.Sample<Cell>(); current.Link(neighbor); break; } } } }
private void BuildGrid() { const int width = 6; const int height = 3; const float border = 0; const int quadCount = 15; grid = FlatHexGrid<MeshTileCell>.HorizontallyWrappedRectangle(width, height); map = new PolarFlatBrickMap(Vector2.zero, 50, 300, new VectorPoint(width, height)); foreach (var point in grid) { var cell = Instantiate(cellPrefab); cell.transform.parent = gridRoot.transform; Mesh mesh = cell.GetComponent<MeshFilter>().mesh; float innerRadius = map.GetInnerRadius(point) + border/2; float outerRadius = map.GetOuterRadius(point) - border/2; float startAngle = map.GetStartAngleZ(point); float endAngle = map.GetEndAngleZ(point) - border * Mathf.Rad2Deg / outerRadius; MeshUtil.MakeBandedSector(mesh, startAngle, endAngle,innerRadius, outerRadius, quadCount); cell.Color = ExampleUtils.Colors[point.GetColor1_3()]; cell.HighlightOn = false; cell.__CenterOffset = map[point].XYTo3D(); grid[point] = cell; } }
public ReadyForNextGroupState(ISetting setting, IGrid grid, IGroupFactory groupFactory, OnDeleteEndEventHandler onDeleteEndEvent) { _setting = setting; _grid = grid; _groupFactory = groupFactory; _onDeleteEndEvent = onDeleteEndEvent; }
/// <summary> /// Erstellt ein neues Informationsobjekt für ein 3D-Modell, das eine Kante darstellt. /// [base="pipe1", Angles3.Zero, new Vector3 (10,10,10)] /// </summary> public Pipe(IScreen screen, IGrid grid, Knot knot, Edge edge, Node node1, Node node2) : base(screen: screen) { UniqueKey = edge.ToString (); // Weise Knoten und Kante zu Knot = knot; Edge = edge; Grid = grid; // Berechne die beiden Positionen, zwischen denen die Kante gezeichnet wird PositionFrom = node1; PositionTo = node2; // Kanten sind verschiebbar und auswählbar IsMovable = true; IsSelectable = true; // Berechne die Drehung Rotation += RotationMap [Edge.Direction]; // Aktualisiere die Kategorie Coloring.OnColorChanged += UpdateCategory; IsSingleColored = true; incomplete = true; }
private void BuildGrid() { const int width = 6; const int height = 5; const float border = 0f; const float quadSize = 15f; grid = RectGrid<MeshTileCell>.HorizontallyWrappedParallelogram(width, height); map = new PolarRectMap(Vector2.zero, 50, 350, new VectorPoint(width, height)); foreach (var point in grid) { var cell = Instantiate(cellPrefab); cell.transform.parent = gridRoot.transform; float innerRadius = map.GetInnerRadius(point) + border/2; float outerRadius = map.GetOuterRadius(point) - border/2; float startAngle = map.GetStartAngleZ(point); float endAngle = map.GetEndAngleZ(point) - border*Mathf.Rad2Deg/outerRadius; int quadCount = Mathf.CeilToInt(outerRadius*2*Mathf.PI/(quadSize*width)); Mesh mesh = cell.GetComponent<MeshFilter>().mesh; MeshUtils.MakeBandedSector(mesh, startAngle, endAngle, innerRadius, outerRadius, quadCount, v => v); cell.Color = ExampleUtils.Colors[point.GetColor(6, 3, 1)]; cell.HighlightOn = false; cell.__CenterOffset = map[point].XYTo3D(); grid[point] = cell; } }
public void Run(ref IGrid grid, SelectionFunction SelectionFunction) { var startAt = grid.GetRandomCell; active = new Stack<Cell>(); active.Push(startAt); while(active.Any()) { var cell = SelectionFunction(active); var availableNeighbors = cell.Neighbors.Where(x => x.Links.Count == 0); if (availableNeighbors.Any()) { var neighbor = availableNeighbors.Sample(); cell.Link(neighbor); active.Push(neighbor); } else { var list = active.ToList(); list.Remove(cell); active = new Stack<Cell>(list); } } }
public GridDataBindingSettings(IGrid grid) { this.grid = grid; Server = new GridBindingSettings(grid); Ajax = new GridBindingSettings(grid); WebService = new GridBindingSettings(grid); }
public GridPagingSettings(IGrid grid) { this.grid = grid; Style = GridPagerStyles.NextPreviousAndNumeric; CurrentPage = 1; PageSizesInDropDown = new[] {5, 10, 20, 50}; }
public Rover(Direction direction, Point location, IGrid grid, IMoveSupplier moveSupplier) { this.Direction = direction; this.Location = location; this.grid = grid; this.moveSupplier = moveSupplier; }
/// <summary> /// Updates the cells. /// </summary> /// <param name="block">if set to <c>true</c> blocked cells will be calculated; otherwise only unblocking will occur.</param> protected override void UpdateCells(bool block) { if (!block) { if (_lastGrid != null) { UpdateCells(_lastGrid, false); _lastGrid = null; } return; } var grid = GridManager.instance.GetGrid(_transform.position); if (grid != _lastGrid && _lastGrid != null) { UpdateCells(_lastGrid, false); } _lastGrid = grid; if (grid != null) { UpdateCells(grid, block); } }
public void reveal_all_tiles_near_mines_surrounding_tile_at(Coordinate coordinate, IGrid _grid) { // minefield.reveal for (var row = coordinate.X - 1; row <= coordinate.X + 1; row++) for (var col = coordinate.Y - 1; col <= coordinate.Y + 1; col++) { var coordinate_of_tile_under_inspection = Coordinate.new_coord(row, col); if (!coordinate_of_tile_under_inspection.Equals(coordinate)) { if (!has_already_been_checked(coordinate_of_tile_under_inspection)) { coordinates_checked.Add(coordinate_of_tile_under_inspection); if (_grid.contains_tile_at(coordinate_of_tile_under_inspection) && !_grid.mine_on_tile_at(coordinate_of_tile_under_inspection)) { _grid.reveal_tile_at(coordinate_of_tile_under_inspection); if (!_grid.mines_near_tile_at(coordinate_of_tile_under_inspection)) { reveal_all_tiles_near_mines_surrounding_tile_at(coordinate_of_tile_under_inspection, _grid); } } } } } }
public GridGroupingSettings(IGrid grid) { this.grid = grid; Groups = new List<GroupDescriptor>(); Visible = true; }
/// <summary> /// Generete game field /// </summary> /// <param name="grid">Field member</param> /// <param name="player"Player member></param> /// <returns>Genereted game filed</returns> public IGrid GenerateGrid(IPlayer player, IGrid grid) { DefaultRandomGenerator random = DefaultRandomGenerator.Instance(); int percentageOfBlockedCells = random.Next(GlobalConstants.MinimumPercentageOfBlockedCells, GlobalConstants.MaximumPercentageOfBlockedCells); for (int row = 0; row < grid.TotalRows; row++) { for (int col = 0; col < grid.TotalCols; col++) { int num = random.Next(0, 100); if (num < percentageOfBlockedCells) { grid.SetCell(row, col, GlobalConstants.BlockedCellSymbol); } else { grid.SetCell(row, col, GlobalConstants.FreeCellSymbol); } } } grid.SetCell(grid.TotalRows / 2, grid.TotalCols / 2, GlobalConstants.PlayerSignSymbol); this.MakeAtLeastOneExitReachable(grid, player); return grid; }
/// <summary> /// Initializes a new instance of the <see cref="FullGridVectorField"/> class. /// </summary> /// <param name="group">The transient unit group.</param> /// <param name="path">The path.</param> /// <param name="options">The vector field options.</param> public FullGridVectorField(TransientGroup<IUnitFacade> group, Path path, VectorFieldOptions options) { Ensure.ArgumentNotNull(group, "group"); this.group = group; _currentPath = path; var modelUnit = group.modelUnit; _unitProperties = modelUnit; var pathOptions = modelUnit.pathFinderOptions; // cache options locally _obstacleStrengthFactor = options.obstacleStrengthFactor; _allowCornerCutting = pathOptions.allowCornerCutting; _allowDiagonals = !pathOptions.preventDiagonalMoves; _announceAllNodes = modelUnit.pathNavigationOptions.announceAllNodes; _builtInContainment = options.builtInContainment; _updateInterval = options.updateInterval; // pre-allocate lists _openSet = new SimpleQueue<Cell>(31); _tempWalkableNeighbours = new DynamicArray<Cell>(8); _extraTempWalkableNeighbours = new DynamicArray<Cell>(8); _grid = GridManager.instance.GetGrid(group.modelUnit.position); if (_grid != null) { _fastMarchedCells = new PlaneVector[_grid.sizeX, _grid.sizeZ]; _cellDirs = new VectorFieldCell[_grid.sizeX, _grid.sizeZ]; } }
public void CanSetGoalScoreWhenInitialize() { gameServer = new VersusScoreAttackModeGameServer(100); gridOne = Substitute.For<IGrid>(); gridTwo = Substitute.For<IGrid>(); }
public IGrid<Cell> On(IGrid<Cell> grid, Cell startAt = null) { if (startAt == null) { startAt = grid.RandomCell(); } var stack = new Stack<Cell>(); stack.Push(startAt); while (stack.Count != 0) { var current = stack.Peek(); var neighbours = current.Neighbours().Where(n => n.Links.Count == 0).ToList(); if (neighbours.Count == 0) { stack.Pop(); } else { var neighbour = neighbours[rand.Next(neighbours.Count)]; current.Link(neighbour); stack.Push(neighbour); } } return grid; }
public void Run(ref IGrid grid) { var startAt = grid.GetRandomCell; active = new Stack<Cell>(); active.Push(startAt); costs = new Dictionary<Cell, int>(); foreach(var cell in grid) { costs[cell] = GetRandomNumber(0, 100); } int iterations = 1; while(active.Any()) { iterations++; var cell = Min(active); // Get the minimum value in the *active* set var availableNeighbors = cell.Neighbors.Where(x => x.Links.Count == 0); if (availableNeighbors.Any()) { var neighbor = Min(availableNeighbors); // Get the minimum value in the *availableNeighbors* set cell.Link(neighbor); active.Push(neighbor); } else { var list = active.ToList(); list.Remove(cell); active = new Stack<Cell>(list); } } Console.WriteLine($"Iterations: {iterations}"); }
/// <summary> /// Signals the <see cref="Robot"/> to start moving. /// </summary> /// <param name="grid">The <see cref="IGrid"/> to traverse.</param> public void Traverse(IGrid grid) { Contract.Requires(grid != null); Contract.Ensures(this.FinishPosition != null); foreach (var instruction in this.instructions) { var newPosition = instruction.TransformPosition(this.currentPosition); var moveResult = grid.Move(this.currentPosition, newPosition); if (moveResult == RobotFeedback.Lost) { this.FinishPosition = this.currentPosition; this.Lost = true; return; } else if (moveResult == RobotFeedback.Safe) { this.currentPosition = newPosition; } } this.FinishPosition = this.currentPosition; }
public void Initialize() { gameServer = new GameServer(); gridOne = Substitute.For<IGrid>(); gridTwo = Substitute.For<IGrid>(); }
public GridEventManager(ISetting setting, IGrid grid, IGroupFactory groupFactory) { _grid = grid; _groupFactory = groupFactory; _setting = setting; }
public IEnumerable<Point> GetEmptySquares(IGrid grid) { for (int x = 0; x < grid.Size; x++) for (int y = 0; y < grid.Size; y++) if (grid[x, y].Content == TileContent.Empty) yield return new Point(x, y); }
/// <summary> /// /// </summary> internal CheckColumn(IGrid gridControl, string columnName) : base(columnName, typeof(bool)) { //InitializeComponent(); m_checkColumnHelper = new CheckColumnHelper(this, gridControl); }
public GridPagerTests() { grid = new Grid <GridModel>(new GridModel[0]); pager = new GridPager <GridModel>(grid); grid.Query = new QueryCollection(); }
/// <summary> /// Set a single tile in a tilemap based on a collision grid. /// </summary> /// <param name="map">The tilemap to set tiles in.</param> /// <param name="grid">The grid to get tile data from.</param> /// <param name="x">The column of the tile to set.</param> /// <param name="y">The row of the tile to set.</param> public static void SetTile(Tilemap map, IGrid <bool> grid, int x, int y) { if (!grid[x, y]) { map.SetTile(x, y, map.TileCount - 1); return; } Func <int, int, bool> test = (i, j) => grid[x + i, y + j]; near[0] = test(0, -1); near[1] = test(1, 0); near[2] = test(0, 1); near[3] = test(-1, 0); near[4] = test(-1, -1); near[5] = test(1, -1); near[6] = test(1, 1); near[7] = test(-1, 1); // value for a single block with no neighbors, otherwise it'll be set to (0, 0) int sx = 6, sy = 2; if (all(near[3])) { sx = 2; sy = 2; } if (all(near[0])) { sx = 3; sy = 2; } if (all(near[1])) { sx = 4; sy = 2; } if (all(near[2])) { sx = 5; sy = 2; } if (all(near[1], near[3])) { sx = 0; sy = 2; } if (all(near[0], near[2])) { sx = 1; sy = 2; } if (all(near[0], near[3])) { sx = 7; sy = 1; } if (all(near[1], near[0])) { sx = 0; sy = 0; } if (all(near[2], near[1])) { sx = 1; sy = 0; } if (all(near[3], near[2])) { sx = 2; sy = 0; } if (all(near[2], near[3], near[7])) { sx = 4; sy = 3; } if (all(near[3], near[0], near[4])) { sx = 5; sy = 3; } if (all(near[0], near[1], near[5])) { sx = 6; sy = 3; } if (all(near[1], near[2], near[6])) { sx = 7; sy = 3; } if (all(near[0], near[1], near[3])) { sx = 3; sy = 0; } if (all(near[1], near[2], near[0])) { sx = 4; sy = 0; } if (all(near[2], near[3], near[1])) { sx = 5; sy = 0; } if (all(near[3], near[0], near[2])) { sx = 6; sy = 0; } if (all(near[0], near[1], near[2], near[3])) { sx = 7; sy = 4; } if (all(near[0], near[2], near[3], near[7])) { sx = 7; sy = 2; } if (all(near[1], near[3], near[0], near[4])) { sx = 0; sy = 1; } if (all(near[2], near[0], near[1], near[5])) { sx = 1; sy = 1; } if (all(near[3], near[1], near[2], near[6])) { sx = 2; sy = 1; } if (all(near[0], near[1], near[3], near[5])) { sx = 3; sy = 1; } if (all(near[1], near[2], near[0], near[6])) { sx = 4; sy = 1; } if (all(near[2], near[3], near[1], near[7])) { sx = 5; sy = 1; } if (all(near[3], near[0], near[2], near[4])) { sx = 6; sy = 1; } if (all(near[1], near[2], near[3], near[6], near[7])) { sx = 0; sy = 3; } if (all(near[0], near[2], near[3], near[4], near[7])) { sx = 1; sy = 3; } if (all(near[0], near[1], near[3], near[4], near[5])) { sx = 2; sy = 3; } if (all(near[0], near[1], near[2], near[5], near[6])) { sx = 3; sy = 3; } if (all(near[0], near[1], near[2], near[3], near[7])) { sx = 3; sy = 4; } if (all(near[0], near[1], near[2], near[3], near[4])) { sx = 4; sy = 4; } if (all(near[0], near[1], near[2], near[3], near[5])) { sx = 5; sy = 4; } if (all(near[0], near[1], near[2], near[3], near[6])) { sx = 6; sy = 4; } if (all(near[0], near[1], near[2], near[3], near[5], near[7])) { sx = 1; sy = 4; } if (all(near[0], near[1], near[2], near[3], near[4], near[6])) { sx = 2; sy = 4; } if (all(near[0], near[1], near[2], near[3], near[6], near[7])) { sx = 5; sy = 5; } if (all(near[0], near[1], near[2], near[3], near[4], near[7])) { sx = 6; sy = 5; } if (all(near[0], near[1], near[2], near[3], near[4], near[5])) { sx = 7; sy = 5; } if (all(near[0], near[1], near[2], near[3], near[5], near[6])) { sx = 0; sy = 4; } if (all(near[0], near[1], near[2], near[3], near[5], near[6], near[7])) { sx = 1; sy = 5; } if (all(near[0], near[1], near[2], near[3], near[4], near[6], near[7])) { sx = 2; sy = 5; } if (all(near[0], near[1], near[2], near[3], near[4], near[5], near[7])) { sx = 3; sy = 5; } if (all(near[0], near[1], near[2], near[3], near[4], near[5], near[6])) { sx = 4; sy = 5; } if (all(near[0], near[1], near[2], near[3], near[4], near[5], near[6], near[7])) { sx = 0; sy = 5; } // convert coords for top-left index int currentTileIndex = (5 - sy) * 8 + sx; map.SetTile(x, y, currentTileIndex); }
public IGrid LoadGrid(Guid gridId) { IGrid grid = database.Controller.DBDriver.LoadGrid(gridId, database); return(grid); }
public Guid SaveGrid(IGrid grid) { Guid id = database.Controller.DBDriver.SaveGrid(grid, database); return(id); }
public GridSort(IGrid <T> grid) { Grid = grid; ProcessorType = GridProcessorType.Pre; DefinitionsValue = new OrderedDictionary(); }
/// <summary> /// Loads the actual grid data for the given <paramref name="grid"/>. /// That is, loads the actual cell data. /// </summary> /// <param name="grid"></param> /// <returns></returns> public IGrid LoadGridData(IGrid grid) { return(gridDatabaseDriver.LoadGridData(grid)); }
protected override IUnitAttack GetUnitAttack(Unit unit, IGrid grid) { return(new CharacterAttack(unit, grid)); }
public void Update(IGrid grid, PointI[] endPoints) { this.grid = grid; Update(endPoints); }
public AsyncPathUpdater(IGrid grid) { this.grid = grid; this.path = new SplinePath(new Vector2[0], InterpolationType.Null); this.pathFinder = new PathFinder(grid); }
private ReversiBoard(IGrid <Var <Player> > contents) { this._contents = contents; }
public Grid(IGrid grid) : this(grid.ToMatrix()) { }
public abstract void PaintLandRegion(Land land, LandRegionType land_region_type, IGrid <LandPoint> grid);
public AjaxGridPager(IGrid grid) { _grid = grid; }
protected override IUnitAI GetUnitAI(Unit unit, IGrid grid, IUnitMovement unitMovement) { return(null); }
/// <summary> /// Performs additional actions before the new time will be set to an object. /// </summary> /// <remarks> /// Inside this method the new time can be changed or quantizing of an object can be cancelled. /// </remarks> /// <param name="obj">Object to quantize.</param> /// <param name="quantizedTime">Holds information about new time for an object.</param> /// <param name="grid">Grid to quantize object by.</param> /// <param name="tempoMap">Tempo map used to quantize object.</param> /// <param name="settings">Settings according to which object should be quantized.</param> /// <returns>An object indicating whether the new time should be set to the object /// or not. Also returned object contains that new time.</returns> protected abstract TimeProcessingInstruction OnObjectQuantizing( TObject obj, QuantizedTime quantizedTime, IGrid grid, TempoMap tempoMap, TSettings settings);
/// <summary> /// Generates Ok Game Over Winner response data object /// </summary> /// <param name="player">Winner player</param> /// <param name="grid">Grid</param> /// <returns>Service response data</returns> private BoringToeMoveResponse GenerateGameOverWinnerResponseData(Player player, IGrid grid) { BoringToeMoveResponse resp = new BoringToeMoveResponse(player, grid); resp.GameOver = true; resp.Repeat = false; resp.Winner = player; resp.Grid = grid.ToString(); return(resp); }
/// <summary> /// Specifies that the grid's columns should be automatically generated from the public properties on the model object. /// </summary> public static IGridWithOptions <T> AutoGenerateColumns <T>(this IGrid <T> grid) where T : class { return(grid.WithModel(new AutoColumnGridModel <T>(ModelMetadataProviders.Current))); }
public void Setup() { _grid = new Grid(5); }
public ShipPlacementResult PlaceShip(IShip ship, IVector2D <int> position, Direction direction, IGrid <ITile> grid) { //Check if one end of the ship if out of bounds. if (grid.PositionIsOutOfBounds(position)) { return(ShipPlacementResult.ShipWasNotPlaced); } //Check if the other end of the ship if out of bounds. IVector2D <int> shipVector = direction.ToIntVector(ship.Size); IVector2D <int> shipVectorOffset = position.Clone().Add(shipVector); if (grid.PositionIsOutOfBounds(shipVectorOffset)) { return(ShipPlacementResult.ShipWasNotPlaced); } //List of tiles that the ship is going to occupy. List <ITile> checkedTiles = new List <ITile>(); IVector2D <int> shipNormalVector = direction.ToIntVector(); //Check if any tile along the given direction in the magnitude of the ships length is occupied. for (int i = 0; i < ship.Size; i++) { IVector2D <int> interpolatedShipVector = shipNormalVector.Clone().Mul(i); IVector2D <int> tilePosition = position.Clone(); tilePosition.Add(interpolatedShipVector); if (grid.PositionIsOutOfBounds(tilePosition)) { return(ShipPlacementResult.ShipWasNotPlaced); } ITile tile = grid.GetCellAt(tilePosition); //If any tile in the magnitude of the ship is occupied then cancel placement. if (tile.IsOccupied) { return(ShipPlacementResult.ShipWasNotPlaced); } //Add tile for later assignment. checkedTiles.Add(tile); } foreach (ITile tile in checkedTiles) { tile.Occupant = ship; } //Ship placement was successful. return(ShipPlacementResult.ShipWasPlaced); }
public PlayGrid(ISequence <Constraints> columnConstraints, ISequence <Constraints> rowConstraints, IGrid <Square> squares) { if (columnConstraints == null) { throw new ArgumentNullException(nameof(columnConstraints)); } else if (rowConstraints == null) { throw new ArgumentNullException("rowConstraints "); } else if (squares == null) { throw new ArgumentNullException(nameof(squares)); } else if (columnConstraints.Length != squares.Size.Width) { throw new ArgumentException("Number of column constraints should be equal to grid width"); } else if (rowConstraints.Length != squares.Size.Height) { throw new ArgumentException("Number of row constraints should be equal to grid height"); } else { this.Squares = squares.Map(sqr => new Var <Square>(sqr)).Copy(); this.ColumnConstraints = (from i in Squares.ColumnIndices let constraints = columnConstraints[i] let slice = new Slice(Squares.Column(i).Map(var => var.Value)) select new PlayGridConstraints(slice, constraints)).ToSequence(); this.RowConstraints = (from i in Squares.RowIndices let constraints = rowConstraints[i] let slice = new Slice(Squares.Row(i).Map(var => var.Value)) select new PlayGridConstraints(slice, constraints)).ToSequence(); } }
public override void InitGrid() { grid = Grid.CloneStructure(p => Grid[p].GetRequiredComponent <LinesCell>()); Reset(); }
public bool IsInstance(IGrid grid) { return(grid is SquareGrid); }
/// <summary> /// Saves the given grid object to the database; /// </summary> /// <returns> /// the Guid of the <see cref="IGrid"/>-object that was saved /// (equal to the <see cref="IDatabaseEntityInfo{T}.ID"/>-property). /// </returns> /// <param name="grid"> /// The grid to save. /// </param> /// <param name="database"> /// chaos /// </param> public Guid SaveGrid(IGrid grid, IDatabaseInfo database) { return(gridDatabaseDriver.SaveGrid(grid, database)); }
/// <summary> /// Maps points inside the inner grid to the inner grid, but everything outside comes from the outer grid. /// </summary> public static IGrid <T> EmbedInside <T>(this IDefinedSizeGrid <T> innerGrid, IGrid <T> outerGrid) { return(new GeneratedGrid <T>(p => innerGrid.Region().ContainsPoint(p) ? innerGrid.Get(p) : outerGrid.Get(p))); }
public void Init(IGrid grid) { _grid = grid; }
/// <summary> /// Searches for an equivalent grid in the database and, if none is found /// saves a grid object to the database. /// </summary> /// <param name="grid"> /// On entry, the grid which should be saved to the database. /// On exit, either unchanged, or the equivalent grid. /// </param> /// <param name="EquivalentGridFound"> /// Inidicates that an equivalent grid was found. /// </param> /// <param name="database"></param> public Guid SaveGridIfUnique(ref IGrid grid, out bool EquivalentGridFound, IDatabaseInfo database) { return(gridDatabaseDriver.SaveGridIfUnique(ref grid, out EquivalentGridFound, database)); }
static public IEnumerable <OUTPUT_TYPE> ConvertToData <INPUT_TYPE, OUTPUT_TYPE>(this IGrid <INPUT_TYPE> item, Operation <OUTPUT_TYPE, INPUT_TYPE> operation) { return(item.Convert(operation).ConvertToData()); }
static public IEnumerable <OUTPUT_TYPE> ConvertWithIndexsToData <INPUT_TYPE, OUTPUT_TYPE>(this IGrid <INPUT_TYPE> item, Operation <OUTPUT_TYPE, VectorI2, INPUT_TYPE> operation) { return(item.ConvertWithIndexs(operation).ConvertToData()); }
public GridColumnCollection(IGrid grid, IColumnBuilder <T> columnBuilder, IGridSortSettings sortSettings) { _grid = grid; _columnBuilder = columnBuilder; SortSettings = sortSettings; }
public West(IGrid grid) { _grid = grid; }