Ejemplo n.º 1
0
        protected Player(PlayerNumber PN, PlayerType PT, BoardState Board)
        {
            playerNumber = PN;
            playerType   = PT;
            //balance can be changed for testing and balancing
            balance = 4;

            //homeBase = new Base();
            if (playerNumber == PlayerNumber.Player1)
            {
                BaseX = (Board.BoardSizeX) / 2;
                BaseY = Board.BoardSizeY - 2;
            }
            else
            {
                BaseX = (Board.BoardSizeX) / 2;
                BaseY = 1;
            }
            Coordinate ThisCo = new Coordinate(BaseX, BaseY);

            new Base(this, Board.getSquare(ThisCo), 20);
            for (uint y = BaseY - 1; y < BaseY + 2; y++)
            {
                for (uint x = BaseX - 1; x < BaseX + 2; x++)
                {
                    ThisCo.X = x;
                    ThisCo.Y = y;
                    Board.getSquare(ThisCo).Owner = this;
                }
            }
        }
Ejemplo n.º 2
0
        public bool Action(Coordinate From, Coordinate Check, Player MyPlayer, BoardState board)
        {
            //the bool output lets the caller know if the unit moved
            bool   Moved    = false;
            String CheckDep = board.getSquare(Check).Dep.DepType;
            Player Owner    = board.getSquare(Check).Dep.OwnedBy;

            if (((CheckDep == "Empty") || (CheckDep == "Barracks") && Owner == MyPlayer))
            {
                //drag or destroys a friendly barracks
                if (board.getSquare(From).Dep.MP > 0)
                {
                    board.getSquare(From).Dep.MP--;
                    Drag(new Coordinate(From.X, From.Y), new Coordinate(Check.X, Check.Y), MyPlayer, board);
                    Moved = true;
                }
            }
            else if ((CheckDep == "Unit" || CheckDep == "Barracks" || CheckDep == "Base") && (Owner != MyPlayer))
            {
                Attack(From, Check, MyPlayer, board);
            }

            //TerritoryDeaths();
            //BaseSquares();
            return(Moved);
        }
Ejemplo n.º 3
0
        public void ReplaceState(BoardState NewBoard)
        {
            this.boardSize.X = NewBoard.BoardSizeX;
            this.boardSize.Y = NewBoard.BoardSizeY;
            this.player1     = new Human(NewBoard.Player1);
            m_BoardState     = new Square[NewBoard.BoardSizeX, NewBoard.BoardSizeY];
            Coordinate Here = new Coordinate();

            if (NewBoard.Player2.GetPlayerType == "Human")
            {
                this.player2 = new Human(NewBoard.Player2);
                for (uint y = 0; y < NewBoard.BoardSizeY; y++)
                {
                    for (uint x = 0; x < NewBoard.BoardSizeX; x++)
                    {
                        Here.Y             = y;
                        Here.X             = x;
                        m_BoardState[x, y] = new Square(NewBoard.getSquare(Here), (Human)this.player1, (Human)this.player2);
                    }
                }
            }
            else
            {
                this.player2 = new Computer((Computer)NewBoard.Player2);
                for (uint y = 0; y < NewBoard.BoardSizeY; y++)
                {
                    for (uint x = 0; x < NewBoard.BoardSizeX; x++)
                    {
                        Here.Y             = y;
                        Here.X             = x;
                        m_BoardState[x, y] = new Square(NewBoard.getSquare(Here), (Human)this.player1, (Computer)this.player2);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public bool Attack(Coordinate From, Coordinate Check, Player MyPlayer, BoardState board)
        {
            //returns true if this unit dies
            bool Died = false;

            //attack
            //adjust health and then if the attacking unit won, use the drag function
            //i dont know if i want to use the drag function on an attack. i will wait until i test it to decide
            //i dont have to redefine these squares but i think it helps the code read better
            Square Attacker = board.getSquare(From);
            Square Defender = board.getSquare(Check);
            String CheckDep = board.getSquare(Check).Dep.DepType;
            Player Owner    = board.getSquare(Check).Dep.OwnedBy;

            //attacker must be more than 1 turn old in order to attack
            if (Attacker.Dep.JustCreated == false)
            {
                //checks who wins the combat: attacker or defender
                //attacker wins
                if (Attacker.Dep.Health > Defender.Dep.Health)
                {
                    Attacker.Dep.Health -= Defender.Dep.Health;
                    //Barracks are a special case
                    if (CheckDep == "Barracks")
                    {
                        board.getSquare(Check).Dep   = new Barracks(MyPlayer, board.getSquare(Check), 5);
                        board.getSquare(Check).Owner = MyPlayer;
                    }
                    else
                    {
                        Defender.Dep = new Empty();
                    }
                }
                //defender wins
                else if (Attacker.Dep.Health < Defender.Dep.Health)
                {
                    Defender.Dep.Health -= Attacker.Dep.Health;
                    Attacker.Dep         = new Empty();
                    //Cursor.Instance.CursorMode = Cursor.Mode.free;
                    Died = true;
                }
                //both have equal health
                else
                {
                    if (CheckDep == "Barracks")
                    {
                        board.getSquare(Check).Dep   = new Barracks(MyPlayer, board.getSquare(Check), 5);
                        board.getSquare(Check).Owner = MyPlayer;
                    }
                    else
                    {
                        Defender.Dep = new Empty();
                    }
                    Attacker.Dep = new Empty();
                    //Cursor.Instance.CursorMode = Cursor.Mode.free;
                    Died = true;
                }
            }
            return(Died);
        }
Ejemplo n.º 5
0
        //BoardState
        public BoardState(BoardState CurrentBoard)
        {
            this.boardSize.X = CurrentBoard.BoardSizeX;
            this.boardSize.Y = CurrentBoard.BoardSizeY;
            this.player1     = new Human(CurrentBoard.Player1);
            m_BoardState     = new Square[CurrentBoard.BoardSizeX, CurrentBoard.BoardSizeY];
            Coordinate Here = new Coordinate();

            if (CurrentBoard.Player2.GetPlayerType == "Human")
            {
                this.player2 = new Human(CurrentBoard.Player2);
                for (uint y = 0; y < CurrentBoard.BoardSizeY; y++)
                {
                    for (uint x = 0; x < CurrentBoard.BoardSizeX; x++)
                    {
                        Here.Y             = y;
                        Here.X             = x;
                        m_BoardState[x, y] = new Square(CurrentBoard.getSquare(Here), (Human)this.player1, (Human)this.player2);
                    }
                }
            }
            else
            {
                this.player2 = new Computer((Computer)CurrentBoard.Player2);
                for (uint y = 0; y < CurrentBoard.BoardSizeY; y++)
                {
                    for (uint x = 0; x < CurrentBoard.BoardSizeX; x++)
                    {
                        Here.Y             = y;
                        Here.X             = x;
                        m_BoardState[x, y] = new Square(CurrentBoard.getSquare(Here), (Human)this.player1, (Computer)this.player2);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        //this may not need to be void however i dont yet know if or what the output will be (currently just counts)
        public void SweepSearch(StishMiniMaxNode Sibling, BoardState Now, Coordinate UnitPos, Player Side)
        {
            Coordinate Upper = new Coordinate();
            Coordinate Lower = new Coordinate();
            Coordinate Look  = new Coordinate();

            //upper refers to the upper left corner (lower coordinate values)
            //assigns full values to the bounds and then changes them if they are inappropriate
            Upper.X = UnitPos.X - StishBoard.Instance.GameMP;
            Upper.Y = UnitPos.Y - StishBoard.Instance.GameMP;
            Lower.X = UnitPos.X + StishBoard.Instance.GameMP;
            Lower.Y = UnitPos.Y + StishBoard.Instance.GameMP;

            //checks if the unit is losing movement positions because it is too close to the edge of the board
            if (UnitPos.X < StishBoard.Instance.GameMP)
            {
                Upper.X = 0;
            }
            if (UnitPos.X > Now.BoardSizeX - StishBoard.Instance.GameMP)
            {
                Lower.X = Now.BoardSizeX;
            }
            if (UnitPos.Y < StishBoard.Instance.GameMP)
            {
                Upper.Y = 0;
            }
            if (UnitPos.Y > Now.BoardSizeY - StishBoard.Instance.GameMP)
            {
                Lower.Y = Now.BoardSizeY;
            }

            for (uint y = Upper.Y; y <= Lower.Y; y++)
            {
                for (uint x = Upper.X; x <= Lower.X; x++)
                {
                    Look.X = x;
                    Look.Y = y;
                    //stishboard.instance is okay here as this variable is global and is not dependant on a particular state
                    if (UnitPos.Get2DDistance(Look) <= StishBoard.Instance.GameMP)
                    {
                        //general squares around unit within range
                        if ((Now.getSquare(Look) != null) && !((Now.getSquare(Look).Owner) == Side && ((Now.getSquare(Look).Dep.DepType == "Unit") || (Now.getSquare(Look).Dep.DepType == "Base"))))
                        {
                            //the unit can legally move to any of these positions however the events of this action are not distinguished
                            //obstructions are not accounted for
                            List <Coordinate> Path = FindPath(UnitPos, Look, Now);
                            if (Path != null)
                            {
                                UnitBasedMovement(Sibling, Now, Path, Side);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 7
0
        private void Drag(Coordinate FromCo, Coordinate ToCo, Player MyPlayer, BoardState board)
        {
            Square From = board.getSquare(FromCo);
            Square To   = board.getSquare(ToCo);

            From.Owner = MyPlayer;
            To.Owner   = MyPlayer;

            To.Dep   = From.Dep;
            From.Dep = new Empty();
        }
Ejemplo n.º 8
0
 private void TestSquare(StishMiniMaxNode Sibling, BoardState Now, Player Side, Coordinate Invest, uint cost)
 {
     if ((Now.getSquare(Invest).Owner == Side) && (Now.getSquare(Invest).Dep.DepType == "Empty"))
     {
         //can buy possibly buy
         BuyPossibility(Sibling, Now, Side, Invest, cost);
     }
     if ((Now.getSquare(Invest).Owner == Side) && (Now.getSquare(Invest).Dep.DepType == "Unit"))
     {
         //sweeps through all possible unit moves
         SweepSearch(Sibling, Now, Invest, Side);
     }
 }
Ejemplo n.º 9
0
        public List <Coordinate> TrainPath(BoardState board, Coordinate UnitPos, Coordinate Twitch, uint MoveCost, uint MoveHealth, Player Cont, List <PathNode> ToCheck, List <PathNode> Checked, List <Coordinate> Path)
        {
            uint PersonalMoveCost   = MoveCost + 1;
            uint PersonalMoveHealth = MoveHealth;

            if ((board.getSquare(Twitch).Dep.OwnedBy != Cont) && (board.getSquare(Twitch).Dep.DepType == "Unit" || board.getSquare(Twitch).Dep.DepType == "Barracks" || board.getSquare(Twitch).Dep.DepType == "Base"))
            {
                //if an enemy dep type that can remove health
                //this prevents underflow errors as Health is a Uint
                if (PersonalMoveHealth >= board.getSquare(Twitch).Dep.Health)
                {
                    PersonalMoveHealth -= board.getSquare(Twitch).Dep.Health;
                }
                else
                {
                    PersonalMoveHealth = 0;
                }
            }

            //parameter for being a path member in the if statement
            //within range (an allowed cost) and positive health. if drops under zero it will overflow.
            if ((PersonalMoveCost <= StishBoard.Instance.GameMP) && ((PersonalMoveHealth <= board.getSquare(UnitPos).Dep.Health) && (PersonalMoveHealth != 0)))
            {
                //suitable to be created as a new node but not checked for suitability for the list system
                PathNode NodeToTest = new PathNode(null, PersonalMoveCost, PersonalMoveHealth, board, Twitch);

                if (SearchForPathNode(NodeToTest, Checked) == false)
                {
                    Coordinate SolidPos = new Coordinate(Twitch);
                    //comment below is no longer true but the changes are possible
                    //not already searched. note, this method allows there to be more than one node per square as long as the path is not 'essentially the same' which is a nice unintended consequence of this method.
                    //PathNode TestedNode = CreatePathNode(ToCheck, ToCheck[0], PersonalMoveCost, PersonalMoveHealth, board, SolidPos);

                    PathNode TestedNode = CreatePathNode(ToCheck, ToCheck[0], PersonalMoveCost, PersonalMoveHealth, board, SolidPos);
                    //is this the destination?
                    if ((Twitch.X == UnitPos.X) && (Twitch.Y == UnitPos.Y))
                    {
                        //recursion to create a list of PathNode Parents
                        Path = FollowParents(TestedNode);
                        //returns a list of coordinates 'UnitPos --> To' for each individual step
                        ToCheck[0].RemoveChild(TestedNode);

                        return(Path);
                    }
                }
            }

            //nothing of interest
            return(null);
        }
Ejemplo n.º 10
0
        public bool BuyUnit(Coordinate Pur, Player ConPlayer, BoardState board)
        {
            bool bought = false;

            if ((board.getSquare(Pur) != null) && (board.getSquare(Pur).Dep.DepType == "Empty") && (board.getSquare(Pur).Owner == ConPlayer))
            {
                //spend the entire player balance
                if (ConPlayer.Balance > 0)
                {
                    board.getSquare(Pur).Dep = new Unit(board.getSquare(Pur).Owner, board.getSquare(Pur), ConPlayer.Balance);
                    ConPlayer.Balance        = 0;
                    bought = true;
                }
            }
            return(bought);
        }
Ejemplo n.º 11
0
        public void TurnBalance(BoardState Board)
        {
            Coordinate ThisCo = new Coordinate();

            for (uint y = 0; y < Board.BoardSizeY; y++)
            {
                for (uint x = 0; x < Board.BoardSizeX; x++)
                {
                    ThisCo.X = x;
                    ThisCo.Y = y;
                    if ((Board.getSquare(ThisCo).Dep.DepType == "Barracks" || Board.getSquare(ThisCo).Dep.DepType == "Base") && Board.getSquare(ThisCo).Owner == this)
                    {
                        this.Balance++;
                    }
                }
            }
        }
Ejemplo n.º 12
0
        public bool BuyBarracks(Coordinate Pur, Player ConPlayer, BoardState board)
        {
            bool bought = false;

            if ((board.getSquare(Pur) != null) && (board.getSquare(Pur).Dep.DepType == "Empty") && (board.getSquare(Pur).Owner == ConPlayer))
            {
                //check how many barracks the player already has and multiply it buy the cost of one barracks
                uint       multiply = 0;
                Coordinate See      = new Coordinate();

                for (uint y = 0; y < board.BoardSizeY; y++)
                {
                    for (uint x = 0; x < board.BoardSizeX; x++)
                    {
                        See.X = x;
                        See.Y = y;
                        if ((board.getSquare(See).Dep.DepType == "Barracks" || board.getSquare(See).Dep.DepType == "Base") && board.getSquare(See).Dep.OwnedBy == ConPlayer)
                        {
                            multiply++;
                        }
                    }
                }

                if (ConPlayer.Balance >= 3 * multiply)
                {
                    board.getSquare(Pur).Dep = new Barracks(board.getSquare(Pur).Owner, board.getSquare(Pur), 5);
                    ConPlayer.Balance       -= 3 * multiply;
                    bought = true;
                }
            }
            return(bought);
        }
Ejemplo n.º 13
0
        public uint BarracksCost(BoardState Now, Player Side)
        {
            //finds if the player can afford a barracks
            uint multiply = 1;

            Coordinate look = new Coordinate();

            for (uint y = 0; y < Now.BoardSizeY; y++)
            {
                for (uint x = 0; x < Now.BoardSizeX; x++)
                {
                    look.X = x;
                    look.Y = y;

                    if ((Now.getSquare(look).Owner == Side) && (Now.getSquare(look).Dep.DepType == "Barracks"))
                    {
                        multiply++;
                    }
                }
            }
            return(3 * multiply);
        }
Ejemplo n.º 14
0
 //coordinates are uints so anything less than 0 will overflow
 public bool OnBoard(Coordinate num, BoardState board)
 {
     try
     {
         Square Check = board.getSquare(num);
         if (Check != null)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch
     {
         return(false);
     }
 }
Ejemplo n.º 15
0
        public void MaxMP(BoardState Board)
        {
            //this fuction is run at the start of a turn and sets all units that belong to this player to the max MP.
            Coordinate ThisCo = new Coordinate();

            for (uint y = 0; y < Board.BoardSizeY; y++)
            {
                for (uint x = 0; x < Board.BoardSizeX; x++)
                {
                    ThisCo.X = x;
                    ThisCo.Y = y;
                    Square ThisSquare = Board.getSquare(ThisCo);
                    if ((ThisSquare.Owner == this) && (ThisSquare.Dep.DepType == "Unit"))
                    {
                        //This number is subject to change throughout testing and balancing
                        ThisSquare.Dep.MP          = StishBoard.Instance.GameMP;
                        ThisSquare.Dep.JustCreated = false;
                    }
                }
            }
        }
Ejemplo n.º 16
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);
        }