update pubeval to take tuples of proper length as input
This commit is contained in:
parent
57367329ec
commit
fcc373c0d8
2
board.py
2
board.py
|
@ -33,7 +33,7 @@ class Board:
|
||||||
negatives = [x if x < 0 else 0 for x in board]
|
negatives = [x if x < 0 else 0 for x in board]
|
||||||
board.append(15 - sum(positives))
|
board.append(15 - sum(positives))
|
||||||
board.append(-15 - sum(negatives))
|
board.append(-15 - sum(negatives))
|
||||||
return board
|
return tuple(board)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
2
bot.py
2
bot.py
|
@ -52,7 +52,7 @@ class Bot:
|
||||||
# TODO: Test this, the score results should be deterministic
|
# TODO: Test this, the score results should be deterministic
|
||||||
def make_pubeval_move(self, board, sym, roll):
|
def make_pubeval_move(self, board, sym, roll):
|
||||||
legal_moves = Board.calculate_legal_states(tuple(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 ]
|
scores = [ x[1] for x in moves_and_scores ]
|
||||||
best_move_pair = moves_and_scores[np.array(scores).argmax()]
|
best_move_pair = moves_and_scores[np.array(scores).argmax()]
|
||||||
return best_move_pair
|
return best_move_pair
|
||||||
|
|
2
game.py
2
game.py
|
@ -184,7 +184,7 @@ class Game:
|
||||||
roll = self.roll()
|
roll = self.roll()
|
||||||
self.board = (self.p1.make_move(self.board, self.p1.get_sym(), roll))[0]
|
self.board = (self.p1.make_move(self.board, self.p1.get_sym(), roll))[0]
|
||||||
roll = self.roll()
|
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]))
|
sys.stderr.write("\t outcome {}".format(Board.outcome(self.board)[1]))
|
||||||
outcomes.append(Board.outcome(self.board)[1])
|
outcomes.append(Board.outcome(self.board)[1])
|
||||||
sys.stderr.write("\n")
|
sys.stderr.write("\n")
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
|
|
||||||
|
static PyObject* PubevalError;
|
||||||
|
|
||||||
static float x[122];
|
static float x[122];
|
||||||
|
|
||||||
static const float wc[122] = {
|
static const float wc[122] = {
|
||||||
|
@ -140,7 +142,11 @@ pubeval_eval(PyObject *self, PyObject *args) {
|
||||||
numValues = PyTuple_Size(tuple_obj);
|
numValues = PyTuple_Size(tuple_obj);
|
||||||
|
|
||||||
if (numValues < 0) return NULL;
|
if (numValues < 0) return NULL;
|
||||||
|
if (numValues != 28) {
|
||||||
|
PyErr_SetString(PubevalError, "Tuple must have 28 entries");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// Iterate over tuple to retreive positions
|
// Iterate over tuple to retreive positions
|
||||||
for (int i=0; i<numValues; i++) {
|
for (int i=0; i<numValues; i++) {
|
||||||
val_obj = PyTuple_GetItem(tuple_obj, i);
|
val_obj = PyTuple_GetItem(tuple_obj, i);
|
||||||
|
@ -168,6 +174,15 @@ static struct PyModuleDef pubeval_definition = {
|
||||||
};
|
};
|
||||||
|
|
||||||
PyMODINIT_FUNC PyInit_pubeval(void) {
|
PyMODINIT_FUNC PyInit_pubeval(void) {
|
||||||
//Py_Initialize();
|
PyObject* module;
|
||||||
return PyModule_Create(&pubeval_definition);
|
|
||||||
|
module = PyModule_Create(&pubeval_definition);
|
||||||
|
if (module == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
PubevalError = PyErr_NewException("pubeval.error", NULL, NULL);
|
||||||
|
Py_INCREF(PubevalError);
|
||||||
|
PyModule_AddObject(module, "error", PubevalError);
|
||||||
|
|
||||||
|
return module;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,6 @@ pubeval = Extension('pubeval',
|
||||||
sources = ['pubeval.c'])
|
sources = ['pubeval.c'])
|
||||||
|
|
||||||
setup (name = 'pubeval',
|
setup (name = 'pubeval',
|
||||||
version = '0.2',
|
version = '0.3',
|
||||||
description = 'Pubeval for Python',
|
description = 'Pubeval for Python',
|
||||||
ext_modules = [pubeval])
|
ext_modules = [pubeval])
|
||||||
|
|
Loading…
Reference in New Issue
Block a user