robocode简单使用1

package ms; import robocode.*; import java.util.*; //******************************************************************************************/ // GoodBot: determine, if a bot is a bastart or not // // needed: public void run() // GoodBot.Reset(); // public void onRobotDeath(RobotDeathEvent e) // GoodBot.BotDeath(e.getName(), this); // // example: public void onScannedRobot(ScannedRobotEvent e) // if (GoodBot.badBot(e.getName(), this)) //******************************************************************************************/ class GoodBot { static private Hashtable Bots = new Hashtable(); static private int GoodBots1 = 1; static private int GoodBots2 = 0; static private String bot; static public int KilledGoodBots1 = 0; static public int KilledGoodBots2 = 0; //******************************************************************************************/ // BadBot: is it a bad bot? //******************************************************************************************/ public static boolean badBot(String Name, AdvancedRobot in_this) { bot = (String)Bots.get(Name); if (bot == null) classBot(Name, in_this); int others = in_this.getOthers(); if ( (bot.compareTo("1") == 0) && (others >= GoodBots1 - KilledGoodBots1) ) return false; else if ( (bot.compareTo("2") == 0) && (others >= GoodBots1 - KilledGoodBots1 + GoodBots2 - KilledGoodBots2) ) return false; else return true; } public static void BotDeath(String Name, AdvancedRobot in_this) { bot = (String)Bots.get(Name); if (bot == null) classBot(Name, in_this); if ( bot.compareTo("1") == 0 ) KilledGoodBots1++; else if ( bot.compareTo("2") == 0 ) KilledGoodBots2++; } public static void Reset() { KilledGoodBots1 = 0; KilledGoodBots2 = 0; } private static void classBot(String Name, AdvancedRobot in_this) { int M_GoodBots = GoodBots1; String Gegnertyp = botTyp(Name); String Mytyp = botTyp(in_this.getName()); if (Gegnertyp.compareTo(Mytyp) == 0) { bot = "1"; if (GoodBots1 > M_GoodBots) in_this.out.println("I've found " + (GoodBots1 - 1) + " more " + Mytyp + "-Bot(s)."); } else { GoodBots1 = M_GoodBots; String Gegnerpack = botTyp2(Name); String Mypack = botTyp2(in_this.getName()); if (Gegnerpack.compareTo(Mypack) == 0) { bot = "2"; GoodBots2++; in_this.out.println("I've found " + (GoodBots2) + " more " + Mypack + "-Bot(s)."); } else bot = "0"; } Bots.put(Name, new String(bot)); } private static String botTyp(String BotName) { int k=BotName.indexOf("("); if (k != -1) { int Nr=Integer.parseInt(BotName.substring(k+1, BotName.indexOf(")")),10); if (GoodBots1 < Nr) GoodBots1 = Nr; return BotName.substring(0, k-1); } else return BotName; } private static String botTyp2(String BotName) { int k=BotName.indexOf("."); if (k != -1) { return BotName.substring(0, k); } else return BotName; } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值