Ejemplo n.º 1
0
 public StrategyData(SimBlock sb, Direction d)
 {
     simBlock    = new SimBlock(sb);
     direction   = d;
     winningTime = 0;
     testTime    = 0.001f;
 }
Ejemplo n.º 2
0
 public Damage(float _d, DamageType _type, Hero _h, SimBlock _t)
 {
     damage = _d;
     caster = _h;
     target = _t;
     type   = _type;
 }
Ejemplo n.º 3
0
    public override bool DoChangeDamageOnAttack(ref Damage[] dmgs)
    {
        SimBlock[] enermys  = BattleField.GetEnermyBlockSim(parent.GetHeroInfo().TeamColor);
        SimBlock   temBlock = parent.TemSimpleBlock;

        bool isBlocked = false;

        foreach (SimBlock b in enermys)
        {
            if (b.GetDistance(temBlock) <= 1)
            {
                isBlocked = true;
            }
        }

        if (isBlocked)
        {
            for (int i = 0; i < dmgs.Length; ++i)
            {
                dmgs[i].damage = 0;
            }
        }
        else
        {
            for (int i = 0; i < dmgs.Length; ++i)
            {
                dmgs[i].damage += temBlock.GetDistance(dmgs[i].target) * attackIncrease;
            }
        }

        return(!isBlocked);
    }
Ejemplo n.º 4
0
//	static public void ResetEmpty( Block centerBlock  )
//	{
//		for (int i = 0; i < Instance.gridWidth; ++i)
//			for (int j = 0; j < Instance.gridHeight; ++j) {
//				if (Instance.blockGrid [i, j].BlockInfo.state == Block.BlockState.Empty) {
//					Instance.blockGrid [i, j].BackgroundSetColor (Color.white);
//				}
//			}
//	}

    /// <summary>
    /// Rotates the blocks and remove the illegal block
    /// </summary>
    /// <returns>The blocks.</returns>
    /// <param name="blocks">Blocks.</param>
    /// <param name="center">Center.</param>
    /// <param name="direction">Direction.</param>
    static public SimBlock[] RotateBlocks(SimBlock[] blocks, SimBlock center, Direction direction)
    {
        List <SimBlock> res = new List <SimBlock>();
        int             ci  = center.m_i;
        int             cj  = center.m_j;

        for (int i = 0; i < blocks.Length; ++i)
        {
            // the relative coordinate of the block
            int ii = blocks[i].m_i - ci;
            int jj = blocks[i].m_j - cj;
            switch (direction)
            {
            case Direction.Right:
            {
                SimBlock b = new SimBlock(ci + ii, cj + jj);
                if (IsBlockInRange(b))
                {
                    res.Add(b);
                }
                break;
            }

            case Direction.Left:
            {
                SimBlock b = new SimBlock(ci - ii, cj - jj);
                if (IsBlockInRange(b))
                {
                    res.Add(b);
                }
                break;
            }

            case Direction.Up:
            {
                SimBlock b = new SimBlock(ci - jj, cj + ii);
                if (IsBlockInRange(b))
                {
                    res.Add(b);
                }
                break;
            }

            case Direction.Down:
            {
                SimBlock b = new SimBlock(ci + jj, cj - ii);
                if (IsBlockInRange(b))
                {
                    res.Add(b);
                }
                break;
            }

            default:
                break;
            }
            ;
        }
        return(res.ToArray());
    }
Ejemplo n.º 5
0
    public override float MoveTo(SimBlock block)
    {
        float duration    = LogicManager.moveDuration;
        Block targetBlock = BattleField.GetBlock(block);

        parent.transform.DOMove(targetBlock.linkedBlock.GetCenterPosition(), duration);
        return(duration);
    }
Ejemplo n.º 6
0
    public override void SetBlock(SimBlock block)
    {
        base.SetBlock(block);

        if (TemBlock != null)
        {
            transform.position = TemBlock.GetCenterPosition();
        }
    }
