Ejemplo n.º 1
0
        public void AutoSplitPlayerCell(PlayerCell cell)
        {
            var minSplit  = Settings.playerMaxSize * Settings.playerMaxSize;
            var cellsLeft = 1 * Settings.playerMaxCells - cell.owner.ownedCells.Count;
            var overflow  = (float)Math.Ceiling(cell.SquareSize / minSplit);

            if (overflow == 1 || cellsLeft <= 0)
            {
                return;
            }
            var splitTimes = (int)Math.Min(overflow, cellsLeft);
            var splitSize  = (float)Math.Min(Math.Sqrt(cell.SquareSize / splitTimes), Settings.playerMaxSize);
            var random     = new Random();

            for (int i = 1; i < splitTimes; i++)
            {
                var angle = (float)(random.NextDouble() * 2 * Math.PI);
                LaunchPlayerCell(cell, splitSize, new Boost
                {
                    dx = (float)Math.Sin(angle),
                    dy = (float)Math.Cos(angle),
                    d  = Settings.playerSplitBoost
                });
            }
            cell.Size = splitSize;
        }
Ejemplo n.º 2
0
        private void HandlePlayer(Point currentPoint, Color dotColor, Color[] colorData, Level level)
        {
            Point      position = GetCenterPoint(currentPoint, dotColor, colorData);
            PlayerCell player   = new PlayerCell(PlayWindow, PointToPosition(position));

            level.SetPlayer(player);
        }
Ejemplo n.º 3
0
    // Layout interface
    public void LayoutInterface(int newPlayer)
    {
        // Set interface
        playerIndex = newPlayer;

        // Get player
        GamePlayer player = null;

        if (playerIndex >= 0 && GameManager.instance.players != null && playerIndex < GameManager.instance.players.Count)
        {
            player = GameManager.instance.players[playerIndex];
        }
        // Get character
        GameCharacter character = null;

        if (player != null && player.characterIndex >= 0 && player.characterIndex < GameManager.instance.gameData.characters.Length)
        {
            character = GameManager.instance.gameData.characters[player.characterIndex];
        }

        // Set character icon & tints
        characterName.text = character == null ? "???" : character.characterName;
        PlayerCell.SetCharacterIcon(characterIcon, character == null ? null : character.characterIconTexture);
        foreach (Image t in characterTintables)
        {
            t.color = GameManager.instance.GetPlayerColor(playerIndex);
        }

        // Set Default Score
        LayoutScore();

        // Set animation items
        playerPosition = _rect.anchoredPosition;
        Animate(true);
    }
Ejemplo n.º 4
0
 private void CurrentTurn_LoadPlayerPositionEvent(PlayerCell playerCell)
 {
     Cell lastPosition = PlayerCell.LastTurnPosition;
       PlayerCell = playerCell;
       PlayerCell.LastTurnPosition = lastPosition;
       PlayerCell.DetermineFacing();
 }
Ejemplo n.º 5
0
        private void LoadLevel(String file)
        {
            World.Clear();
            GoodCellList.Clear();
            VirusList.Clear();

            _level    = _levelParser.Parse(Texture2D.FromStream(Game1.graphics.GraphicsDevice, new FileStream(file, FileMode.Open)));
            _wallList = _level.GetWalls();


            foreach (var item in _level.GetFriendlies())
            {
                GoodCellList.Add((GoodCell)item);
            }

            foreach (var item in _level.GetEnemies())
            {
                VirusList.Add((Virus)item);
            }

            _objectList = _level.GetFriendlies();
            _objectList.AddRange(_level.GetEnemies());

            _player = _level.Player;
        }
Ejemplo n.º 6
0
        public static Line[] VerLines(FieldContext gameProcess, PlayerCell flag)
        {
            Line[] ArrVer = new Line[(gameProcess.QuanRows) * (gameProcess.QuanCols)];
            int    N      = 1;

            for (int j = 0; j < gameProcess.QuanCols; j++)
            {
                Line a = EmptyLine;
                a.length = 0;
                a.y_coor = j;
                for (int i = 0; i < gameProcess.QuanRows; i++)
                {
                    PlayerCell d = gameProcess.Field[i, j];
                    if (d == flag)
                    {
                        if (a.length == 0)
                        {
                            a.x_coor = i;
                        }
                        a.length++;
                    }

                    if ((d != flag || i == 2 * gameProcess.N - 2) && a.length != 0)
                    {
                        ArrVer[N++] = a;
                        a.length    = 0;
                    }
                }
            }
            ArrVer[0].length = N;
            return(ArrVer);
        }
Ejemplo n.º 7
0
        public void MakeStep(int col, FieldContext gameProcess, PlayerCell first)
        {
            int k = 0;

            for (int i = 0; i < 2 * gameProcess.N - 1; i++)
            {
                k += gameProcess.FreePositions[i];
            }
            if (k == 1)
            {
                if (gameProcess.Field[0, gameProcess.N] == PlayerCell.Hero)
                {
                    gameProcess.Field[gameProcess.FreePositions[gameProcess.N - 1], gameProcess.N - 1] = PlayerCell.Antagonist;
                    gameProcess.FreePositions[gameProcess.N - 1]++;
                }
                else
                {
                    gameProcess.Field[gameProcess.FreePositions[gameProcess.N], gameProcess.N] = PlayerCell.Antagonist;
                    gameProcess.FreePositions[gameProcess.N]++;
                }
            }
            else
            {
                Win       a = new Win(0);
                StepScore s = Minimax(gameProcess, first, PlayerCell.Antagonist, 0, -1, a);
                col = s.Step;
                gameProcess.FillField(col, PlayerCell.Antagonist);
            }
            k++;
        }
Ejemplo n.º 8
0
    // Reload cell
    private void ReloadCell(int playerIndex)
    {
        Transform  child = playerTable.GetChild(playerIndex);
        PlayerCell cell  = child.GetComponent <PlayerCell>();

        cell.SetPlayer(playerIndex);
    }
Ejemplo n.º 9
0
        public void SpawnPlayer(Player player, PointF pos, float size)
        {
            var playerCell = new PlayerCell(player, pos.X, pos.Y, size);

            AddCell(playerCell);
            player.UpdateState(PlayerState.Alive);
        }
