Exemple #1
0
    public static void MarkTileAsSearched(SearchTile searchTile)
    {
        bool allSearched = true;

        foreach (Tile tile in zone.tiles)
        {
            if (tile.GetID() == searchTile.id)
            {
                if (!tile.IsSearched())
                {
                    numberOfTilesSearched++;
                }

                tile.SetAsSearched();
            }
            if (!tile.IsSearched())
            {
                allSearched = false;
            }
        }

        if (allSearched)
        {
            //WorldStateManager.EndTrial ();
            taskCompleted = true;
        }
    }
Exemple #2
0
    public SearchTile GetNextBestTile(Vector3 currentPosition, ArrayList updates)
    {
        SearchTile bestTile   = null;
        float      highestBid = float.MinValue;

        foreach (SearchTile tile in tilesInAuction)
        {
            float gj = BidEvaluation(currentPosition, tile.center, updates);
            if (!IsStillBestTile(bestTile, highestBid, tile, gj))
            {
                bestTile   = tile;
                highestBid = gj;
            }
        }

        foreach (SearchTile tile in openTiles)
        {
            float gj = BidEvaluation(currentPosition, tile.center, updates);
            if (!IsStillBestTile(bestTile, highestBid, tile, gj))
            {
                bestTile   = tile;
                highestBid = gj;
            }
        }

        return(bestTile);
    }
Exemple #3
0
    public void RecvSearchedMessage(int srcId, int searchTileId)
    {
        SearchTile tile = this.FindTileWithId(this.claimedTiles, searchTileId);

        if (tile != null)
        {
            // if (!WorldStateManager.IsSearched (tile)) { Debug.Log ("ERROR : Received Search Message for something that the World State hasn't had searched yet... But you think is claimed"); }
            tile.SetAsSearched();
            this.MoveTile(tile, this.claimedTiles, this.searchedTiles);
            return;
        }

        tile = this.FindTileWithId(this.tilesInAuction, searchTileId);
        if (tile != null)
        {
            // if (!WorldStateManager.IsSearched (tile)) { Debug.Log ("ERROR : Received Search Message for something that the World State hasn't had searched yet... But you think is in auction"); }
            tile.SetAsSearched();
            this.MoveTile(tile, this.tilesInAuction, this.searchedTiles);
            return;
        }

        tile = this.FindTileWithId(this.openTiles, searchTileId);
        if (tile != null)
        {
            // if (!WorldStateManager.IsSearched (tile)) { Debug.Log ("ERROR : Received Search Message for something that the World State hasn't had searched yet... But you think is open"); }
            tile.SetAsSearched();
            this.MoveTile(tile, this.openTiles, this.searchedTiles);
            return;
        }
    }
Exemple #4
0
 //TODO: convert all lists to arrays by index to improve performance
 public void CleanUp()
 {
     sender.CleanUp();
     sender       = null;
     canidateBid  = null;
     canidateTile = null;
     kb           = null;
     foreach (SearchTile s in openTiles)
     {
         s.CleanUp();
     }
     openTiles.Clear();
     openTiles = null;
     foreach (SearchTile s in tilesInAuction)
     {
         s.CleanUp();
     }
     tilesInAuction.Clear();
     tilesInAuction = null;
     foreach (SearchTile s in claimedTiles)
     {
         s.CleanUp();
     }
     claimedTiles.Clear();
     claimedTiles = null;
     foreach (SearchTile s in searchedTiles)
     {
         s.CleanUp();
     }
     searchedTiles.Clear();
     searchedTiles = null;
 }
Exemple #5
0
 public static void MarkTileAsOpen(SearchTile searchTile)
 {
     foreach (Tile tile in zone.tiles)
     {
         if (tile.GetID() == searchTile.id)
         {
             tile.SetAsOpen();
         }
     }
 }
Exemple #6
0
 private bool MoveTile(SearchTile tile, ArrayList src, ArrayList dst)
 {
     if (src.Contains(tile))
     {
         dst.Add(tile);
         src.Remove(tile);
         return(true);
     }
     // Debug.Log ("ERROR | Trying to remove a tile not found.");
     return(false);
 }
Exemple #7
0
 public static bool IsSearched(SearchTile searchTile)
 {
     foreach (Tile tile in zone.tiles)
     {
         if (tile.GetID() == searchTile.id)
         {
             return(tile.IsSearched());
         }
     }
     // Debug.Log("ERROR | Cannot find world tile.");
     return(false);
 }
Exemple #8
0
    public override double GetCostValue()
    {
        float      distToGoal = 0;
        SearchTile goal       = this.kb.GetCurrentGoal();

        if (goal != null)
        {
            distToGoal = Vector3.Distance(desiredPosition, goal.center);
        }

        float cost = 2.0f * Mathf.Atan(distToGoal / MAX_PENALTY_DISTANCE) / Mathf.PI;

        return(Mathf.Min(cost, 1));
    }
Exemple #9
0
 public void MarkTileAsSearched(SearchTile tile)
 {
     tile.SetAsSearched();
     if (this.claimedTiles.Contains(tile))
     {
         this.MoveTile(tile, this.claimedTiles, this.searchedTiles);
     }
     else if (this.tilesInAuction.Contains(tile))
     {
         this.MoveTile(tile, this.tilesInAuction, this.searchedTiles);
     }
     else if (this.openTiles.Contains(tile))
     {
         this.MoveTile(tile, this.openTiles, this.searchedTiles);
     }
 }
Exemple #10
0
 public static void MarkTileAsClaimed(SearchTile searchTile)
 {
     foreach (Tile tile in zone.tiles)
     {
         if (tile.GetID() == searchTile.id)
         {
             if (tile.IsSearched())
             {
                 // Debug.Log("DEBUG | TRYING TO CLAIM A SEARCHED TILE");
                 return;
             }
             // if(tile.IsClaimed ()) { Debug.Log("ERROR: Trying to claim an already claimed tile"); }
             tile.SetAsClaimed();
         }
     }
 }
Exemple #11
0
    public void AddBidForTile(int searchTileId, SearchTileBid bid)
    {
        /* Search for the tile in the set that is currently in auction */
        foreach (SearchTile tile in tilesInAuction)
        {
            if (searchTileId == tile.id)
            {
                // WorldStateManager.MarkTileAsHasBid (this);
                tile.AddBid(bid, this.myId == bid.agentId);
                return;
            }
        }
        /* This is the first bid for the tile */
        foreach (SearchTile tile in openTiles)
        {
            if (searchTileId == tile.id)
            {
                this.MoveTile(tile, this.openTiles, this.tilesInAuction);
                tile.AddBid(bid, this.myId == bid.agentId);
                WorldStateManager.MarkTileAsHasBid(tile);
                return;
            }
        }
        // If we can't find the tile, it's been claimed or searched
        SearchTile searchTile = this.FindTileWithId(this.claimedTiles, searchTileId);

        // If it's found as a claimed tile
        if (searchTile != null)
        {
            // Debug.Log("Agent " + this.myId + "  got a bid for a claimed tile");
            // Send a claimed message giving the agents belived state
            sender.SendClaimed(searchTile.id, searchTile.acceptedBid.agentId, searchTile.acceptedBid.value);
            return;
        }

        // Otherwise, the tile has been searched. Send searched message.
        searchTile = this.FindTileWithId(this.searchedTiles, searchTileId);
        if (searchTile != null)
        {
            // Debug.Log("Agent " + this.myId + "  got a bid for a searched tile");
            sender.SendSearched(searchTile.id);
            return;
        }
        // Debug.Log("ERROR -> Adding bid for tile that does not exist.");
    }
Exemple #12
0
 public static void MarkTileAsHasBid(SearchTile searchTile)
 {
     foreach (Tile tile in zone.tiles)
     {
         if (tile.GetID() == searchTile.id)
         {
             if (tile.IsSearched())
             {
                 // Debug.Log("DEBUG | Trying to bid on an already searched tile");
                 return;
             }
             else if (tile.IsClaimed())
             {
                 // Debug.Log("DEBUG | Trying to bid on an already claimed tile");
             }
             tile.SetAsHasBid();
         }
     }
 }
