Esempio n. 1
0
        public void SetRandomDestination(HackGameBoard board)
        {
            Point current = this.getCurrentBoardLocation();
            Point dest = current;

            //get all "nodes"
            List<Point> allNodes = new List<Point>();
            for (int i = 0; i < board.GetGameBoardSize(); i++)
            {
                for (int k = 0; k < board.GetGameBoardSize(); k++)
                {
                    if (board.board[i, k].type == HackGameBoardElementBaseType.HackGameBoardElementBaseType_Node &&
                        board.board[i, k].GetCurrentState() == HackGameBoardElement.HackGameBoardElement_State.HackGameBoardElement_State_Active)
                    {
                        allNodes.Add(new Point(k, i));
                    }
                }
            }

            if (allNodes.Count > 0)
            {
                TryDestination(allNodes[board.r.Next(0, allNodes.Count)], board);

                if (nextBoardElementDestinations.Count > maxThinkAheadLength)
                {
                    //shorten to maxThinkAheadLength
                    List<Point> rev = new List<Point>();
                    while (nextBoardElementDestinations.Count > 0)
                    {
                        rev.Add(nextBoardElementDestinations.Pop());
                    }

                    rev.Reverse();
                    rev.RemoveRange(0, rev.Count - maxThinkAheadLength);

                    while (board.GetElementAtPoint(rev[0]).type != HackGameBoardElementBaseType.HackGameBoardElementBaseType_Node && rev.Count > 0)
                    {
                        rev.RemoveAt(0);
                    }

                    if (rev.Count <= 0)
                    {
                        // uh oh. we were too aggressive.
                        //reset.
                        TryDestination(allNodes[board.r.Next(0, allNodes.Count)], board);
                    }

                    else
                    {
                        foreach (Point p in rev)
                        {
                            nextBoardElementDestinations.Push(p);
                        }
                    }
                }
            }
            else
            {
                Kill(0);
            }
        }
Esempio n. 2
0
        public void SetInitialRandom(HackGameBoard board, HackGameAgent_Player player)
        {
            //get all "nodes"
            List<Point> allNodes = new List<Point>();
            for (int i = 0; i < board.GetGameBoardSize(); i++)
            {
                for (int k = 0; k < board.GetGameBoardSize(); k++)
                {
                    if (board.board[i, k].type == HackGameBoardElementBaseType.HackGameBoardElementBaseType_Node &&
                        board.board[i, k].GetCurrentState() == HackGameBoardElement.HackGameBoardElement_State.HackGameBoardElement_State_Active)
                    {
                        if (player.getCurrentBoardLocation() != new Point(k, i))
                        {
                            allNodes.Add(new Point(k, i));
                        }
                    }
                }
            }

            if (allNodes.Count > 0)
            {
                Point newCur = allNodes[board.r.Next(0, allNodes.Count)];
                setCurrentBoardLocation(newCur, board);
            }
            else
            {
                Kill(0);
            }
        }
Esempio n. 3
0
 public bool setDestinationBoardLocation(Point location, HackGameBoard board)
 {
     if (location.X > board.GetGameBoardSize() || location.Y > board.GetGameBoardSize() || location.X < 0 || location.Y < 0)
     {
         return false;
     }
     else
     {
         justLeavingNode = currentBoardElementDestination;
         justLeaving = true;
         this.currentBoardElementDestination = location;
         this.t = 0;
         return true;
     }
 }