From fcc373c0d891a5c4a16c4778c3be827f8ffabd53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoffer=20M=C3=BCller=20Madsen?= Date: Wed, 14 Mar 2018 12:47:27 +0100 Subject: [PATCH] update pubeval to take tuples of proper length as input --- board.py | 2 +- bot.py | 2 +- game.py | 2 +- pubeval/pubeval.c | 21 ++++++++++++++++++--- pubeval/setup.py | 2 +- 5 files changed, 22 insertions(+), 7 deletions(-) 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