Ejemplo n.º 1
0
 public Human(PlayerNumber PN, PlayerType PT, BoardState Board) :  base(PN, PT, Board)
 {
 }
Ejemplo n.º 2
0
 public Computer(PlayerNumber PN, PlayerType PT, BoardState Board) : base(PN, PT, Board)
 {
 }
Ejemplo n.º 3
0
        public void BuyPossibility(StishMiniMaxNode Sibling, BoardState Now, Player Side, Coordinate look, uint cost)
        {
            if (Side.Balance > 0)
            {
                //can afford a unit

                BoardState UnitBoardState = new BoardState(Now);
                if (Side.GetPlayerNum == "Player1")
                {
                    GameMaster.Instance.BuyUnit(look, UnitBoardState.Player1, UnitBoardState);
                }
                else
                {
                    GameMaster.Instance.BuyUnit(look, UnitBoardState.Player2, UnitBoardState);
                }

                /*
                 * if (Side.GetPlayerNum == "Player1")
                 * {
                 *  //opposite allegiance to it's parent
                 *  PlayersTurn = UnitBoardState.Player2;
                 * }
                 * else
                 * {
                 *  PlayersTurn = UnitBoardState.Player1;
                 * }
                 */

                //Parent.Parent as "parent" is actually just an updated model of the "real" parent where no actions were taken
                StishMiniMaxNode UnitCaseNode = new StishMiniMaxNode(Sibling.Parent, Sibling.Allegiance, UnitBoardState);
                PredctionCount();
            }
            if (Side.Balance >= cost)
            {
                //can afford a barracks

                BoardState BarracksBoardState = new BoardState(Now);
                if (Side.GetPlayerNum == "Player1")
                {
                    GameMaster.Instance.BuyBarracks(look, BarracksBoardState.Player1, BarracksBoardState);
                }
                else
                {
                    GameMaster.Instance.BuyBarracks(look, BarracksBoardState.Player2, BarracksBoardState);
                }

                /*
                 * if (Side.GetPlayerNum == "Player1")
                 * {
                 *  //opposite allegiance to it's parent
                 *  PlayersTurn = BarracksBoardState.Player2;
                 * }
                 * else
                 * {
                 *  PlayersTurn = BarracksBoardState.Player1;
                 * }
                 */

                //Parent.Parent as "parent" is actually just an updated model of the "real" parent where no actions were taken
                StishMiniMaxNode BarracksCaseNode = new StishMiniMaxNode(Sibling.Parent, Sibling.Allegiance, BarracksBoardState);
                PredctionCount();
            }
        }
Ejemplo n.º 4
0
        public PathNode CreatePathNode(List <PathNode> ToCheck, PathNode Parent, uint Cost, uint Health, BoardState World, Coordinate Invest)
        {
            PathNode Generate = new PathNode(Parent, Cost, Health, World, Invest);

            ToCheck.Add(Generate);
            return(Generate);
        }
Ejemplo n.º 5
0
        //not void! returns a list of Pathnodes
        public List <Coordinate> FindPath(Coordinate UnitPos, Coordinate To, BoardState board)
        {
            //lists as we dont want a limit that would be given by an array
            List <Coordinate> Path    = new List <Coordinate>();
            List <PathNode>   ToCheck = new List <PathNode>();
            List <PathNode>   Checked = new List <PathNode>();
            Coordinate        Invest  = new Coordinate();
            Coordinate        Twitch  = new Coordinate();
            uint   MoveCost;
            uint   MoveHealth = board.getSquare(UnitPos).Dep.Health;
            Player Cont       = board.getSquare(UnitPos).Dep.OwnedBy;

            //MoveHealth must remain above 0 and MoveCost must remain below the maximum unit move distance

            //Start at To and end at UnitPos
            Invest.X = To.X;
            Invest.Y = To.Y;
            MoveCost = 0;

            //has to be cast here as the parent has to be given as null
            //adds this node to the list ToCheck
            CreatePathNode(ToCheck, null, MoveCost, MoveHealth, board, Invest);

            //Spreading from Invest
            while (ToCheck.Count != 0)
            {
                for (int dir = 0; dir < 4; dir++)
                {
                    Invest     = ToCheck[0].Position;
                    MoveCost   = ToCheck[0].Cost;
                    MoveHealth = ToCheck[0].Health;

                    Twitch.X = Invest.X;
                    Twitch.Y = Invest.Y;

                    if (dir == 0)
                    {
                        //up
                        Twitch.MoveUp();
                    }
                    else if (dir == 1)
                    {
                        //right
                        Twitch.MoveRight();
                    }
                    else if (dir == 2)
                    {
                        //down
                        Twitch.MoveDown();
                    }
                    else if (dir == 3)
                    {
                        //left
                        Twitch.MoveLeft();
                    }

                    if (board.getSquare(Twitch) != null)
                    {
                        //the 2d distance this way around makes a lot of sense and is nicely restricting
                        if (UnitPos.Get2DDistance(Twitch) <= StishBoard.Instance.GameMP)
                        {
                            //tests to see if twitch is ontop of a friendly deployment but gives an exception for the destination which is the moving unit
                            if (((Twitch.X == UnitPos.X) && (Twitch.Y == UnitPos.Y)) || !(board.getSquare(Twitch).Owner == board.getSquare(UnitPos).Owner&& board.getSquare(Twitch).Dep.DepType != "Empty"))
                            {
                                Coordinate SolidPos = new Coordinate(Twitch);
                                //make changes to Movecost and MoveHealth here
                                //trained equals true if this node is suitable and lands at the destination
                                List <Coordinate> Trained = TrainPath(board, UnitPos, SolidPos, MoveCost, MoveHealth, Cont, ToCheck, Checked, Path);
                                if (Trained != null)
                                {
                                    return(Trained);
                                }
                            }
                        }
                    }
                }

                Checked.Add(ToCheck[0]);
                ToCheck.Remove(ToCheck[0]);
            }
            //there is no connection
            return(null);
        }