Exemplo n.º 1
0
        public override double Value()
        {
            double total = 1;

            if (Coord.Distance(Target, Oponent.GetCultCenter().Position) <
                Coord.Distance(AllyPos, Oponent.GetCultCenter().Position))
            {
                total += 2 * (1 + 1.0 / Coord.Distance(AllyPos, Oponent.GetCultCenter().Position));
            }

            ETerrain terrainAtTarget = Boards.TerrainAt(Target);

            foreach (ETerrain terrain in CurPlayer.GetPawnAt(AllyPos).PositiveTerrains)
            {
                if (terrainAtTarget == terrain)
                {
                    total += 1;
                    break;
                }
            }

            foreach (ABasicPawn enemy in Oponent.GetAttackers())
            {
                if (Coord.Distance(enemy.Position, CurPlayer.GetCultCenter().Position) < BoardConsts.MAX_COL / 2 &&
                    Coord.Distance(Target, enemy.Position) < Coord.Distance(AllyPos, enemy.Position))
                {
                    total += 3.0 * (1 + 1.0 / Coord.Distance(AllyPos, enemy.Position));
                }
            }

            return(total);
        }
Exemplo n.º 2
0
        public override bool Execute(bool isSimualtion = false)
        {
            bool valid = false;

            if (Validate())
            {
                APawn        allyPawn  = CurPlayer.GetPawnAt(AllyPos);
                Dijkstra     didi      = new Dijkstra(Boards.GetBoard(), AllyPos, allyPawn.MovePoints);
                List <Coord> moveRange = didi.GetValidPaths(Command.MOVE);
                if (moveRange.Contains(Target))
                {
                    valid = true;
                    allyPawn.Erase(Boards);
                    allyPawn.Position = Target;
                    allyPawn.Place(Boards);
                    allyPawn.Adapt(Boards.TerrainAt(AllyPos), Boards.TerrainAt(Target));
                }
                else
                {
                    ErrorMsg = OUT_OF_RANGE;
                }
            }
            if (!ErrorMsg.Equals("") && !isSimualtion)
            {
                UserUtils.PrintError(ErrorMsg);
                Console.ReadLine();
            }

            return(valid);
        }
Exemplo n.º 3
0
        protected override bool Validate()
        {
            bool valid = true;

            if (!Coord.IsValid(AllyPos) || !Coord.IsValid(Target))
            {
                ErrorMsg = INVALID_POS;
                valid    = false;
            }
            else if (CurPlayer == null)
            {
                ErrorMsg = PLAYER;
                valid    = false;
            }
            else if (CurPlayer.GetPawnAt(AllyPos) == null)
            {
                ErrorMsg = NO_PAWN;
                valid    = false;
            }
            else if (!Boards.CellAt(Target).Equals(BoardConsts.EMPTY))
            {
                ErrorMsg = OCCUPIED_CELL;
                valid    = false;
            }
            return(valid);
        }
Exemplo n.º 4
0
        public override bool IsValid()
        {
            bool valid = Validate();

            if (valid)
            {
                ABasicPawn   allyPawn = (ABasicPawn)CurPlayer.GetPawnAt(AllyPos);
                Dijkstra     didi     = new Dijkstra(Boards.GetBoard(), AllyPos, allyPawn.AtkRange);
                List <Coord> atkRange = didi.GetValidPaths(Command.ATTACK);
                valid = PosValidate(atkRange);
            }
            return(valid);
        }
Exemplo n.º 5
0
        protected override bool Validate()
        {
            bool valid = true;

            if (!Coord.IsValid(AllyPos) || !Coord.IsValid(Target))
            {
                ErrorMsg = INVALID_POS;
                valid    = false;
            }
            else if (Oponent == null)
            {
                ErrorMsg = NO_OPONENT;
                valid    = false;
            }
            else if (CurPlayer == null)
            {
                ErrorMsg = PLAYER;
                valid    = false;
            }
            else if (Boards == null)
            {
                ErrorMsg = NO_BOARDS;
                valid    = false;
            }
            else
            {
                APawn allyPawn = CurPlayer.GetPawnAt(AllyPos);
                if (allyPawn is ABasicPawn)
                {
                    ABasicPawn allyAttackerPawn = CurPlayer.GetPawnAt(AllyPos) as ABasicPawn;
                    if (allyPawn == null)
                    {
                        ErrorMsg = NO_PAWN;
                        valid    = false;
                    }
                    else if (Oponent.GetUnitAt(Target) == null)
                    {
                        ErrorMsg = NO_PAWN;
                        valid    = false;
                    }
                }
                else
                {
                    valid = false;
                }
            }
            return(valid);
        }
Exemplo n.º 6
0
        public override bool Execute(bool isSimulation = false)
        {
            bool valid = false;

            if (Validate())
            {
                ABasicPawn   allyPawn = (ABasicPawn)CurPlayer.GetPawnAt(AllyPos);
                Dijkstra     didi     = new Dijkstra(Boards.GetBoard(), AllyPos, allyPawn.AtkRange);
                List <Coord> atkRange = didi.GetValidPaths(Command.ATTACK);
                if (PosValidate(atkRange))
                {
                    valid = true;
                    Unit enemyUnit = Oponent.GetUnitAt(Target);
                    int  damage    = allyPawn.Atk - enemyUnit.Def;
                    if (damage > 0)
                    {
                        HitMsg             = String.Format("{0} HAVE DEALT {1} DAMAGE!", allyPawn.Culture, damage);
                        enemyUnit.CurrLife = enemyUnit.CurrLife - damage;
                        if (enemyUnit.CurrLife <= 0)
                        {
                            Oponent.RemoveUnitAt(Target, Boards);
                            HitMsg += " ENEMY KILLED!!";
                        }
                    }
                    else
                    {
                        HitMsg = BLOCK;
                    }
                }
            }
            //if (!isSimulation) {
            //    UserUtils.PrintSucess((valid) ? (HitMsg) : (ErrorMsg));
            //    Console.ReadLine();
            //}
            return(valid);
        }