Exemple #13
0
 private bool IsStillBestTile(SearchTile bestTile, float highestBid, SearchTile tile, float gj)
 {
     if (bestTile == null)
     {
         return(false);
     }
     if (gj >= highestBid)
     {
         if (tile.GetState() == SearchTile.TileState.OPEN)
         {
             return(false);
         }
         else
         {
             if ((new SearchTileBid(this.myId, gj)).IsBetterThan(tile.GetHighestBid()))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Exemple #14
0
    private void SendBidForNextBestTile()
    {
        SearchTile tile = this.GetNextBestTile(this.kb.agent.sensorModule.gps.position, this.kb.updates);

        // Check if there are any tiles left to be claimed
        if (tile == null)
        {
            //isDone = true;
//			Debug.Log ("No more tiles to bid on");
//			if (this.IsMapSearched () ) { Debug.Log ("Agent "+this.kb.agent.ID+" thinks the map is searched"); }
            this.ResetCandidateAndGoalTile();
            return;
        }
        this.ResetCandidateAndGoalTile();
        this.kb.SetTempGoal(tile);
        this.canidateTile = tile;
        int   tileId    = canidateTile.id;
        float bidAmount = this.BidEvaluation(this.kb.agent.sensorModule.gps.position, this.canidateTile.center, this.kb.updates);

        this.canidateBid = new SearchTileBid(this.kb.agent.ID, bidAmount);
        this.AddBidForTile(tileId, this.canidateBid);
        this.sender.SendBid(tileId, bidAmount);
//		Debug.Log (this.kb.agent.ID + " Just Sent a bid");
    }
Exemple #15
0
    private void SendBidForNextBestTile()
    {
        SearchTile tile = this.bidKnowledge.GetNextBestTile(agent.sensorModule.gps.position, this.updates);

        // Check if there are any tiles left to be claimed
        if (tile == null)
        {
            //isDone = true;
            // if (this.bidKnowledge.IsMapSearched () ) { Debug.Log ("Agent "+this.agent.ID+" thinks the map is searched"); }
            this.bidKnowledge.ResetCandidateAndGoalTile();
            return;
        }
        this.ResetGoalTile();
        this.tempGoal = tile;
        this.bidKnowledge.SetCandidateTile(tile);
        int   tileId    = tile.id;
        float bidAmount = this.bidKnowledge.BidEvaluation(agent.sensorModule.gps.position, tile.center, this.updates);

        SearchTileBid canidateBid = new SearchTileBid(this.agent.ID, bidAmount);

        this.bidKnowledge.SetCandidateBid(canidateBid);
        this.bidKnowledge.AddBidForTile(tileId, canidateBid);
        this.sender.SendBid(tileId, bidAmount);
    }
Exemple #16
0
 public void CleanUp()
 {
     agent = null;
     incoming.Clear();
     incoming = null;
     foreach (AgentUpdate a in updates)
     {
         a.CleanUp();
     }
     updates.Clear();
     updates = null;
     sender.CleanUp();
     sender = null;
     agentStates.Clear();
     agentStates = null;
     if (agents != null)
     {
         agents.Clear();
     }
     agents = null;
     bidKnowledge.CleanUp();
     tempGoal = null;
     goalTile = null;
 }
Exemple #17
0
 public void ResetCandidateTile()
 {
     this.canidateTile = null;
 }
Exemple #18
0
 public void SetCandidateTile(SearchTile t)
 {
     this.canidateTile = t;
 }
Exemple #19
0
    /*
     *  Core agent update function.
     */
    void Update()
    {
        if (this.sensorModule == null || this.knowledgeBase == null)
        {
            return;
        }
        float distToGoal = -1;

        if (WorldStateManager.CONTROL)
        {
            // This is control logic for a simple test to compare algos against
            // here for now because logic was tightly coupled
            // TODO: extract this into separate agent
            this.sensorModule.Update();
            if (knowledgeBase.GetCurrentGoal() == null)
            {
                Tile t = WorldStateManager.GetControlTileForAgent(this.ID);
                if (t == null)
                {
                    // Debug.Log("Tile is null");
                    //No goal so just chill out
                    flightController.SetNextDestination(sensorModule.gps.position);
                    this.flightController.UpdateMotion(1f);
                    return;
                }
                knowledgeBase.SetGoalTile(new SearchTile(t.GetID(), t.GetCenter()));
            }
            this.flightController.UpdateMotion(distToGoal);
            flightController.SetNextDestination(knowledgeBase.GetCurrentGoal().center);
            Debug.DrawLine(this.sensorModule.gps.position, new Vector3(this.knowledgeBase.GetCurrentGoal().center.x, this.knowledgeBase.GetCurrentGoal().center.y - 40f, this.knowledgeBase.GetCurrentGoal().center.z), Color.black);

            distToGoal = this.GetDistanceToGoal(this.sensorModule.gps.position, knowledgeBase.GetCurrentGoal().center);
            if (distToGoal < 5.1f)
            {
                WorldStateManager.MarkTileAsSearched(knowledgeBase.GetCurrentGoal());
                knowledgeBase.SetCurrentGoalAsSearched();
            }
            return;
        }
        // Update the knowledge base first
        this.sensorModule.Update();
        this.knowledgeBase.UpdateKnowledgeBase();

        // Check if the agent is in range of the tile
        SearchTile goalTile = knowledgeBase.GetCurrentGoal();

        if (goalTile != null)
        {
            distToGoal = this.GetDistanceToGoal(this.sensorModule.gps.position, goalTile.center);
            if (distToGoal < 5.1f)
            {
                WorldStateManager.MarkTileAsSearched(goalTile);
                knowledgeBase.SetCurrentGoalAsSearched();
            }
        }

        //This should be used with horizons and stuff
        if (shouldUpdateHeading())
        {
            this.knowledgeBase.ComputeNextHorizon(HEADING_UPDATE_TIME);
            Vector3 nextPoint = decisionManager.getNextDesiredPoint();
            // Debug.DrawLine( new Vector3(nextPoint.x, nextPoint.y - 50, nextPoint.z), new Vector3(nextPoint.x, nextPoint.y + 20, nextPoint.z));
            flightController.SetNextDestination(nextPoint);
        }

        // Update position
        this.flightController.UpdateMotion(distToGoal);
        // if(this.knowledgeBase.GetCurrentGoal() != null)
        // Debug.DrawLine( this.sensorModule.gps.position, new Vector3(this.knowledgeBase.GetCurrentGoal().center.x, this.knowledgeBase.GetCurrentGoal().center.y-40f, this.knowledgeBase.GetCurrentGoal().center.z), Color.black);
        this.knowledgeBase.SendAgentUpdate();
        // if(this.ID == 0){
        foreach (AgentUpdate upd in this.knowledgeBase.updates)
        {
            if (Vector3.Distance(this.sensorModule.gps.position, upd.lastUpdate.position) < 200)
            {
                Debug.DrawLine(this.sensorModule.gps.position, upd.lastUpdate.position, Color.black);
            }
        }
        // }
    }
Exemple #20
0
    public void RecvClaimedMessage(int srcId, int searchTileId, int agentId, float bestBidAmount)
    {
        if (agentId == this.myId)
        {
            return;
        }

        SearchTileBid recvClaimBid = new SearchTileBid(agentId, bestBidAmount);
        SearchTile    tile         = this.FindTileWithId(this.tilesInAuction, searchTileId);

        if (tile != null)
        {
            // If the received claim is the best bid, mark the tile as claimed
            if (recvClaimBid.IsBetterThan(tile.GetHighestBid()))
            {
                tile.SetAsClaimed(new SearchTileBid(agentId, bestBidAmount));
                this.MoveTile(tile, this.tilesInAuction, this.claimedTiles);
                if ((CandidateTile != null && CandidateTile.id == tile.id) ||
                    (this.kb.GoalTile != null && this.kb.GoalTile.id == tile.id))
                {
                    this.ResetCandidateAndGoalTile();
                }
            }
            else
            {
                // Get the highest bid for the tile claimed
                tile.SetAsClaimed(tile.GetHighestBid());
                this.MoveTile(tile, this.tilesInAuction, this.claimedTiles);
                // If I have claimed this tile let others know
                if ((CandidateTile != null && CandidateTile.id == tile.id) ||
                    (this.kb.GoalTile != null && this.kb.GoalTile.id == tile.id))
                {
                    WorldStateManager.MarkTileAsClaimed(tile);
                    this.sender.SendClaimed(tile.id, tile.acceptedBid.agentId, tile.acceptedBid.value);
                }
            }
            return;
        }

        tile = this.FindTileWithId(this.openTiles, searchTileId);
        if (tile != null)
        {
            tile.SetAsClaimed(new SearchTileBid(agentId, bestBidAmount));
            this.MoveTile(tile, this.openTiles, this.claimedTiles);
            return;
        }

        // Check if the tile has been claimed
        tile = this.FindTileWithId(this.claimedTiles, searchTileId);
        if (tile != null)
        {
            if (tile.acceptedBid.IsBetterThan(recvClaimBid))
            {
                if ((CandidateTile != null && CandidateTile.id == tile.id) ||
                    (this.kb.GoalTile != null && this.kb.GoalTile.id == tile.id))
                {
                    //Debug.Log("Recv claimed for tile "+tile.id+", I agent "+ this.myId+" have claimed.");
                    this.sender.SendClaimed(tile.id, tile.acceptedBid.agentId, tile.acceptedBid.value);
                }
            }
            else
            {
                // The recv claim is better, so update knowledge
                if ((CandidateTile != null && CandidateTile.id == tile.id) ||
                    (this.kb.GoalTile != null && this.kb.GoalTile.id == tile.id))
                {
                    ResetCandidateAndGoalTile();
                }

                tile.acceptedBid.agentId = agentId;
                tile.acceptedBid.value   = bestBidAmount;
            }
        }

        // Otherwise, the tile has been claimed by another agent or searched already
        tile = this.FindTileWithId(this.searchedTiles, searchTileId);
        if (tile != null)
        {
            this.sender.SendSearched(searchTileId);
            return;
        }
    }
Exemple #21
0
    public SearchTile GetClaimedTile(SearchTile tile)
    {
        int index = claimedTiles.BinarySearch(tile);

        return((SearchTile)claimedTiles[index]);
    }
Exemple #22
0
 public void SetGoalTile(SearchTile g)
 {
     this.goalTile = g;
 }
Exemple #23
0
 public void SetTempGoal(SearchTile g)
 {
     this.tempGoal = g;
 }
Exemple #24
0
 public void ResetGoalTile()
 {
     goalTile = null;
 }