Skip to content
Snippets Groups Projects
Commit be0fac28 authored by Pizon Antoine's avatar Pizon Antoine
Browse files

Method move_to_pos added to penguin

parent 5fe26243
No related branches found
No related tags found
No related merge requests found
......@@ -526,7 +526,7 @@ namespace game
return board;
}
uint64_t pengin::penguin_move_board(const uint32_t& pen) const
uint64_t penguin::penguin_move_board(const uint32_t& pen) const
{
uint64_t board = 0;
//Direction A
......@@ -567,4 +567,27 @@ namespace game
return played;
}
uint32_t penguin::move_to_pos(uint16_t m)
{
uint32_t result = 0;
uint32_t* peng;
uint16_t rel_move = m;
int i = 0;
if(state.current_player_red) {
for(i = 0; (i < 3) && (PENGUIN_TOT_MOVES(state.peng_red[i]) <= rel_move); i ++) //While we didn't find the penguin
rel_move -= PENGUIN_TOT_MOVES(state.peng_red[i]);
peng = &state.peng_red[i];
}
else {
for(i = 0; (i < 3) && (PENGUIN_TOT_MOVES(state.peng_blue[i]) <= rel_move); i ++) //While we didn't find the penguin
rel_move -= PENGUIN_TOT_MOVES(state.peng_blue[i]);
peng = &state.peng_blue[i];
}
result = PENGUIN_POS(*peng) << 16;
play(m);
result |= PENGUIN_POS(*peng);
}
}
......@@ -81,6 +81,8 @@ namespace game
static penguin_state random_start_state();
std::uint64_t penguin_board(bool) const; // true for position of blue penguin, else false
uint8_t turns_played() const;
uint32_t move_to_pos(uint16_t m);
private:
penguin_state state;
......
......@@ -87,13 +87,16 @@ template <typename Game>
void test_mcts_two_players<Game>::save_board(const Game& game, int move){
std::shared_ptr<game::penguin> g = game::copy(game);
game::penguin_state state = g->get_state();
savefile << state.one_fish << ";" << state.two_fish << ";" << state.three_fish << ";" << g->penguin_board(false) << ";" << g->penguin_board(true) << ";" << move << std::endl;
uint32_t pos = g->move_to_pos(move);
uint16_t peng_pos = (uint16_t)(pos >> 16);
uint16_t peng_pos = (uint16_t)pos;
savefile << state.one_fish << ";" << state.two_fish << ";" << state.three_fish << ";" << g->penguin_board(false) << ";" << g->penguin_board(true) << ";" << peng_pos << ";" << dest << std::endl;
}
template <typename Game>
void test_mcts_two_players<Game>::play(Game g, const heuristic<Game>& h)
{
// ProfilerStart("theturk.prof");
//ProfilerStart("theturk.prof");
auto the_turk = make_mcts_two_players(g, MCTS_TURN_TIME, 0.4, 8, h);
std::cout << "play one game" << std::endl;
std::cout << "who's first? (h)uman/(c)omputer ";
......
......@@ -4,28 +4,28 @@ from keras.models import Sequential
from keras.layers import Dense
import numpy
# fix random seed for reproducibility
# Fix random seed for reproducibility
seed = 7
numpy.random.seed(seed)
# loading data
# Loading data
dataset = numpy.loadtxt("save.csv", delimiter=";")
# split into input (X) and output (Y) variables
# Split into input (X) and output (Y) variables
X = dataset[:,0:5]
Y = dataset[:,5]
# create model
# Creating the model
model = Sequential()
model.add(Dense(12, input_dim=5, init='uniform', activation='relu'))
model.add(Dense(8, init='uniform', activation='relu'))
model.add(Dense(1, init='uniform', activation='sigmoid'))
model.add(Dense(1, init='uniform', activation='softmax'))
# Compile model
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
# Compiling the model
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
# Fit the model
model.fit(X, Y, nb_epoch=150, batch_size=10)
# Training the model
model.fit(X, Y, nb_epoch=5, batch_size=10)
# evaluate the model
# Evaluating the model
scores = model.evaluate(X, Y)
print("%s: %.2f%%" % (model.metrics_names[1], scores[1]*100))
......@@ -48,7 +48,6 @@
234191587400222720;1073746433;64;18014398515773952;4398180732992;0
234191587400222720;1073746433;64;18014398515773952;4398180732992;0
234191587400222720;1073742337;64;18014398515773952;4398180730944;0
931934812694784276;148647583688971945;72339108223090754;19795638484992;576601558511257600;54306
931934812694784276;148629991502927529;72339108223090754;2203452440592;576601558511257600;38
931794075206428948;148629991502927529;72339108223090754;2203452440592;576460821022935040;35
931794075206428948;148629991502927529;72339103928123458;2199157538832;576460821022935040;6
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment