예제 #1
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);
 }
예제 #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;
        }
    }