farhanrahman / kyoto

18 stars 7 forks source link

NonAnnexOne countries respond to all trade broadcast messages #126

Closed farhanrahman closed 12 years ago

farhanrahman commented 12 years ago

I ran simulations and i realised that non annex1 countries respond to all broadcast messages whether it is CDM or Trade BUY or Trade SELL. So I got results such as BGD buying from Ukraine. The bug is the following:

        if (this.tradeProtocol.canHandle(in)) {
            this.tradeProtocol.handle(in);
        }
        else {

            if(in instanceof Message){
                try{
                    @SuppressWarnings("unchecked")
                    Message<OfferMessage> m = (Message<OfferMessage>) in;
                    OfferMessage o = m.getData();
                    if(!this.tradeProtocol
                            .getActiveConversationMembers()
                                .contains(m.getFrom())){
                        try {
/*You should not respond to all the offers. You should see if the offer is of type that you want. If its a buy or sell offer you should ignore it as a non annex one country.*/
//TODO insert your logic here
                            this.tradeProtocol.offer(
                                    m.getFrom(), 
                                    o.getOfferQuantity(), 
                                    o);
                        } catch (FSMException e) {
                            logger.warn(e);
                        }
                    }
                }catch(ClassCastException e){
                    logger.warn("Class cast exception");
                    logger.warn(e);
                }
            }
        }

In the above function NonAnnexOne exactly copies what was given in the wiki. You have to insert your country logic where I have given a TODO in the above function.

Let me know if you have any problems :)

sc1109 commented 12 years ago

This is a pretty hilarious oversight. @n1kunj brought it to my attention lol.