public object doMLVForPoint(GameCell gameCell) { log(); object result="Клетка пуста."; if (gameCell.FrameExample != null && gameCell.FrameExample.BaseFrame != null && gameCell.FrameExample.BaseFrame.FrameId != -1) { situations = gatherSituationsList(); situationExample = new FrameExample(); Slot slotAgent = new Slot(); slotAgent.SlotName = "agent"; slotAgent.SlotType = SlotType.Frame; slotAgent.SlotInheritance = SlotInherit.Override; slotAgent.IsSystem = false; situationExample.AddSlot(slotAgent); situationExample.SetValue("agent", gameCell.FrameExample); Frame situationToCheck = this.getNextFrameToCheck(); while (!situationExample.ContainsSlot("action") && situationToCheck != null) //пока не определили целевой слот "действие" { checkedFramesIDs.Add(situationToCheck.FrameId); if (checkSituation(situationToCheck, situationExample)) { Slot actionSlot = situationToCheck.GetSlotByName("action"); situationExample.AddSlot(actionSlot); situationExample.SetValue(actionSlot.SlotName, actionSlot.SlotDefault); } situationToCheck = this.getNextFrameToCheck(); } result = null; if (situationExample.ContainsSlot("action")) result = situationExample.Value("action"); } return result; }
/// <summary> /// Evaluates a cell for desirability /// </summary> /// <param name="context">The game context</param> /// <param name="cell">The cell to evaluate</param> /// <returns>Gets a numeric score for the cell under evaluation</returns> protected override decimal ScoreCell(GameContext context, GameCell cell) { var score = 0; // Main criteria is distance from nearest enemy _enemies.Each(e => score += e.Pos.CalculateDistanceInMovesFrom(cell.Pos) * 5); // Score the cell by its proximity to openness so the actors will avoid boxing themselves into a corner score += cell.FilterAdjacentCells(context, cells => cells.Where(c => !c.HasObstacle)).Count(); return(score); }
private static char GetSymbol(GameCell cell) { if (cell == GameCell.Empty) { return('.'); } if (cell == GameCell.Player1) { return('X'); } return('O'); }
public bool GameCellIsStartOfVictoryRow(GameCell gameCell, GameState gameState) { if (gameCell.Team == null) { return(false); } var victoryConditions = new List <VictoryCondition>() { new VictoryCondition() { IsMatch = true, RowTransform = 1, ColumnTransform = 0 }, //Horizontal new VictoryCondition() { IsMatch = true, RowTransform = 0, ColumnTransform = 1 }, //Vertical new VictoryCondition() { IsMatch = true, RowTransform = -1, ColumnTransform = 1 }, //Diagonal Up Left new VictoryCondition() { IsMatch = true, RowTransform = 1, ColumnTransform = 1 }, //Diagonal Up Right }; for (var i = 1; i < gameState.GameSettings.PiecesInARowToWin; i++) { foreach (var victoryCondition in victoryConditions.Where(vc => vc.IsMatch)) { if (null == gameCell.Row) { throw new ApplicationException("Invalid Game Position in Game State - Missing Row"); } var targetRow = gameCell.Row.Value + i * victoryCondition.RowTransform; var targetColumn = gameCell.Column + i * victoryCondition.ColumnTransform; if (!IsValidGamePosition(gameState, targetRow, targetColumn)) { victoryCondition.IsMatch = false; continue; } var targetCell = gameState.GameCells[targetRow][targetColumn]; victoryCondition.IsMatch = targetCell?.Team?.TeamId == gameCell.Team.TeamId; } } return(victoryConditions.Any(v => v.IsMatch)); }
public void InitializeWithGameCell(GameCell topCell) { this.cell = topCell; CanvasGroup canvasGroup = this.GetComponent <CanvasGroup>(); canvasGroup.alpha = topCell.solid ? 1 : 0; Color c = Color.black; Color alphaColor = new Color(c.r, c.g, c.b, 0.3f); if (topCell.blockedBottom) { bottomImage.color = c; } else { bottomImage.color = alphaColor; } if (topCell.blockedLeft) { leftImage.color = c; } else { leftImage.color = alphaColor; } if (topCell.blockedRight) { rightImage.color = c; } else { rightImage.color = alphaColor; } if (topCell.blockedTop) { topImage.color = c; } else { topImage.color = alphaColor; } if (topCell.displayedNumber == 0) { text.text = ""; } else { text.text = topCell.displayedNumber.ToString(); } }
/// <summary> /// Adds a <paramref name="cell"/> to the level, potentially merging it with another cell at that position. /// </summary> /// <param name="cell">The cell to add.</param> /// <param name="roomId">The unique identifier of the room.</param> public void AddCell(GameCell cell, Guid roomId) { if (_cells.ContainsKey(cell.Pos)) { _cells[cell.Pos] = MergeCells(_cells[cell.Pos], cell); } else { _cells[cell.Pos] = cell; } _cellRoomId[cell.Pos] = roomId; }
protected void OnTriggerEnter(Collider other) { GameCell otherGameCell = other.gameObject.GetComponent <GameCell>(); if (otherGameCell != null && !nearbyCells.Contains(otherGameCell)) { nearbyCells.Add(otherGameCell); } if (other.GetComponent <Base>() && nearbyBase == null) { nearbyBase = other.GetComponent <Base>(); } }
public void SpawnBoard() { foreach (GameCell cell in transform.GetComponentsInChildren <GameCell>()) { GameCell obj = (GameCell)Instantiate(emptyBoardSpace, cell.transform.position, cell.transform.localRotation); obj.state = cell.state; obj.ownerSeat = cell.ownerSeat; obj.resourceType = cell.resourceType; GameManager.singleton.cells.Add(obj); NetworkServer.Spawn(obj.gameObject); } }
void MakeMove(GameCell targetCell) { Animator animator = GetComponentInChildren <Animator>(); animator.SetBool("isWalk", true); transform.LookAt(positionConverter.ConvertBoardPositionToScene(targetCell.GetCoordinates(), true)); iTween.MoveTo(this.gameObject, iTween.Hash( "position", positionConverter.ConvertBoardPositionToScene(targetCell.GetCoordinates(), true), "oncomplete", "TryMove", "time", 3, "easetype", "linear")); }
/// <summary> /// Merges two cells together to form a single combined cell. /// </summary> /// <param name="oldCell">The cell already present.</param> /// <param name="newCell">The cell to merge into the original cell.</param> /// <returns>GameCell.</returns> private static GameCell MergeCells(GameCell oldCell, GameCell newCell) { // Make sure invulnerable flags don't get lost when merging cells if (oldCell.Objects.Any(o => o.ObjectType == GameObjectType.Wall && o.IsInvulnerable)) { foreach (var obj in newCell.Objects.Where(o => o.ObjectType == GameObjectType.Wall)) { obj.SetInvulnerable(); } } return(newCell); }
public void AreaCreationWorks() { Dictionary <Coordinate, GameBoardSquare> boardInfo = new Dictionary <Coordinate, GameBoardSquare>(); for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { Coordinate coord = new Coordinate(i, j); GameBoardSquare square = new GameBoardSquare(coord); GameCell cell = new GameCell(); square.AddGameCell(cell); boardInfo.Add(coord, square); } } GameBoardSquare sq = boardInfo[new Coordinate(0, 0)]; sq.TopCell.blockedTop = false; sq.TopCell.blockedRight = false; GameBoardSquare sq2 = boardInfo[new Coordinate(1, 0)]; sq2.TopCell.blockedLeft = false; GameBoardSquare sq3 = boardInfo[new Coordinate(0, 1)]; sq3.TopCell.blockedBottom = false; sq3.TopCell.blockedRight = false; GameBoard board = new GameBoard(boardInfo); Assert.That(board.AreaForSquare(new Coordinate(0, 0)).Size() == 3); Assert.That(board.AreaForSquare(new Coordinate(1, 0)).Size() == 3); GameBoardSquare sq4 = boardInfo[new Coordinate(1, 1)]; sq4.TopCell.blockedLeft = false; sq4.TopCell.blockedRight = false; Assert.That(board.AreaForSquare(new Coordinate(0, 0)).Size() == 4); Assert.That(board.AreaForSquare(new Coordinate(1, 1)).Size() == 4); Assert.That(board.AreaForSquare(new Coordinate(2, 2)).Size() == 1); boardInfo[new Coordinate(2, 1)].TopCell.blockedLeft = false; boardInfo[new Coordinate(2, 1)].TopCell.blockedTop = false; boardInfo[new Coordinate(2, 2)].TopCell.blockedBottom = false; boardInfo[new Coordinate(2, 2)].TopCell.blockedLeft = false; boardInfo[new Coordinate(1, 2)].TopCell.blockedRight = false; Assert.That(board.AreaForSquare(new Coordinate(2, 2)).Size() == 7); }
private void TryMove() { GameCell nextCell = GetNextMove(); if (nextCell != null) { isMoving = true; MakeMove(nextCell); } else { isMoving = false; } }
private void DoPutBomb(Player player, Bomb bombPrefab, GameCell gameCell) { Vector3 bombPosition = levelManager.GetPositionConverter().ConvertBoardPositionToScene(gameCell.GetCoordinates(), true); bombPosition.y = bombPrefab.transform.localScale.y / 0.85f; Bomb bomb = Instantiate(bombPrefab, bombPosition, Quaternion.identity) as Bomb; bomb.player = player.gameObject; bomb.explosionRange = GameManager.instance.GetPlayer().bombRange; gameCell.bomb = bomb; AddToBombMap(player, bomb, gameCell); }
public override void Select() { base.Select(); //pick a random empty gamecell List <GameCell> allCells = new List <GameCell>(GameObject.FindObjectsOfType <GameCell>()).FindAll((GameCell cell) => { return(cell.state == GameCellState.Empty && cell.hasShip == false); }); GameCell randomCell = allCells[Random.Range(0, allCells.Count)]; Player.localPlayer.Cmd_ShipWormholeTo(mgr.CurrentEncounter.playerShip.netId, randomCell.netId); }
public static GameBoardSquare GameBoardSquareFromNode(JSONNode square) { int row = square["row"]; int column = square["column"]; GameBoardSquare sq = new GameBoardSquare(); Coordinate coord = new Coordinate(row, column); sq.coordinate = coord; //TODO: only add GameCell if square is not "greyed out" (add something in the json for that) GameCell gameCell = GameCell.GameCellFromJSONNode(square); sq.AddGameCell(gameCell); return(sq); }
public void MoveBack() { GameCell nextCell = GetBackMove(); if (nextCell != null) { isMoving = true; MakeMove(nextCell); } else { isMoving = false; } }
private String GetSymbol(IGameManager gameManager, GameCell gameCell) { if (gameCell.Owner == Player.NonPlayer) { return(""); } if (gameCell.Owner == gameManager.Players.First()) { return("X"); } return("O"); }
public static int DiagonalRelatives2(this GameCell cell, GameCell[,] grid) { int relatives = 0; for (var x = 0; x < 3; x++) { if (grid[x, 2 - x].CellStatus.Equals(cell.CellStatus)) { relatives++; } } return(relatives - 1); }
private void DrawLines(GameCell gameCell) { var coOrd = gameCell.CoOrd; int pos; for (pos = 0; pos < 3; pos++) { OffSetGridPosition(coOrd, pos + 1, 0, false); Console.Write("-"); } OffSetGridPosition(coOrd, pos + 1, 0, false); Console.Write("+"); if (coOrd.XCord == _sweeper.Width - 1) { for (pos = 0; pos < 3; pos++) { OffSetGridPosition(new CoOrdinate(coOrd.XCord + 1, coOrd.YCord), 0, pos + 1, false); Console.Write("|"); } } if (coOrd.XCord == 0) { OffSetGridPosition(new CoOrdinate(coOrd.XCord, coOrd.YCord), -1, 2, false); Console.Write(coOrd.YCord.ToString()); } for (pos = 0; pos < 3; pos++) { OffSetGridPosition(coOrd, 0, pos + 1, false); Console.Write("|"); } OffSetGridPosition(coOrd, 0, pos + 1, false); Console.Write("+"); if (coOrd.YCord == _sweeper.Height - 1) { for (pos = 0; pos < 3; pos++) { OffSetGridPosition(new CoOrdinate(coOrd.XCord, coOrd.YCord + 1), pos + 1, 0, false); Console.Write("-"); } } if (coOrd.YCord == 0) { OffSetGridPosition(new CoOrdinate(coOrd.XCord, coOrd.YCord), 2, -1, false); Console.Write(coOrd.XCord.ToString()); } }
public List <GameCell> GetNeihbours(Vector2Int pos) { List <GameCell> nbrs = new List <GameCell>(); foreach (Vector2Int d in directions) { GameCell n = GetCell(pos + d); if (n != null) { nbrs.Add(n); } } return(nbrs); }
private void CreateOneCell(Form form, Panel start, int row, int col) { GameCell cell = new GameCell(row, col) { Size = start.Size, BorderStyle = start.BorderStyle }; cell.Location = new Point(start.Location.X + col * cell.Size.Width, start.Location.Y + row * cell.Size.Width); cell.Click += new EventHandler(((Form1)form).GameCell_Click); cell.MouseHover += new EventHandler(((Form1)form).GameCell_Hover); form.Controls.Add(cell); GameMaster.AddCells(cell); }
public void NextTurn(GameCell cell) { if (cell == null) { throw new ArgumentNullException("cell"); } if (cell.Owner == Player.NonPlayer) { GameManager.NextTurn(cell.Location.X, cell.Location.Y); UpdateGameStatus(GameManager); } CheckIsGameOver(); }
public static GameCell GetNextMovement(Character character, GameCell target, GameCell[,] boardState) { if (IsPathPassable(character.x, target.X, target.Y, boardState)) { return(new GameCell() { X = character.x < target.X ? character.x + 1 : character.x - 1, Y = character.y }); } // CONTINUE HERE return(new GameCell() { X = character.x, Y = character.y }); }
// Use this for initialization void Start() { gameObject.AddComponent <AudioSource>(); GameObject.FindObjectOfType <TimestepManager>().addFinalizer(this); // Set up bullet grid based on levelDescriptor's size Texture2D levelDescriptor = GetComponent <SpriteRenderer>().sprite.texture; int cellsWidth = levelDescriptor.width; int cellsHeight = levelDescriptor.height; GameGrid = new GameCell[cellsWidth][]; for (int x = 0; x < cellsWidth; x++) { GameGrid[x] = new GameCell[cellsHeight]; } // In-world grid size is based on this GameObject's size Vector2 center = gameObject.transform.position; float realWidth = GetComponent <SpriteRenderer>().bounds.size.x; float realHeight = GetComponent <SpriteRenderer>().bounds.size.y; // Populate bullet grid Vector2 botLeft = center - new Vector2(realWidth / 2, realHeight / 2); float cellWidth = realWidth / cellsWidth; float cellHeight = realHeight / cellsHeight; for (int x = 0; x < cellsWidth; x++) { for (int y = 0; y < cellsHeight; y++) { Vector2 cellCenter = botLeft + new Vector2(cellWidth * (x + 0.5f), cellHeight * (y + 0.5f)); //pick the cell type to place based on the color of the pixel at this location GameObject cellPrefab = getPrefabForColor(levelDescriptor.GetPixel(x, y)); GameObject cell = (GameObject)Instantiate(cellPrefab, cellCenter, Quaternion.identity); cell.transform.localScale = new Vector2(CELL_SCALE * cellWidth / cell.GetComponent <SpriteRenderer>().bounds.size.x, CELL_SCALE * cellHeight / cell.GetComponent <SpriteRenderer>().bounds.size.y); cell.GetComponent <Cell>().GridPosition = new GridPosition(x, y); cell.GetComponent <Cell>().placeBotSound = placeBotSound; cell.GetComponent <CellHighlighter>().tileHoverSound = tileHoverSound; GameGrid[x][y] = new GameCell(); GameGrid[x][y].Cell = cell; GameGrid[x][y].Grid = this; GameGrid[x][y].movingHere = new List <GameObject>(); GameGrid[x][y].goingAway = new List <GameObject>(); } } GameGrid[startTileX][startTileY].isExplored = true; }
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) { var cell = tableView.DequeueReusableCell(GameCellId); if (cell == null) { cell = new GameCell(GameCellId); } var row = indexPath.Row; var gameCell = cell as GameCell; var game = _viewModel.Games[row]; gameCell?.UpdateCell(game); return(cell); }
override protected GameCell GetNextMove() { Vector2 currentPosition = positionConverter.ConvertScenePositionToBoard(this.transform.position); List <GameCell> adjacentCells = board.GetAdjacentCells(currentPosition); if (adjacentCells.Count != 0) { prevCell = currentCell; currentCell = adjacentCells[Random.Range(0, adjacentCells.Count)]; return(currentCell); } else { return(null); } }
public void OnPostionChanged(Vector3 newPostion) { Vector2 boardPostion = positonConverter.ConvertScenePositionToBoard(newPostion); GameCell gameCell = board.GetGameCell(boardPostion); if (gameCell.Equals(currentCell)) { return; } if (currentCell != null) { currentCell.RemovePlayer(player); } currentCell = gameCell; gameCell.AddPlayer(player); }
private UIGameCell mapCellToUICell(GameCell gameCell) { string color; if (gameCell.Alive) { color = "Black"; } else { color = "White"; } return(new UIGameCell { Color = color, Alive = gameCell.Alive, Position = gameCell.Position }); }
public static Tuple <int, int> IndexOf(this GameCell[,] cells, GameCell cell) { for (var x = 0; x < cells.GetLength(0); x++) { for (var y = 0; y < cells.GetLength(1); y++) { if (cells[x, y].Equals(cell)) { return(new Tuple <int, int>(x, y)); } } } //If code reaches this point, then it didn't find anything, return -1 return(new Tuple <int, int>(-1, -1)); }
public static int VerticalRelatives(this GameCell cell, GameCell[,] grid) { int relatives = 0; int colNum = grid.IndexOf(cell).Item1; for (var y = 0; y < 3; y++) { //Find row of cell if (grid[colNum, y].CellStatus.Equals(cell.CellStatus)) { relatives++; } } return(relatives - 1); }
public static int HorizontalRelatives(this GameCell cell, GameCell[,] grid) { int relatives = 0; int rowNum = grid.IndexOf(cell).Item2; for (var x = 0; x < 3; x++) { //Find row of cell if (grid[x, rowNum].CellStatus.Equals(cell.CellStatus)) { relatives++; } } return(relatives - 1); }