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 ();
}
}
......
......@@ -12,66 +12,158 @@
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkBox" id="widget_deal">
<object class="GtkStack">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="homogeneous">True</property>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">3 players</property>
<object class="GtkBox" id="widget_deal">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="select_3_players" swapped="no"/>
<property name="can_focus">False</property>
<property name="homogeneous">True</property>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">3 players</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="select_3_players" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">4 players</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="select_4_players" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">5 players</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="select_5_players" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">5, call</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="select_5_players_call" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
<property name="name">page0</property>
<property name="title" translatable="yes">page0</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">4 players</property>
<object class="GtkBox" id="widget_bid">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="select_4_players" swapped="no"/>
<property name="can_focus">False</property>
<property name="homogeneous">True</property>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Pass</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="select_pass" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button_take">
<property name="label" translatable="yes">Take</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="select_take" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button_push">
<property name="label" translatable="yes">Push</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="select_push" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button_straight_keep">
<property name="label" translatable="yes">Straight</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="select_straight_keep" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button_double_keep">
<property name="label" translatable="yes">Double</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="select_double_keep" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="name">page1</property>
<property name="title" translatable="yes">page1</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">5 players</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="select_5_players" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">5, call</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="select_5_players_call" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
......
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