Exemplo n.º 1
0
        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);
        }
Exemplo n.º 3
0
 private static char GetSymbol(GameCell cell)
 {
     if (cell == GameCell.Empty)
     {
         return('.');
     }
     if (cell == GameCell.Player1)
     {
         return('X');
     }
     return('O');
 }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
    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();
        }
    }
Exemplo n.º 6
0
        /// <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;
        }
Exemplo n.º 7
0
Arquivo: Ship.cs Projeto: tgrosh/hX
    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>();
        }
    }
Exemplo n.º 8
0
    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);
        }
    }
Exemplo n.º 9
0
    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"));
    }
Exemplo n.º 10
0
        /// <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);
        }
Exemplo n.º 11
0
    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);
    }
Exemplo n.º 12
0
    private void TryMove()
    {
        GameCell nextCell = GetNextMove();

        if (nextCell != null)
        {
            isMoving = true;
            MakeMove(nextCell);
        }
        else
        {
            isMoving = false;
        }
    }
Exemplo n.º 13
0
    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);
    }
Exemplo n.º 14
0
    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);
    }
Exemplo n.º 15
0
    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);
    }
Exemplo n.º 16
0
    public void MoveBack()
    {
        GameCell nextCell = GetBackMove();

        if (nextCell != null)
        {
            isMoving = true;
            MakeMove(nextCell);
        }
        else
        {
            isMoving = false;
        }
    }
Exemplo n.º 17
0
        private String GetSymbol(IGameManager gameManager, GameCell gameCell)
        {
            if (gameCell.Owner == Player.NonPlayer)
            {
                return("");
            }

            if (gameCell.Owner == gameManager.Players.First())
            {
                return("X");
            }

            return("O");
        }
Exemplo n.º 18
0
        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);
        }
Exemplo n.º 19
0
        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());
            }
        }
Exemplo n.º 20
0
    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);
    }
Exemplo n.º 21
0
        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);
        }
Exemplo n.º 22
0
        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();
        }
Exemplo n.º 23
0
 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
     });
 }
Exemplo n.º 24
0
    // 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;
    }
Exemplo n.º 25
0
        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);
        }
Exemplo n.º 26
0
    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);
        }
    }
Exemplo n.º 27
0
        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);
        }
Exemplo n.º 28
0
        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
            });
        }
Exemplo n.º 29
0
        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));
        }
Exemplo n.º 30
0
        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);
        }
Exemplo n.º 31
0
        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);
        }