예제 #1
0
    private void ProcessBid(Packet p)
    {
        BidMessage bidMsg = (BidMessage)p.message;
//		Debug.Log ("Processing bid for Agent " + p.src.ID + " on tile " + bidMsg.tileId + " with amount " + bidMsg.bidAmount);
        /* Determine if the agent should bid for a different tile */
        SearchTileBid recvBid = new SearchTileBid(p.src.ID, bidMsg.bidAmount);

        if (this.goalTile == null && this.bidKnowledge.CandidateTile != null && bidMsg.tileId == this.bidKnowledge.CandidateTile.id)           //&& this.canidateBid != null
        // If the recv bid is better than my bid, reset
        {
            if (recvBid.IsBetterThan(this.bidKnowledge.CandidateBid))
            {
                this.bidKnowledge.CandidateTile.SetAsClaimed(recvBid);
                this.bidKnowledge.ResetCandidateAndGoalTile();
            }
        }
        else if (this.goalTile != null && bidMsg.tileId == this.goalTile.id)
        {
            // If the recv bid is better than my claimed bid, give up on that tile and assert that the other
            //
            if (recvBid.IsBetterThan(this.goalTile.acceptedBid))
            {
                this.goalTile.acceptedBid = recvBid;
                this.bidKnowledge.ResetCandidateAndGoalTile();
//				this.sender.SendClaimed (bidMsg.tileId, recvBid.agentId, recvBid.value);
            }
        }
        bidKnowledge.AddBidForTile(bidMsg.tileId, new SearchTileBid(p.src.ID, bidMsg.bidAmount));
    }
예제 #2
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;
        }
    }