Commit db8cec66 authored by Vivien Kraus's avatar Vivien Kraus

Ask the bid

parent 1649ecd8
Pipeline #103224 passed with stages
in 4 minutes and 40 seconds
......@@ -34,6 +34,8 @@ It can also play asynchronously.
public signal void render ();
public signal void ask_n_players (bool ask);
public signal void ask_bid (bool ask, bool take_enabled, bool push_enabled,
bool strk_enabled, bool dblk_enabled);
public int n_iterations = 100;
public string seed = "default";
......@@ -80,7 +82,7 @@ It can also play asynchronously.
var current_trick = restricted_game.current_trick ();
var n_tricks = restricted_game.n_tricks ();
_assignment.cards_foreground = new Tarot.CardArray.alloc ();
_assignment.myself = 3;
_assignment.myself = 0;
Tarot.Card trick_card = 78;
bool cnf, cno, cnu;
if (_assignment.cards_trick.resize (n_players) != 0) {
......@@ -106,7 +108,7 @@ It can also play asynchronously.
}
if (current_trick < n_tricks
&& restricted_game.get_trick_card_of (current_trick, _assignment.myself, out trick_card,
out cnf, out cno, out cnu) == 0) {
out cnf, out cno, out cnu) == 0) {
_assignment.cards_trick[0] = trick_card;
}
for (int i = 0; i + 1 < n_players; i++) {
......@@ -122,7 +124,7 @@ It can also play asynchronously.
_assignment.cards_adversaries[i] = cards;
if (current_trick < n_tricks
&& restricted_game.get_trick_card_of (current_trick, p, out trick_card,
out cnf, out cno, out cnu) == 0) {
out cnf, out cno, out cnu) == 0) {
_assignment.cards_trick[i + 1] = trick_card;
}
}
......@@ -136,6 +138,7 @@ It can also play asynchronously.
public void select_n_players (size_t n_players, bool with_call) {
Tarot.GameEvent e = new Tarot.GameEvent.alloc ();
if (e.set_setup (n_players, with_call) != 0) {
stderr.printf ("ICI 0\n");
GLib.Process.abort ();
}
add_event (e);
......@@ -162,6 +165,17 @@ It can also play asynchronously.
send_redraw ({});
}
public void select_bid (Tarot.Bid bid) {
Tarot.GameEvent e = new Tarot.GameEvent.alloc ();
if (e.set_bid (bid) != 0) {
GLib.Process.abort ();
}
add_event (e);
run ();
ask_bid (false, false, false, false, false);
send_redraw ({});
}
private void add_event (Tarot.GameEvent e) {
if (e.type () == Tarot.GameEventT.DISCARD_EVENT) {
var cards = new Tarot.CardArray.alloc ();
......@@ -217,6 +231,17 @@ It can also play asynchronously.
if (full_game.has_next () && full_game.next () != _assignment.myself) {
add_event (run_mcts ());
run ();
} else if (full_game.has_next ()) {
Tarot.Bid mini;
Tarot.Player next;
if (restricted_game.hint_bid (out next, out mini) == 0) {
assert (next == _assignment.myself);
ask_bid (true,
mini <= Tarot.Bid.TAKE,
mini <= Tarot.Bid.PUSH,
mini <= Tarot.Bid.STRAIGHT_KEEP,
mini <= Tarot.Bid.DOUBLE_KEEP);
}
}
}
......@@ -242,6 +267,21 @@ we only have to implement the callback to actually paint the game.
[GtkChild]
private Gtk.Box widget_deal;
[GtkChild]
private Gtk.Box widget_bid;
[GtkChild]
private Gtk.Button button_take;
[GtkChild]
private Gtk.Button button_push;
[GtkChild]
private Gtk.Button button_straight_keep;
[GtkChild]
private Gtk.Button button_double_keep;
[GtkChild]
private Gtk.Box player_information_others;
......@@ -283,6 +323,31 @@ we only have to implement the callback to actually paint the game.
engine.select_n_players (5, true);
}
[GtkCallback]
private void select_pass () {
engine.select_bid (Tarot.Bid.PASS);
}
[GtkCallback]
private void select_take () {
engine.select_bid (Tarot.Bid.TAKE);
}
[GtkCallback]
private void select_push () {
engine.select_bid (Tarot.Bid.PUSH);
}
[GtkCallback]
private void select_straight_keep () {
engine.select_bid (Tarot.Bid.STRAIGHT_KEEP);
}
[GtkCallback]
private void select_double_keep () {
engine.select_bid (Tarot.Bid.DOUBLE_KEEP);
}
public Window (Gtk.Application app) {
Object (application: app);
engine.render.connect (() => {
......@@ -317,6 +382,17 @@ we only have to implement the callback to actually paint the game.
widget_deal.hide ();
}
});
engine.ask_bid.connect ((show, take, push, strk, dblk) => {
if (show) {
button_take.sensitive = take;
button_push.sensitive = push;
button_straight_keep.sensitive = strk;
button_double_keep.sensitive = dblk;
widget_bid.show ();
} else {
widget_bid.hide ();
}
});
engine.run ();
}
}
......
This diff is collapsed.
Markdown is supported
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