Commit 864a3cdb authored by Vivien Kraus's avatar Vivien Kraus
Browse files

Use the perceptron to make the call

parent bb6bcd7d
......@@ -2107,8 +2107,8 @@ features_strongest_player_aux (size_t n_players,
return features_strongest_player_try_bid (&predictor);
}
static int predictor_select_call (int cnn, const TarotGame * game,
TarotCard * call, double *score);
static int predictor_perceptron_select_call (const TarotGame * game,
TarotCard * call, double *score);
static inline TarotCard
features_strongest_call (size_t n_players, size_t n_cards,
......@@ -2150,13 +2150,61 @@ features_strongest_call (size_t n_players, size_t n_cards,
assert (0);
}
}
if (predictor_select_call (0, &game, &call, &score) != 0)
if (predictor_perceptron_select_call (&game, &call, &score) != 0)
{
assert (0);
}
return call;
}
static int
predictor_perceptron_select_call (const TarotGame * game, TarotCard * call,
double *best_score)
{
static const TarotSuit suits[4] = {
TAROT_HEARTS,
TAROT_CLUBS,
TAROT_DIAMONDS,
TAROT_SPADES
};
TarotNumber minimum, candidate;
TarotGameEvent e;
TarotPlayer player;
int ret = 1;
int isuit;
TarotPerceptron *perceptron;
e.n = 0;
*best_score = -DBL_MAX;
if (game_get_hint_call (game, &player, &minimum) != TAROT_GAME_OK)
{
return 1;
}
perceptron = tarot_perceptron_static_default ();
for (isuit = 0; isuit < 4; isuit++)
{
TarotSuit suit = suits[isuit];
for (candidate = minimum; candidate <= TAROT_KING; candidate++)
{
TarotCard c;
double candidate_score;
if (tarot_of (candidate, suit, &c) != 0)
{
assert (0);
}
event_set_call (&e, c);
candidate_score = tarot_perceptron_predict (perceptron, game, &e);
if (candidate_score > *best_score)
{
*call = c;
*best_score = candidate_score;
ret = 0;
}
}
}
tarot_perceptron_free (perceptron);
return ret;
}
static inline TarotPlayer
features_strongest_player (size_t n_players,
int with_call,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment