Exemple #1
0
    void ShowPath_AStar()
    {
        MapPosition pos = endPoint;

        while (!pos.Equals(startPoint))
        {
            GameObject gameObject = searchBlocks[pos.PosX, pos.PosY];
            gameObject.GetComponent <Renderer>().material = pathMat;

            pos = astarSearch[pos.PosX, pos.PosY].Parent;
        }
    }
Exemple #2
0
        /// <summary>
        /// Returns true if ClanWarMember instances are equal
        /// </summary>
        /// <param name="input">Instance of ClanWarMember to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(ClanWarMember?input)
        {
            if (input == null)
            {
                return(false);
            }

            return
                ((
                     Tag == input.Tag ||
                     (Tag != null &&
                      Tag.Equals(input.Tag))
                     ) &&
                 (
                     Name == input.Name ||
                     (Name != null &&
                      Name.Equals(input.Name))
                 ) &&
                 (
                     MapPosition == input.MapPosition ||
                     MapPosition.Equals(input.MapPosition)
                 ) &&
                 (
                     TownhallLevel == input.TownhallLevel ||
                     TownhallLevel.Equals(input.TownhallLevel)
                 ) &&
                 (
                     OpponentAttacks == input.OpponentAttacks ||
                     OpponentAttacks.Equals(input.OpponentAttacks)
                 ) &&
                 (
                     BestOpponentAttack == input.BestOpponentAttack ||
                     (BestOpponentAttack != null &&
                      BestOpponentAttack.Equals(input.BestOpponentAttack))
                 ) &&
                 (
                     Attacks == input.Attacks ||
                     Attacks != null &&
                     input.Attacks != null &&
                     Attacks.SequenceEqual(input.Attacks)
                 ));
        }
    private void MoveNext()
    {
        if (_folowingMove.IsMoving)
        {
            return;
        }

        MapPosition nextPosition = TryGetNextPosition(_currentPosition);

        if (nextPosition.Equals(_currentPosition))
        {
            StopMove?.Invoke();
            return;
        }

        _currentPosition = nextPosition;
        Vector3 scenePosition = _navigator.ToScenePosition(_currentPosition);

        _folowingMove.Move(scenePosition);

        StartMoveNext?.Invoke();
    }
Exemple #4
0
    void Astar()
    {
        searchingList = new List <MapPosition>();
        astarSearch   = new AStarScore[map.GetLength(0), map.GetLength(1)];

        astarSearch[startPoint.PosX, startPoint.PosY] = new AStarScore(0, 0);

        searchingList.Add(startPoint);

        MapPosition checkingPos = searchingList[0];

        searchingList.RemoveAt(0);

        while (!checkingPos.Equals(endPoint))
        {
            if (CheckPos(-1, 0))
            {
                return;
            }
            if (CheckPos(1, 0))
            {
                return;
            }
            if (CheckPos(0, -1))
            {
                return;
            }
            if (CheckPos(0, 1))
            {
                return;
            }

            searchingList.Sort((MapPosition pos1, MapPosition pos2) =>
            {
                AStarScore a1 = astarSearch[pos1.PosX, pos1.PosY];
                AStarScore a2 = astarSearch[pos2.PosX, pos2.PosY];

                return(a1.CompareTo(a2));
            });

            checkingPos = searchingList[0];
            searchingList.RemoveAt(0);
        }

        bool CheckPos(int offsetX, int offsetY)
        {
            int x = checkingPos.PosX + offsetX;
            int y = checkingPos.PosY + offsetY;

            if (x >= 0 && x < H && y >= 0 && y < W)
            {
                AStarScore tempScore = astarSearch[x, y];

                AStarScore  checkingScore = astarSearch[checkingPos.PosX, checkingPos.PosY];
                MapPosition tempPos       = new MapPosition(x, y);

                //////////////////if (map[x, y] == END)
                //////////////////{
                //////////////////    AScore a = new AScore(checkingScore._gScore + 1, 0);
                //////////////////    a.Parent = checkingPos;
                //////////////////    astarSearch[x, y] = a;

                //////////////////    searchBlocks[x, y].transform.GetChild(0).GetChild(0).GetComponent<Text>().text = astarSearch[x, y].g.ToString();
                //////////////////    searchBlocks[x, y].transform.GetChild(0).GetChild(1).GetComponent<Text>().text = astarSearch[x, y].h.ToString();
                //////////////////    searchBlocks[x, y].transform.GetChild(0).GetChild(2).GetComponent<Text>().text = astarSearch[x, y].F.ToString();
                //////////////////    searchBlocks[x, y].GetComponent<Renderer>().material = searchMat;
                //////////////////    searchBlocks[x, y].SetActive(true);

                //////////////////    isFound = true;
                //////////////////    searchingList.Clear();
                //////////////////    return true;
                //////////////////}
                //////////////////if (map[x, y] == EMPTY)
                //////////////////{
                //////////////////    if (tempScore == null)
                //////////////////    {
                //////////////////        AScore a = new AScore(checkingScore._gScore + 1, MapPosition.AStarDistance(tempPos, endPoint));
                //////////////////        a.Parent = checkingPos;
                //////////////////        astarSearch[x, y] = a;
                //////////////////        searchingList.Add(tempPos);
                //////////////////    }
                //////////////////    else if (tempScore._gScore > checkingScore._gScore + 1)
                //////////////////    {
                //////////////////        tempScore._gScore = checkingScore._gScore + 1;
                //////////////////        tempScore.Parent = checkingPos;

                //////////////////        if (!searchingList.Contains(tempPos))
                //////////////////        {
                //////////////////            searchingList.Add(tempPos);
                //////////////////        }
                //////////////////    }

                //////////////////    searchBlocks[x, y].transform.GetChild(0).GetChild(0).GetComponent<Text>().text = astarSearch[x, y].g.ToString();
                //////////////////    searchBlocks[x, y].transform.GetChild(0).GetChild(1).GetComponent<Text>().text = astarSearch[x, y].h.ToString();
                //////////////////    searchBlocks[x, y].transform.GetChild(0).GetChild(2).GetComponent<Text>().text = astarSearch[x, y].F.ToString();
                //////////////////    searchBlocks[x, y].GetComponent<Renderer>().material = searchMat;
                //////////////////    searchBlocks[x, y].SetActive(true);
                //////////////////}
            }

            return(false);
        }
    }
Exemple #5
0
    IEnumerator DFS()
    {
        //searchingQueue = new Queue<Pos>();
        searchingList = new List <MapPosition>();

        search = new int[map.GetLength(0), map.GetLength(1)];
        for (int i = 0; i < search.GetLength(0); i++)
        {
            for (int j = 0; j < search.GetLength(1); j++)
            {
                search[i, j] = EMPTY;
            }
        }

        search[startPoint.PosX, startPoint.PosY] = 0;

        //searchingQueue.Enqueue(startPoint);
        searchingList.Add(startPoint);

        //Pos checkingPos = searchingQueue.Dequeue();
        MapPosition checkingPos = searchingList[searchingList.Count - 1];

        searchingList.RemoveAt(searchingList.Count - 1);

        while (!checkingPos.Equals(endPoint))
        {
            if (CheckPos(-1, 0))
            {
                yield break;
            }
            if (CheckPos(1, 0))
            {
                yield break;
            }
            if (CheckPos(0, -1))
            {
                yield break;
            }
            if (CheckPos(0, 1))
            {
                yield break;
            }

            //checkingPos = searchingQueue.Dequeue();
            checkingPos = searchingList[searchingList.Count - 1];
            searchingList.RemoveAt(searchingList.Count - 1);

            yield return(null);
        }

        bool CheckPos(int offsetX, int offsetY)
        {
            int x = checkingPos.PosX + offsetX;
            int y = checkingPos.PosY + offsetY;



            if (x >= 0 && x < H && y >= 0 && y < W)
            {
                Debug.Log(x + ", " + y);

                if (map[x, y] == END)
                {
                    search[x, y] = search[checkingPos.PosX, checkingPos.PosY] + 1;

                    searchBlocks[x, y].transform.GetChild(0).GetChild(0).GetComponent <Text>().text = search[x, y].ToString();
                    searchBlocks[x, y].GetComponent <Renderer>().material = searchMat;
                    searchBlocks[x, y].SetActive(true);

                    isFound = true;
                    //searchingQueue.Clear();
                    searchingList.Clear();
                    return(true);
                }

                if (map[x, y] == EMPTY && (search[x, y] == EMPTY || search[x, y] > search[checkingPos.PosX, checkingPos.PosY]))
                {
                    MapPosition temp = new MapPosition(x, y);

                    search[x, y] = search[checkingPos.PosX, checkingPos.PosY] + 1;

                    mapBlocks[x, y].SetActive(false);

                    searchBlocks[x, y].transform.GetChild(0).GetChild(0).GetComponent <Text>().text = search[x, y].ToString();
                    searchBlocks[x, y].GetComponent <Renderer>().material = searchMat;
                    searchBlocks[x, y].SetActive(true);

                    searchingList.Add(temp);
                }
            }

            return(false);
        }
    }
