尝试在这里做一些非常基本的数学,但是我对Java缺乏了解会给我带来一些问题。
double[][] handProbability = new double[][] {{0,0,0},{0,0,0},{0,0,0}};
double[] handProbabilityTotal = new double[] {0,0,0};
double positivePot = 0;
double negativePot = 0;
int localAhead = 0;
int localTied = 1;
int localBehind = 2;
//do some stuff that adds values to handProbability and handProbabilityTotal
positivePot =
(handProbability[localBehind][localAhead] +
(handProbability[localBehind][localTied] / 2.0) +
(handProbability[localTied][localAhead] / 2.0) ) /
(handProbabilityTotal[localBehind] + (handProbability[localTied] / 2.0));
negativePot =
(handProbability[localAhead][localBehind] +
(handProbability[localAhead][localTied] / 2.0) +
(handProbability[localTied][localBehind] / 2.0) ) /
(handProbabilityTotal[localAhead] + (handProbabilityTotal[localTied] / 2.0));
最后两行给我带来了麻烦(抱歉他们很长)。 编译器错误:
src/MyPokerClient/MyPokerClient.java:180: operator / cannot be applied to double[],double
positivePot = ( handProbability[localBehind][localAhead] + (handProbability[localBehind][localTied] / 2.0) + (handProbability[localTied][localAhead] / 2.0) ) / (handProbabilityTotal[localBehind] + (handProbability[localTied] / 2.0) );
^
src/MyPokerClient/MyPokerClient.java:180: operator + cannot be applied to double,
positivePot = ( handProbability[localBehind][localAhead] + (handProbability[localBehind][localTied] / 2.0) + (handProbability[localTied][localAhead] / 2.0) ) / (handProbabilityTotal[localBehind] + (handProbability[localTied] / 2.0) );
^
src/MyPokerClient/MyPokerClient.java:180: operator / cannot be applied to double,
positivePot = ( handProbability[localBehind][localAhead] + (handProbability[localBehind][localTied] / 2.0) + (handProbability[localTied][localAhead] / 2.0) ) / (handProbabilityTotal[localBehind] + (handProbability[localTied] / 2.0) );
不确定问题是什么。对于基础数学,你不需要任何特殊的东西,对吧?
答案 0 :(得分:3)
在第一行(handProbability[localTied] / 2.0)
的最后一部分,您尝试划分数组(hardProbability[localTied]
)而不是数字(其中一个值)。
答案 1 :(得分:3)
最后一行之前的行有问题。
positivePot =
(handProbability[localBehind][localAhead] +
(handProbability[localBehind][localTied] / 2.0) +
(handProbability[localTied][localAhead] / 2.0) ) /
(handProbabilityTotal[localBehind] + (handProbability[localTied] / 2.0));
handProbability是一个二维双数组。所以handProbability [localTied]是一个双打数组。它不是双重价值。基于你的最后一行,我认为它应该是handProbabilityTotal [localTied]。
答案 2 :(得分:1)
由于handProbability
是多维数组,因此无法将数组划分为数字:
handProbability[localTied] / 2.0
当然,它会给你错误。修复此行。你可能意味着handProbabilityTotal
?