diff --git a/board.py b/board.py index 5150d35..bfa7998 100644 --- a/board.py +++ b/board.py @@ -33,7 +33,7 @@ class Board: negatives = [x if x < 0 else 0 for x in board] board.append(15 - sum(positives)) board.append(-15 - sum(negatives)) - return board + return tuple(board) diff --git a/bot.py b/bot.py index 620e399..ca2f734 100644 --- a/bot.py +++ b/bot.py @@ -52,7 +52,7 @@ class Bot: # TODO: Test this, the score results should be deterministic def make_pubeval_move(self, board, sym, roll): legal_moves = Board.calculate_legal_states(tuple(board), sym, roll) - moves_and_scores = [(board, pubeval.eval(False, board)) for board in legal_moves] + moves_and_scores = [(board, pubeval.eval(False, Board.board_features_to_pubeval(board, sym))) for board in legal_moves] scores = [ x[1] for x in moves_and_scores ] best_move_pair = moves_and_scores[np.array(scores).argmax()] return best_move_pair diff --git a/game.py b/game.py index 1abfb23..2da10ea 100644 --- a/game.py +++ b/game.py @@ -184,7 +184,7 @@ class Game: roll = self.roll() self.board = (self.p1.make_move(self.board, self.p1.get_sym(), roll))[0] roll = self.roll() - self.board = Board.flip(self.p2.make_pubeval_move(Board.board_features_to_pubeval(self.board, self.p2.get_sym()), self.p2.get_sym(), roll)[0][0:26]) + self.board = Board.flip(self.p2.make_pubeval_move(self.board, self.p2.get_sym(), roll)[0][0:26]) sys.stderr.write("\t outcome {}".format(Board.outcome(self.board)[1])) outcomes.append(Board.outcome(self.board)[1]) sys.stderr.write("\n") diff --git a/pubeval/pubeval.c b/pubeval/pubeval.c index 159ee09..f3aee29 100644 --- a/pubeval/pubeval.c +++ b/pubeval/pubeval.c @@ -1,5 +1,7 @@ #include +static PyObject* PubevalError; + static float x[122]; static const float wc[122] = { @@ -140,7 +142,11 @@ pubeval_eval(PyObject *self, PyObject *args) { numValues = PyTuple_Size(tuple_obj); if (numValues < 0) return NULL; - + if (numValues != 28) { + PyErr_SetString(PubevalError, "Tuple must have 28 entries"); + return NULL; + } + // Iterate over tuple to retreive positions for (int i=0; i