Exemple #6
0
    IEnumerator BFS()
    {
        searchingQueue = new Queue <MapPosition>();
        search         = new int[map.GetLength(0), map.GetLength(1)];
        for (int i = 0; i < search.GetLength(0); i++)
        {
            for (int j = 0; j < search.GetLength(1); j++)
            {
                search[i, j] = EMPTY;
            }
        }

        search[startPoint.PosX, startPoint.PosY] = 0;
        //searchingQueue.Clear();
        searchingQueue.Enqueue(startPoint);

        MapPosition checkingPos = searchingQueue.Dequeue();

        while (!checkingPos.Equals(endPoint))
        {
            // int up = checkingPos.PosX - 1;
            // int down = checkingPos.PosX + 1;
            // int left = checkingPos.PosY - 1;
            // int right = checkingPos.PosY + 1;

            // if (CheckPos(up, checkingPos.PosY)) yield break;
            // if (CheckPos(down, checkingPos.PosY)) yield break;
            // if (CheckPos(checkingPos.PosX, left)) yield break;
            // if (CheckPos(checkingPos.PosX, right)) yield break;
            if (CheckPos(-1, 0))
            {
                yield break;
            }
            if (CheckPos(1, 0))
            {
                yield break;
            }
            if (CheckPos(0, -1))
            {
                yield break;
            }
            if (CheckPos(0, 1))
            {
                yield break;
            }

            checkingPos = searchingQueue.Dequeue();
            //Debug.Log(checkingPos.PosX + ", " + checkingPos.PosY);
            //yield return new WaitForSeconds(.01f);
            yield return(null);
        }

        bool CheckPos(int offsetX, int offsetY)
        {
            int x = checkingPos.PosX + offsetX;
            int y = checkingPos.PosY + offsetY;

            if (x >= 0 && x < H && y >= 0 && y < W)
            {
                if (map[x, y] == END)
                {
                    //Debug.Log(x + ", " + y);

                    search[x, y] = search[checkingPos.PosX, checkingPos.PosY] + 1;

                    searchBlocks[x, y].transform.GetChild(0).GetChild(0).GetComponent <Text>().text = search[x, y].ToString();
                    searchBlocks[x, y].GetComponent <Renderer>().material = searchMat;
                    searchBlocks[x, y].SetActive(true);

                    isFound = true;
                    searchingQueue.Clear();
                    return(true);
                }

                if (map[x, y] == EMPTY && search[x, y] == EMPTY)
                {
                    MapPosition temp = new MapPosition(x, y /* , checkingPos.step + 1 */);
                    //search[x, y] = temp.step;
                    search[x, y] = search[checkingPos.PosX, checkingPos.PosY] + 1;

                    //Vector3 spawnPos = new Vector3(temp.PosY, transform.position.y - 0.5f, -temp.PosX);
                    //Instantiate(prefabSearch, spawnPos, Quaternion.identity).transform.GetChild(0).GetChild(0).GetComponent<Text>().text = temp.step.ToString();
                    mapBlocks[x, y].SetActive(false);

                    searchBlocks[x, y].transform.GetChild(0).GetChild(0).GetComponent <Text>().text = search[x, y].ToString();
                    searchBlocks[x, y].GetComponent <Renderer>().material = searchMat;
                    searchBlocks[x, y].SetActive(true);

                    //Debug.Log(temp.PosX + ", " + temp.PosY);

                    // if (temp.Equals(endPoint))
                    // {
                    //     endPoint.step = temp.step;
                    //     isFound = true;
                    //     searchingQueue.Clear();
                    //     return true;
                    // }

                    searchingQueue.Enqueue(temp);
                }
            }

            return(false);
        }
    }
Exemple #7
0
 /// <summary>
 /// Przeładowana funkcja z klasy object sprawdzająca rownosc pol.
 /// </summary>
 /// <returns>''true' jesli pola sa tym samym polem, w przeciwnym wypadku 'false'</returns>
 public bool Equals(MapField other)
 {
     return(MapPosition.Equals(other.MapPosition));
 }
    public void TriggerCurrentSelectedSkill(MapPosition targetPosition)
    {
        if (!this._validPositionsForSelectedSkill.Contains(targetPosition))
        {
            return;
        }

        if(this.CurrentActor != null && this.CurrentActor.SelectedSkill != null)
        {
            if (targetPosition.Equals(this.CurrentActor.SkillTargetPosition))
            {
                // fire off skill
                var isValidAction = false;
                foreach (var result in this._currentActionResults)
                {
                    if (result.HasResult)
                    {
                        isValidAction = true;
                        break;
                    }
                }

                if (isValidAction)
                {
                    this.SetTileStateAtPositions(this._validPositionsForSelectedSkill, Tile.TileState.SkillRadius, false);
                    this._validPositionsForSelectedSkill.Clear();

                    this.ProcessActionResult(this._currentActionResults, BattlePhase.NextRound, () => {
                        this.UnsetCharacterSelectedSkillTarget(this.CurrentActor);
                        this.CurrentActor.UpateStatusEffectTurns();
                    });
                }
            }
            else
            {
                // update the target position and visual
                this.PreCalculateActionResults(targetPosition);
            }
        }
    }