Ejemplo n.º 7
0
    public override SimBlock[] GetAttackRange(SimBlock temBlock, Direction direction, int attackRange)
    {
        List <SimBlock> res = new List <SimBlock>();

        for (int i = 1; i <= attackRange; ++i)
        {
            res.Add(new SimBlock(temBlock.m_i + i, temBlock.m_j));
        }
        return(BattleField.RotateBlocks(res.ToArray(), temBlock, direction));
    }
Ejemplo n.º 8
0
 public bool IsInAttackRange(SimBlock block)
 {
     foreach (SimBlock b in GetAttackRange())
     {
         if (b.Equals(block))
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 9
0
 public HistoryStep(HistoryStep other, Dictionary <Hero, Hero> heroMap)
 {
     type   = other.type;
     block  = new SimBlock(other.block);
     health = other.health;
     if (other.damages != null)
     {
         damages = new Damage[other.damages.Length];
         for (int i = 0; i < damages.Length; i++)
         {
             damages [i] = new Damage(other.damages [i], heroMap);
         }
     }
 }
Ejemplo n.º 10
0
//	void CalculateAI()
//	{
//		strategyList.Clear();
////		Debug.Log ("========= Start AI ==========");
//
//		SimBlock[] moveRange = parent.Move.GetMoveRange ();
//		int[] winTimes = new int[moveRange.Length*4];
//		for (int i = 0; i < winTimes.Length; ++i)
//			winTimes [i] = 0;
//
//
//		BattleField.StartVirtual ();
//		for (int i = 0; i < moveRange.Length; ++i)
//			for (int k = 0; k < 4; ++k) {
//				SimBlock moveTo = moveRange [i];
//				Direction direction = (Direction)k;
//				winTimes [i * 4 + k] = GetWinTime (moveTo, direction , AISimulateTime );
//			}
//
//		BattleField.EndVirtual ();
//
//		Debug.Log ("========= End AI ==========");
//
//		int maxIndex = 0;
//		for (int i = 1; i < winTimes.Length; ++i) {
//			if (winTimes [i] > winTimes [maxIndex])
//				maxIndex = i;
//			Debug.Log( "Win Time " + i + " " + winTimes[i] );
//		}
//		Debug.Log (" Max Winning Time = " + winTimes [maxIndex]);
//
//		bestTarget = moveRange [maxIndex / 4];
//		bestDirection = (Direction)(maxIndex % 4);
//
//	}

    public float GetWinTime(SimBlock moveTo, Direction direction, int interation)
    {
        float totalWin = 0;

//		Debug.Log ("【" + name + "】 Get Win Time by Move to " + moveTo.ToString () + " Direction " + direction);
        for (int k = 0; k < interation; ++k)
        {
            int round = 0;
//			Debug.Log ("The k = " + k + " time ");
            BattleField.CopyFromRealToVirtual();
            Hero virtualHero = BattleField.virtualHeroMap [parent];
            if (virtualHero != null)
            {
                if (virtualHero.Strategy is AIVirtualStrategy)
                {
                    ((AIVirtualStrategy)virtualHero.Strategy).ifFollowNext  = true;
                    ((AIVirtualStrategy)virtualHero.Strategy).nextBlock     = moveTo;
                    ((AIVirtualStrategy)virtualHero.Strategy).nextDirection = direction;
                }
            }
//			Debug.Log ("======= Begin Battle ======");
            while (round < AIDepth)
            {
//				Debug.Log ("----Round " + round + "----");
                round++;
//				Debug.Log ("The " + round + " round ");
                bool isForceResult = false;
                if (round == AIDepth)
                {
                    isForceResult = true;
                }
                float result = LogicManager.Instance.VirtualBattle(BattleField.virtualHeroList.ToArray(),
                                                                   parent.GetHeroInfo().TeamColor, isForceResult);
                if (result >= 0)
                {
                    totalWin += result;
                    break;
                }
//				TeamColor winningTeam = LogicManager.Instance.VirtualBattle (BattleField.virtualHeroList.ToArray() , isForceResult);
//				if (winningTeam != TeamColor.None) { // there is a result
//					totalWin += (winningTeam == parent.GetHeroInfo().TeamColor)?1:0;
//					Debug.Log (" winning team is " + winningTeam );
//					break;
//				}
            }
//			Debug.Log ("======= End Battle ======");
        }
//		Debug.Log ("Total wins " + totalWin);
        return(totalWin);
    }
Ejemplo n.º 11
0
 public Damage(Damage other, Dictionary <Hero, Hero> heroMap)
 {
     damage = other.damage;
     type   = other.type;
     caster = heroMap [other.caster];
     target = new SimBlock(other.target);
     if (other.buffs != null)
     {
         buffs = new Buff[other.buffs.Length];
         for (int i = 0; i < other.buffs.Length; ++i)
         {
             buffs [i] = BuffFactory.CreateBuffFrom(other.buffs [i], heroMap);
         }
     }
 }
Ejemplo n.º 12
0
    public override SimBlock[] GetMoveRange(SimBlock temBlock, Direction direction, int moveRange)
    {
        List <SimBlock> res = new List <SimBlock>();

        res.Add(temBlock);
        int ci = temBlock.m_i;
        int cj = temBlock.m_j;
        int i  = moveRange;

        res.Add(new SimBlock(ci + i, cj));
        res.Add(new SimBlock(ci, cj + i));
        res.Add(new SimBlock(ci - i, cj));
        res.Add(new SimBlock(ci, cj - i));

        return(BattleField.RotateBlocks(res.ToArray(), temBlock, direction));
    }
Ejemplo n.º 13
0
    public override SimBlock[] GetAttackRange(SimBlock temBlock, Direction direction, int attackRange)
    {
        List <SimBlock> blocks = new List <SimBlock>();
        int             ci     = temBlock.m_i;
        int             cj     = temBlock.m_j;

        for (int i = -attackRange; i <= attackRange; ++i)
        {
            for (int j = -attackRange; j <= attackRange; ++j)
            {
                blocks.Add(new SimBlock(ci + i, cj + j));
            }
        }

        return(BattleField.RotateBlocks(blocks.ToArray(), temBlock, direction));
    }
Ejemplo n.º 14
0
    /// <summary>
    /// Update the target block and direction
    /// </summary>
    /// <returns>The index of target strategy data.</returns>
    int UpdateTarget()
    {
        int index = Random.Range(0, strategyList.Count);

        for (int i = 0; i < strategyList.Count; ++i)
        {
            if (strategyList[i].winningRate > strategyList[index].winningRate)
            {
                index = i;
            }
        }

        bestTarget    = strategyList[index].simBlock;
        bestDirection = strategyList[index].direction;

        return(index);
    }
Ejemplo n.º 15
0
    public override SimBlock[] GetMoveRange(SimBlock temBlock, Direction direction, int moveRange)
    {
        List <SimBlock> res = new List <SimBlock>();

        for (int i = -moveRange; i <= moveRange; ++i)
        {
            for (int j = -moveRange; j <= moveRange; ++j)
            {
                SimBlock block = new SimBlock(temBlock.m_i + i, temBlock.m_j + j);
                if (block.GetDistance(temBlock) <= moveRange)
                {
                    res.Add(block);
                }
            }
        }
        return(BattleField.RotateBlocks(res.ToArray(), temBlock, direction));
    }
Ejemplo n.º 16
0
    public override SimBlock[] GetAttackRange(SimBlock temBlock, Direction direction, int attackRange)
    {
        List <SimBlock> res = new List <SimBlock>();
        int             ci  = temBlock.m_i;
        int             cj  = temBlock.m_j;

        for (int i = 1; i <= attackRange; ++i)
        {
            for (int j = -attackRange + 1; j < attackRange; ++j)
            {
                if (Mathf.Abs(j) < i)
                {
                    res.Add(new SimBlock(ci + i, cj + j));
                }
            }
        }
        return(BattleField.RotateBlocks(res.ToArray(), temBlock, direction));
    }
Ejemplo n.º 17
0
    public override SimBlock[] GetAttackRange(SimBlock temBlock, Direction direction, int attackRange)
    {
        List <SimBlock> res = new List <SimBlock>();
        int             ci  = temBlock.m_i;
        int             cj  = temBlock.m_j;

        for (int i = -attackRange; i <= attackRange; ++i)
        {
            for (int j = -attackRange; j <= attackRange; ++j)
            {
                if ((Mathf.Abs(i) + Mathf.Abs(j)) < attackRange)
                {
                    res.Add(new SimBlock(ci + i, cj + j));
                }
            }
        }

        return(res.ToArray());
    }
Ejemplo n.º 18
0
 public int GetDistance(SimBlock toward)
 {
     return(Mathf.Abs(m_i - toward.m_i) + Mathf.Abs(m_j - toward.m_j));
 }
Ejemplo n.º 19
0
 // Set and move to target block
 virtual public void SetBlock(SimBlock block)
 {
     TemBlock = BattleField.GetBlock(block);
 }
Ejemplo n.º 20
0
 public SimBlock[] GetAttackRangeInTarget(SimBlock target, Direction direction)
 {
     return(m_attack.GetAttackRange(target, direction, GetHeroInfo().AttackRange));
 }
Ejemplo n.º 21
0
 public virtual SimBlock[] GetMoveRange(SimBlock temBlock, Direction direction, int moveRange)
 {
     return(new SimBlock[0]);
 }
Ejemplo n.º 22
0
 static public Block GetBlock(SimBlock sb)
 {
     return(GetBlock(sb.m_i, sb.m_j));
 }
Ejemplo n.º 23
0
 public virtual Damage GetDamage(HeroInfo myInfo, SimBlock targetBlock)
 {
     return(new Damage(myInfo.Attack, myInfo.m_attackType, myInfo.parent, targetBlock));
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Get all the blocks within the attack range
 /// </summary>
 /// <returns>The attack range.</returns>
 /// <param name="temBlock">Tem block.</param>
 /// <param name="direction">Direction.</param>
 /// <param name="attackRange">Attack range.</param>
 public virtual SimBlock[] GetAttackRange(SimBlock temBlock, Direction direction, int attackRange)
 {
     return(new SimBlock[0]);
 }
Ejemplo n.º 25
0
    public static SimBlock GetReflectBlock(SimBlock block)
    {
        int width = Instance.gridWidth;

        return(new SimBlock(width - 1 - block.m_i, block.m_j));
    }
Ejemplo n.º 26
0
 public SimBlock(SimBlock sb)
 {
     m_i = sb.m_i;
     m_j = sb.m_j;
 }
Ejemplo n.º 27
0
 static bool IsBlockInRange(SimBlock b)
 {
     return((b.m_i >= 0) && (b.m_j >= 0) && (b.m_i < Instance.gridWidth) && (b.m_j < Instance.gridHeight));
 }
Ejemplo n.º 28
0
 public bool Equals(SimBlock sb)
 {
     return((m_i == sb.m_i) && (m_j == sb.m_j));
 }
Ejemplo n.º 29
0
	public override void OnBeforeBattle ()
	{
		base.OnBeforeBattle ();
		target = new SimBlock (parent.TemSimpleBlock);
	}
Ejemplo n.º 30
0
 /// <summary>
 /// Play the move animation
 /// </summary>
 /// <returns> the animation time</returns>
 /// <param name="block">Block.</param>
 public virtual float MoveTo(SimBlock block)
 {
     return(0);
 }