Ejemplo n.º 10
0
 public bool CheckSupportee(PlayerCell cell)
 {
     if (Vector3.SqrMagnitude(cell.transform.position - this.transform.position) < tetherRange * tetherRange)
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 11
0
 static public void LoadContent(GraphicsDevice graphicsDevice)
 {
     PlayerCell.LoadContent(graphicsDevice);
     GoodCell.LoadContent(graphicsDevice);
     Virus.LoadContent(graphicsDevice);
     BackgroundObjectsHandler.LoadContet();
     Wall.LoadContent();
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Checks for collision between enemies and player cells
 /// </summary>
 /// <param name="enemy">Enemy cell to be checked</param>
 /// <param name="player">Nearest Player Cell</param>
 public void CheckCollide(EnemyCell enemy, PlayerCell player)
 {
     if (Vector3.SqrMagnitude(enemy.transform.position - player.transform.position) <= enemy.GetComponent <CircleCollider2D>().radius / 20)
     {
         Debug.Log(Vector3.SqrMagnitude(enemy.transform.position - player.transform.position));
         enemy.isStopped  = true;
         player.isStopped = true;
         player.SetKillTimer(enemy.type);
     }
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Default Constructor
 /// </summary>
 public Sensor()
 {
     CurrentTurn = new World();
       CurrentTurn.LoadOpponentPositionEvent += new LoadOpponentPositionEventHandler(CurrentTurn_LoadOpponentPositionEvent);
       CurrentTurn.LoadPlayerPositionEvent += new LoadPlayerPositionEventHandler(CurrentTurn_LoadPlayerPositionEvent);
       LastTurn = new World();
       LastTurn.LoadOpponentPositionEvent += new LoadOpponentPositionEventHandler(LastTurn_LoadOpponentPositionEvent);
       LastTurn.LoadPlayerPositionEvent += new LoadPlayerPositionEventHandler(LastTurn_LoadPlayerPositionEvent);
       PlayerCell = new PlayerCell();
       OpponentCell = new OpponentCell();
 }
Ejemplo n.º 14
0
        private static long HeuristicLineAntagonist(Line[] arr, int n, PlayerCell first, PlayerCell flag)
        {
            long sum = 0;

            for (int i = 1; i < arr[0].length; i++)
            {
                sum += factorial(arr[i].length + 2);
            }

            return(sum);
        }
Ejemplo n.º 15
0
        public void GetFromConsoleUserStep(FieldContext gameProcess, PlayerCell first)
        {
            string a   = Console.ReadLine();
            int    col = 0;

            for (int i = 0; i < a.Length; i++)
            {
                col *= 10;
                int c = a[i] - '0';
                col += c;
            }
            MakeStep(col, gameProcess, first);
        }
Ejemplo n.º 16
0
        public void LaunchPlayerCell(PlayerCell cell, float size, Boost boost)
        {
            cell.SquareSize -= size * size;
            var X       = cell.X + 20 * boost.dx;
            var Y       = cell.Y + 20 * boost.dy;
            var newCell = new PlayerCell(cell.owner, X, Y, size);

            newCell.boost.dx = boost.dx;
            newCell.boost.dy = boost.dy;
            newCell.boost.d  = boost.d;
            AddCell(newCell);
            SetCellAsBoosting(newCell);
        }
Ejemplo n.º 17
0
    // Update is called once per frame
    new void Update()
    {
        base.Update();

        checktimer -= Time.deltaTime;

        if (aiMode)
        {
            if (target == null)
            {
                target = FindNearestPlayer();
            }
        }
    }
Ejemplo n.º 18
0
    /// <summary>
    /// Creates a new player cell
    /// </summary>
    public void NewPlayer(int cellType)
    {
        // this is the bottom of the bone
        Vector3 startPos = new Vector3(7.3f, -1.5f, 0.001f);//Camera.main.ScreenToWorldPoint(Input.mousePosition);
        //tempPos.z = 0;
        GameObject tempP  = GameObject.Instantiate(playerCellPrefabs[cellType], startPos, Quaternion.identity);
        PlayerCell script = tempP.GetComponent <PlayerCell>();

        //script.aiMode = true;
        script.position = startPos;
        //tempP.gameObject.transform.localScale = new Vector3((7/100), (7/100)); //it didnt like floats
        playerCells.Add(script);
        stats[1]++;
    }
Ejemplo n.º 19
0
    // Refresh interface
    protected virtual void SetInterface(int playerIndex)
    {
        // Set player
        GamePlayer player = GameManager.instance.GetPlayer(playerIndex);

        playerLabel.text = "P" + (playerIndex + 1);

        // Set character
        GameCharacter character = GameManager.instance.gameData.characters[player.characterIndex];

        characterLabel.text = character.characterName.ToUpper();
        PlayerCell.SetCharacterIcon(characterIcon, character.characterIconTexture);

        // Set tints
        Color tint = GameManager.instance.GetPlayerColor(playerIndex);

        foreach (Graphic t in tintables)
        {
            t.color = tint;
        }

        // Set borders
        Texture2D texture = GameManager.instance.GetPlayerBorder(playerIndex);

        foreach (RawImage border in borders)
        {
            border.texture = texture;
            if (texture != null)
            {
                border.color  = Color.white;
                border.uvRect = new Rect(0f, 0f, border.rectTransform.rect.width / (float)texture.width, border.rectTransform.rect.height / (float)texture.height);
            }
            else
            {
                border.color  = Color.black;
                border.uvRect = new Rect(0f, 0f, 1f, 1f);
            }
        }

        // Set text outline
        tint.r *= playerBorderTint;
        tint.g *= playerBorderTint;
        tint.b *= playerBorderTint;
        playerLabel.fontMaterial.SetColor("_OutlineColor", tint);

        // Set match button
        _player = GameManager.instance.lastWinner;
        SetInputButton(2);
    }
Ejemplo n.º 20
0
 /// <summary>
 /// Builds the world from the input given as a string
 /// </summary>
 /// <param name="newWorld"></param>
 /// <returns></returns>
 public bool BuildWorld(string[] newWorld)
 {
     bool builtWorld = false;
       if (newWorld.Length > 0) {
     OpponentCell opponent = null;
     PlayerCell player = null;
     for (var i = 0; i < newWorld.Length; i++) {
       string[] line = newWorld[i].Split(' ');
       int x = int.Parse(line[0]);
       int y = int.Parse(line[1]);
       if (!Cells.ContainsKey(x)) {
     Cells.Add(x, new Dictionary<int, Cell>());
       }
       if (!Cells[x].ContainsKey(y)) {
     CellContent content = Cell.GetWorldState(line[2]);
     switch (content) {
       case CellContent.Opponent:
         opponent = new OpponentCell() { X = x, Y = y, Content = content, Value = 0 };
         Cells[x].Add(y, opponent);
         break;
       case CellContent.You:
         player = new PlayerCell() { X = x, Y = y, Content = content, Value = 0 };
         Cells[x].Add(y, player);
         break;
       case CellContent.OpponentWall:
         Cells[x].Add(y, new Cell() { X = x, Y = y, Content = content, Value = 0 });
         break;
       case CellContent.YourWall:
         Cells[x].Add(y, new Cell() { X = x, Y = y, Content = content, Value = 0 });
         break;
       case CellContent.Clear:
         Cells[x].Add(y, new Cell() { X = x, Y = y, Content = content, Value = 1 });
         break;
     }
       }
       builtWorld = true;
     }
     if (LoadOpponentPositionEvent != null) {
       LoadPositions(opponent);
       LoadOpponentPositionEvent(opponent);
     }
     if (LoadOpponentPositionEvent != null) {
       LoadPositions(player);
       LoadPlayerPositionEvent(player);
     }
       }
       return builtWorld;
 }
Ejemplo n.º 21
0
        public void PopPlayerCell(PlayerCell cell)
        {
            var splits = DistributeCellMass(cell);
            var random = new Random();

            for (int i = 0, l = splits.Count; i < l; i++)
            {
                var angle = (float)random.NextDouble() * 2 * Math.PI;
                LaunchPlayerCell(cell, (float)Math.Sqrt(splits[i] * 100), new Boost
                {
                    dx = (float)Math.Sin(angle),
                    dy = (float)Math.Cos(angle),
                    d  = Settings.playerSplitBoost
                });
            }
        }
Ejemplo n.º 22
0
        private static long HeuristicLineHero(Line[] arr, int n, PlayerCell first, PlayerCell flag)
        {
            long sum = 0;

            for (int i = 1; i < arr[0].length; i++)
            {
                if (arr[i].length == n)
                {
                    return((long)1e12);
                }

                sum += factorial(arr[i].length + 2);
            }

            return(sum);
        }
Ejemplo n.º 23
0
 // Player hit okay
 private void PlayerClick(int playerIndex)
 {
     if (playerIndex == 0)
     {
         Transform  child = playerTable.GetChild(playerIndex);
         PlayerCell cell  = child.GetComponent <PlayerCell>();
         if (cell.inputButton == PlayerCell.PlayerInputButton.Home)
         {
             GoToTitle();
         }
         else if (cell.inputButton == PlayerCell.PlayerInputButton.Start)
         {
             GoToGame();
         }
     }
 }
Ejemplo n.º 24
0
        public static long heuristic(FieldContext gameProcess, PlayerCell first, PlayerCell flag)
        {
            long score = 0;

            score = HeuristicHero(gameProcess, first, flag);

            if (Math.Abs(score) >= 1e12)
            {
                return(score);
            }

            long oppositeScore = 0;

            oppositeScore = heuristicAntagonist(gameProcess, first, gameProcess.GetOppositePlayer(flag)); //при этой и нижней строке одинаковый результат
                                                                                                          //	oppositeScore = heuristicUser(n, field, first, getOppositeFlag(flag));
            score += oppositeScore;
            return(score);
        }
Ejemplo n.º 25
0
        public int EndOfTheGame(PlayerCell flag)
        {
            Line[] arr1 = LinesCounter.HorLines(this, flag);
            for (int i = 1; i < arr1[0].length; i++)
            {
                if (arr1[i].length >= N)
                {
                    return(1);
                }
            }
            Line[] arr2 = LinesCounter.VerLines(this, flag);
            for (int i = 1; i < arr2[0].length; i++)
            {
                if (arr2[i].length >= N)
                {
                    return(1);
                }
            }
            Line[] arr3 = LinesCounter.DiagLeft(this, flag);
            for (int i = 1; i < arr3[0].length; i++)
            {
                if (arr3[i].length >= N)
                {
                    return(1);
                }
            }
            Line[] arr4 = LinesCounter.DiagRight(this, flag);
            for (int i = 1; i < arr4[0].length; i++)
            {
                if (arr4[i].length >= N)
                {
                    return(1);
                }
            }
            bool c = Overflow(Field);

            if (c)
            {
                return(0);
            }

            return(-1);
        }
Ejemplo n.º 26
0
    public void Trigger <T>(T param)
    {
        //casteos estaticos y dinamicos para cambiar tipos de datos
        //estaticos cuando estoy segura de que va a ser ese tipo de dato
        //si no es lo que dije se guarda como null
        PlayerCell player = param as PlayerCell;

        if (_isBig)
        {
            //player do something
            //afecta a los fantasmas
            EventController.TriggerEvent(_bigPelletEvent);
        }
        else
        {
            //agrega score al player
            player.UpdateScore(_scoreMultiplier);
        }
    }
Ejemplo n.º 27
0
        public static Line[] DiagRight(FieldContext gameProcess, PlayerCell flag)
        {
            Line[] ArrDiag = new Line[(gameProcess.QuanCols) * (gameProcess.QuanRows)];
            int    N       = 1;

            bool[,] check = new bool[gameProcess.QuanRows, gameProcess.QuanCols];

            for (int i = 0; i < gameProcess.QuanRows; i++)
            {
                Line a = EmptyLine;
                a.length = 0;
                a.x_coor = i;
                for (int j = 0; j < gameProcess.QuanCols; j++)
                {
                    a.y_coor = j;
                    if (check[i, j] == false && gameProcess.Field[i, j] == flag)
                    {
                        a.length = 0;
                        for (int k = 0; (k + j < gameProcess.QuanCols) && (k + i < gameProcess.QuanRows); k++)
                        {
                            PlayerCell d = gameProcess.Field[k + i, k + j];
                            if (d == flag)
                            {
                                a.length++;
                                check[k + i, k + j] = true;
                            }
                            if ((d != flag || i + k == 2 * gameProcess.N - 2 || j + k == 2 * gameProcess.N - 1) && a.length != 0)
                            {
                                ArrDiag[N++] = a;
                                a.length     = 0;
                                break;
                            }
                        }
                    }
                }
            }
            ArrDiag[0].length = N;
            return(ArrDiag);
        }
Ejemplo n.º 28
0
    private void Update()
    {
        // Should disable
        bool shouldDisable = !IsEveryoneReady();

        if (startButton.isDisabled != shouldDisable)
        {
            SetDisabled(shouldDisable);
        }
        // Get child
        if (playerTable.childCount > 0)
        {
            Transform  child = playerTable.GetChild(0);
            PlayerCell cell  = child.GetComponent <PlayerCell>();
            if (_btnType != cell.inputButton)
            {
                _btnType = cell.inputButton;
                homeButton.SetInputPlayer(_btnType == PlayerCell.PlayerInputButton.Home ? 0 : -1);
                startButton.SetInputPlayer(_btnType == PlayerCell.PlayerInputButton.Start ? 0 : -1);
            }
        }
    }
Ejemplo n.º 29
0
        public void MovePlayerCell(PlayerCell cell)
        {
            var router = cell.owner.router;

            if (router.disconnected)
            {
                return;
            }
            var dx = router.mouseX - cell.X;
            var dy = router.mouseY - cell.Y;
            var d  = (float)Math.Sqrt(dx * dx + dy * dy);

            if (d < 1)
            {
                return;
            }
            dx /= d;
            dy /= d;
            var m = Math.Min(cell.MoveSpeed, d) * handle.stepMult;

            cell.X += dx * m;
            cell.Y += dy * m;
        }
Ejemplo n.º 30
0
    public void Trigger <T>(T param)
    {
        if (!(param is PlayerCell))
        {
            return;
        }

        PlayerCell player = param as PlayerCell;

        switch (dotType)
        {
        case DotType.Big:
            EventController.TriggerEvent(dotBigEvent);
            break;

        case DotType.Small:
            player.UpdateScore(scoreMultiplier);
            break;

        default:
            break;
        }
    }
Ejemplo n.º 31
0
        private static long heuristicAntagonist(FieldContext gameProcess, PlayerCell first, PlayerCell flag)
        {
            long score = 0;

            Line[] arr = LinesCounter.DiagLeft(gameProcess, flag);
            score += HeuristicLineAntagonist(arr, gameProcess.N, first, flag);

            arr    = LinesCounter.DiagRight(gameProcess, flag);
            score += HeuristicLineAntagonist(arr, gameProcess.N, first, flag);

            arr    = LinesCounter.HorLines(gameProcess, flag);
            score += HeuristicLineAntagonist(arr, gameProcess.N, first, flag);

            arr    = LinesCounter.VerLines(gameProcess, flag);
            score += HeuristicLineAntagonist(arr, gameProcess.N, first, flag);

            if (flag == PlayerCell.Antagonist)//bot
            {
                score = (-1) * score;
            }

            return(score);
        }
Ejemplo n.º 32
0
        private void TestInit()
        {
            World = new World(Vector2.Zero);

            _objectList = new List <ActiveGameObject>();

            _player = new PlayerCell(this, new Vector2(0));

            GoodCell goodCell = new GoodCell(this, new Vector2(300, 100));

            GoodCellList.Add(goodCell);
            _objectList.Add(goodCell);
            _objectList.Add(new Virus(this, new Vector2(200, -200)));


            //Vertices vertices = new Vertices();
            //vertices.Add(new Vector2(-300, -200));
            //vertices.Add(new Vector2(-200, -150));
            //vertices.Add(new Vector2(-100, -200));
            //vertices.Add(new Vector2(-160, -300));
            //vertices.Add(new Vector2(-240, -300));

            //_wallList.Add(new Wall(vertices, Wall.WallType.Outer, this));

            Vertices vertices = new Vertices();

            vertices.Add(new Vector2(-200, 200));
            vertices.Add(new Vector2(-150, 225));
            vertices.Add(new Vector2(-100, 200));
            vertices.Add(new Vector2(-125, 250));
            vertices.Add(new Vector2(-100, 300));
            vertices.Add(new Vector2(-150, 275));
            vertices.Add(new Vector2(-200, 300));
            vertices.Add(new Vector2(-175, 250));

            _wallList.Add(new Wall(vertices, Wall.WallType.Outer, this));
        }
Ejemplo n.º 33
0
 public void SetPlayer(PlayerCell player)
 {
     Player = player;
 }
Ejemplo n.º 34
0
 /// <summary>
 /// Event which is fired when the players last position is loaded
 /// </summary>
 /// <param name="playerCell">Player last turn position</param>
 private void LastTurn_LoadPlayerPositionEvent(PlayerCell playerCell)
 {
     PlayerCell.LastTurnPosition = playerCell;
 }