这是对博弈论中的美元票据拍卖博弈的一个KOTH挑战。其中,一美元被卖给出价最高的人。出价增加5美分,输家也支付他们的出价。他们的想法是,为了减少损失,这两家公司都将竞购战升级至一美元以外。
希望你的机器人比这更聪明。
您将通过扩展net.ramenchef.dollarauction.DollarBidder类来创建一个机器人来玩这个游戏。您必须实现返回bot下一个出价的nextBid方法,考虑到另一个bot的上一个出价。如果有必要,您也可以使用newAuction方法为每次拍卖重置与对手的机器人类。
public abstract class DollarBidder {
/**
* Used by the runner to keep track of scores.
*/
long score = 0;
/**
* (Optional) Prepare for the next auction.
*
* @param opponent The class of the opponent's bot.
*/
public void newAuction(Class opponent) {}
/**
* Bid on the dollar. Bidding ends if the bid is
* not enough to top the previous bid or both bids
* exceed $100.
*
* @param opponentsBid How much money, in cents,
* that the opponent bid in the previous round. If
* this is the first round in the auction, it will
* be 0.
* @return How much money to bid in this round, in
* cents.
*/
public abstract int nextBid(int opponentsBid);
}招标直至发生下列情况之一:
nextBid抛出一个异常。如果发生这种情况,抛出例外情况的机器人支付他们以前的出价,而另一个机器人则免费获得美元。每个机器人组合举行2次拍卖。机器人是通过它们在这些拍卖会上获得的总利润来得分的。得分最高者获胜。
GreedyBotimport net.ramenchef.dollarauction.DollarBidder;
public class GreedyBot extends DollarBidder {
@Override
public int nextBid(int opponentsBid) {
return opponentsBid + 5;
}
}OnlyWinningMoveimport net.ramenchef.dollarauction.DollarBidder;
public class OnlyWinningMove extends DollarBidder {
@Override
public int nextBid(int opponentsBid) {
return 0;
}
}AnalystBot不要将此作为具有分析思维的机器人的模板,而是使用ImprovedAnalystBot。
import net.ramenchef.dollarauction.DollarBidder;
// yes, this is a poor implementation, but I'm not
// going to waste my time perfecting it
public class AnalystBot extends DollarBidder {
private DollarBidder enemy;
@Override
public void newAuction(Class opponent) {
try {
enemy = opponent.newInstance();
enemy.newAuction(this.getClass());
} catch (ReflectiveOperationException e) {
enemy = null;
}
}
@Override
public int nextBid(int opponentsBid) {
if (enemy == null)
return 0;
return enemy.nextBid(95) >= 100 ? 0 : 95;
}
}AnalystKillerimport net.ramenchef.dollarauction.DollarBidder;
public class AnalystKiller extends DollarBidder {
private static int instances = 0;
private final boolean tainted;
public AnalystKiller() {
this.tainted = instances++ != 0;
}
@Override
public int nextBid(int opponentsBid) {
if (tainted)
throw new RuntimeException("A mysterious error occurred! >:)");
return 0;
}
}SecurityExceptions。一个例外是导致另一个机器人突破500毫秒的限制。DollarBidder类,否则机器人无法访问运行程序包。MTargetedBot: $14.30
BuzzardBot: $9.83
BluffBot: $9.40
RiskRewardBot: $9.35
SecretBot: $8.50
LuckyDiceBot: $7.28
CounterBot: $6.05
MBot: $5.40
StackTraceObfuscaterBot: $5.20
EvilBot: $4.80
MarginalBot: $4.60
TargetValueBot: $4.59
InflationBot: $4.27
UpTo200: $4.20
InsiderTradingBot: $1.90
MimicBot: $1.50
BorkBorkBot: $1.22
DeterrentBot: $0.95
MarginalerBot: $0.00
RandBot: $-4.45
BreakEvenAsap: $-7.00
AnalystOptimizer: $-13.95
DeterredBot: $-1997.06
ScoreOverflowBot: $-21474844.15
MirrorBot: $-21475836.25祝贺MTargetedBot获得14.30美元的利润!
发布于 2018-04-20 20:05:13
public class MTargetedBot extends MBot {
@Override
protected int calcBid(int opponentsBid, boolean isPeeking, boolean isSubPeeking) {
Class c = this.rivalClass;
switch (c.getSimpleName()) {
case "AnalystBot":
if (isPeeking && !isSubPeeking) {
throw new RuntimeException();
} else if (isPeeking) {
return 66666;
}
break;
case "MirrorBot":
if (isPeeking && !isSubPeeking) {
throw new RuntimeException();
} else if (isPeeking) {
return 0;
}
break;
case "GreedyBot":
case "LuckyDiceBot":
case "InflationBot":
case "TargetValueBot":
// not playing with ya
return 0;
case "MimicBot":
case "BuzzardBot":
case "MarginalBot":
case "MarginalerBot":
case "BluffBot":
case "MBot":
// go away, gimme easy money
return isPeeking ? 66666 : 5;
case "RandBot":
// me or noone
return 100;
case "SecretBot":
return 10;
case "AnalystKiller":
case "OnlyWinningMove":
case "EvilBot":
case "StackTraceObfuscaterBot":
// easy
return opponentsBid + 5;
}
return super.calcBid(opponentsBid, isPeeking, isSubPeeking);
}
}发布于 2018-04-18 01:52:23
import net.ramenchef.dollarauction.DollarBidder;
import java.util.Set;
import java.util.HashSet;
public class MimicBot extends AbstractAnalystCounterBot {
private final Set> bidders = new HashSet<>();
private DollarBidder reference = null;
// A benchmark class. Not MarginalBot because of proposed rule changes.
public static class BidFive extends DollarBidder {
public int nextBid(int o) {
return 5;
}
}
public MimicBot() {
bidders.add(OnlyWinningMove.class);
bidders.add(GreedyBot.class);
bidders.add(BidFive.class);
}
@Override
public void newAuction(Class opponent) {
DollarBidder enemy;
reference = null;
try {
enemy = opponent.newInstance();
} catch (Throwable t) {
return;
}
if (!bidders.contains(opponent))
bidders.add(opponent);
Class leader = OnlyWinningMove.class;
int best = 0;
for (Class audition : bidders) {
try {
enemy.newAuction(MimicBot.class);
} catch (Throwable t) {
reference = new GreedyBot(); // Deterrence.
break;
}
DollarBidder tryout;
try {
tryout = audition.newInstance();
tryout.newAuction(opponent);
} catch (Throwable t) {
continue;
}
int tryoutScore = -100000;
/* This code was copy-pasted from the *
* runner, with significant changes. */
int bid1 = 0, bid2 = 0;
while (true) {
int next;
try {
next = enemy.nextBid(bid2);
} catch (Throwable t) {
tryoutScore = 100;
break;
}
if (next < bid2 + 5) {
if (bid2 > 0) {
tryoutScore = 100 - bid1;
}
break;
}
if (next > 10000 && bid2 > 10000) {
tryoutScore = -10000;
break;
}
bid1 = next;
try {
next = tryout.nextBid(bid1);
} catch (Throwable t) {
tryoutScore = -bid2;
break;
}
if (next < bid1 + 5) {
tryoutScore = -bid2;
break;
}
if (next > 10000 && bid1 > 10000) {
tryoutScore = -10000;
break;
}
bid2 = next;
}
/* End of copy-pasted code. */
if (tryoutScore > best) {
best = tryoutScore;
leader = audition;
}
}
try {
reference = leader.newInstance();
} catch (Throwable t) {
reference = new OnlyWinningMove();
}
reference.newAuction(opponent);
}
@Override
public int nextBid(int opponentsBid) {
try {
return reference.nextBid(opponentsBid);
} catch (Throwable t) {
return 5;
}
}
}天啊。我以为这是简单的写作,然后花了3个小时在上面。
本质上,MimicBot保存了可用的机器人的运行列表。当它进入一个新的拍卖,它运行在列表中寻找最有效的对抗当前的对手。然后,它使用该机器人作为“参考”在拍卖。
为了测试目的,最好是使用提交的随机子集或完整的集合。它以GreedyBot、MimicBot和另外一个仅出价5美分的机器人开始。
发布于 2018-04-17 22:37:07
本着@StephenLeppik回答的精神,InsiderTradingBot了解他的所有对手并理解他们的策略。你的行动,斯蒂芬。
import net.ramenchef.dollarauction.DollarBidder;
public class InsiderTradingBot extends DollarBidder {
private static boolean analystNutcracker = false;
private int bid;
@Override
public void newAuction(Class opponent) {
if (opponent.equals(DeterredBot.class) ||
opponent.equals(OnlyWinningMove.class) ||
opponent.equals(MirrorBot.class)) {
// I can do this ^.^
bid = 5;
} else if (opponent.equals(AnalystKiller.class)) {
// Outbid 'em >:D
bid = 10;
} else if (opponent.equals(BreakEvenAsap.class) ||
opponent.equals(BorkBorkBot.class) ||
opponent.equals(DeterrentBot.class)) {
// Break even quicker!
bid = 100;
} else if (opponent.equals(InsiderTradingBot.class)) {
// I'm probably a simulation inside MirrorBot
bid = 0;
} else if (opponent.equals(Analyst.class)) {
// Let's fight the Analyst with the power of global variables
bid = 100;
analystNutcracker = true;
} else {
// Welp
bid = 0;
}
}
@Override
public int nextBid(int opponentsBid) {
if ((opponentsBid == 95) && analystNutcracker) {
analystNutcracker = false;
return 0;
}
return bid;
}
};https://codegolf.stackexchange.com/questions/162554
复制相似问题