空指针通常意味着某个参数中存在程序员错误,是否可以查看我的代码以确保我没有遗漏任何明显的东西?
它只是一个简单的基于 % 的扑克机器人,很确定这就是它“认为”错误所在的地方。
public Action act(Set<Action> actions) {
Random generator = new Random();
int roll = generator.nextInt(100) + 1; //gives number between 1 and 100
System.out.println("roll = " + roll);
Action myAction = null;
if (roll <= 30) { // RAISE 30%
if (actions.contains(Action.RAISE)) {
myAction = Action.RAISE;
} else if (actions.contains(Action.BET)) {
myAction = Action.BET;
} else if (actions.contains(Action.CALL)) {
myAction = Action.CALL;
}
} else if (roll > 30 && roll <= 90) { // CALL/CHECK 60%
if (actions.contains(Action.CALL)) {
myAction = Action.CALL;
} else if (actions.contains(Action.CHECK)) {
myAction = Action.CHECK;
}
} else if (roll > 90) { // FOLD 10%
if (actions.contains(Action.FOLD)) {
myAction = Action.FOLD;
}
return myAction;
}
}
编辑:
下面是添加的 set Action 方法:
public Action act(Set<Action> actions, int minBet, int currentBet) {
action = client.act(actions);
switch (action) {
case CHECK:
break;
case CALL:
betIncrement = currentBet - bet;
if (betIncrement > cash) {
//TODO: All-in with partial Call.
betIncrement = cash;
}
cash -= betIncrement;
bet += betIncrement;
break;
case BET:
betIncrement = minBet;
if (betIncrement >= cash) {
//TODO: All-in with partial Bet.
betIncrement = cash;
}
cash -= betIncrement;
bet += betIncrement;
raises++;
break;
case RAISE:
currentBet += minBet;
betIncrement = currentBet - bet;
cash -= betIncrement;
bet += betIncrement;
raises++;
break;
case FOLD:
hand.removeAllCards();
break;
}
return action;
}
Action方法继承自接口类Client.java:
Action act(Set<Action> allowedActions);
非常感谢!
解决方案:
当我尝试对自己运行两个相同的机器人时,它在某处发生冲突,导致空指针。当我使用任何两个不同的机器人时,它运行良好,没有错误。