Commit 91bb30dd authored by Vivien Kraus's avatar Vivien Kraus
Browse files

Fix indentation.

parent fe48dee5
......@@ -79,10 +79,12 @@ INDENTED_FILES = \
$(check_deal_SOURCES) \
$(check_deal_cpp_SOURCES)
EXTRA_DIST = indent.stamp
../lib/libgnu.la:
(cd ../lib && $(MAKE) libgnu.la)
$(abs_srcdir)/indent.stamp: $(INDENTED_FILES)
indent.stamp: $(INDENTED_FILES)
if HAVE_INDENT
(cd $(abs_srcdir) && $(INDENT) -gnu $(INDENTED_FILES))
echo "Done!" > $(abs_srcdir)/indent.stamp
......
......@@ -2,7 +2,7 @@
/* In case cards is not sorted, the complexity is a little higher */
static int
is_present_before (const TarotCard *cards, unsigned int i)
is_present_before (const TarotCard * cards, unsigned int i)
{
unsigned int j = 0;
for (j = 0; j < i; ++j)
......@@ -14,7 +14,7 @@ is_present_before (const TarotCard *cards, unsigned int i)
}
static int
no_doubles_unsorted (const TarotCard *cards, unsigned int n)
no_doubles_unsorted (const TarotCard * cards, unsigned int n)
{
unsigned int i = 1;
for (i = 1; i < n; ++i)
......@@ -26,16 +26,16 @@ no_doubles_unsorted (const TarotCard *cards, unsigned int n)
}
int
_tarot_no_doubles (const TarotCard *cards, unsigned int n)
_tarot_no_doubles (const TarotCard * cards, unsigned int n)
{
unsigned int i = 1;
for (i = 1; i < n; ++i)
{
if (cards[i] > cards[i-1])
if (cards[i] > cards[i - 1])
{
/* continue */
}
else if (cards[i] == cards[i-1])
else if (cards[i] == cards[i - 1])
{
return 0;
}
......
#include "tarot_private.h"
static int
has_petit (const TarotCard *cards,
unsigned int n)
has_petit (const TarotCard * cards, unsigned int n)
{
unsigned int i = 0;
for (i = 0; i < n; ++i)
......@@ -16,8 +15,7 @@ has_petit (const TarotCard *cards,
}
static int
has_another_trump_or_excuse (const TarotCard *cards,
unsigned int n)
has_another_trump_or_excuse (const TarotCard * cards, unsigned int n)
{
unsigned int i = 0;
for (i = 0; i < n; ++i)
......@@ -31,9 +29,7 @@ has_another_trump_or_excuse (const TarotCard *cards,
}
int
_tarot_no_petit_sec (const TarotCard *cards,
unsigned int n)
_tarot_no_petit_sec (const TarotCard * cards, unsigned int n)
{
return (!has_petit (cards, n)
|| has_another_trump_or_excuse (cards, n));
return (!has_petit (cards, n) || has_another_trump_or_excuse (cards, n));
}
......@@ -17,50 +17,48 @@ check ()
game = (TarotGame *) buffer;
/* First check: there are not enough cards */
{
TarotCard not_enough[] =
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
TarotCard not_enough[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };
assert (tarot_game_check_deal_one (game, 14, not_enough) == 0);
}
/* Second check: there are too many cards */
{
TarotCard too_many[] =
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
assert (tarot_game_check_deal_one (game, 16, too_many) == 0);
}
/* There is an obvious double */
{
TarotCard double_zero[] =
{0, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
{ 0, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
assert (tarot_game_check_deal_one (game, 15, double_zero) == 0);
}
/* There is a double but the cards are not sorted */
{
TarotCard double_zero[] =
{0, 2, 0, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
{ 0, 2, 0, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
assert (tarot_game_check_deal_one (game, 15, double_zero) == 0);
}
/* There is a double but the cards are not sorted, other */
{
TarotCard double_zero[] =
{0, 0, 3, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
{ 0, 0, 3, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
assert (tarot_game_check_deal_one (game, 15, double_zero) == 0);
}
/* There is a petit sec, with sorted cards */
{
TarotCard petit_sec[] =
{0, 1, 3, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 56};
{ 0, 1, 3, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 56 };
assert (tarot_game_check_deal_one (game, 15, petit_sec) == 0);
}
/* There is a petit sec, but the cards are not sorted */
{
TarotCard petit_sec[] =
{0, 1, 3, 2, 56, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
{ 0, 1, 3, 2, 56, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
assert (tarot_game_check_deal_one (game, 15, petit_sec) == 0);
}
/* OK (not petit sec since there is the excuse) */
{
TarotCard ok[] =
{0, 1, 3, 2, 56, 5, 6, 7, 8, 9, 77, 11, 12, 13, 14};
TarotCard ok[] = { 0, 1, 3, 2, 56, 5, 6, 7, 8, 9, 77, 11, 12, 13, 14 };
assert (tarot_game_check_deal_one (game, 15, ok) == 1);
}
free (buffer);
......
......@@ -13,50 +13,50 @@ check ()
game g (5, true);
/* First check: there are not enough cards */
{
const vector <card> not_enough =
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
const vector < card > not_enough =
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };
assert (!g.check_deal_one (not_enough));
}
/* Second check: there are too many cards */
{
const vector <card> too_many =
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
const vector < card > too_many =
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
assert (!g.check_deal_one (too_many));
}
/* There is an obvious double */
{
const vector <card> double_zero =
{0, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
const vector < card > double_zero =
{ 0, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
assert (!g.check_deal_one (double_zero));
}
/* There is a double but the cards are not sorted */
{
const vector <card> double_zero =
{0, 2, 0, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
const vector < card > double_zero =
{ 0, 2, 0, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
assert (!g.check_deal_one (double_zero));
}
/* There is a double but the cards are not sorted, other */
{
const vector <card> double_zero =
{0, 0, 3, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
const vector < card > double_zero =
{ 0, 0, 3, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
assert (!g.check_deal_one (double_zero));
}
/* There is a petit sec, with sorted cards */
{
const vector <card> petit_sec =
{0, 1, 3, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 56};
const vector < card > petit_sec =
{ 0, 1, 3, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 56 };
assert (!g.check_deal_one (petit_sec));
}
/* There is a petit sec, but the cards are not sorted */
{
const vector <card> petit_sec =
{0, 1, 3, 2, 56, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
const vector < card > petit_sec =
{ 0, 1, 3, 2, 56, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
assert (!g.check_deal_one (petit_sec));
}
/* OK (not petit sec since there is the excuse) */
{
const vector <card> ok =
{0, 1, 3, 2, 56, 5, 6, 7, 8, 9, 77, 11, 12, 13, 14};
const vector < card > ok =
{ 0, 1, 3, 2, 56, 5, 6, 7, 8, 9, 77, 11, 12, 13, 14 };
assert (g.check_deal_one (ok));
}
}
......
......@@ -176,7 +176,8 @@ extern "C"
unsigned int i_trick, TarotPlayer p,
TarotHint * hint);
int tarot_game_check_deal_one (const TarotGame *game, unsigned int n, const TarotCard *cards);
int tarot_game_check_deal_one (const TarotGame * game, unsigned int n,
const TarotCard * cards);
#ifdef __cplusplus
}
......@@ -186,7 +187,8 @@ extern "C"
#include <utility>
#include <cassert>
namespace tarot {
namespace tarot
{
typedef TarotCard card;
typedef TarotNumber number;
typedef TarotSuit suit;
......@@ -201,23 +203,19 @@ namespace tarot {
typedef TarotTeam team;
typedef TarotHint hint;
typedef TarotPlayer player;
inline int
init ()
inline int init ()
{
return tarot_init ();
}
inline std::string
libtarot_version ()
inline std::string libtarot_version ()
{
return std::string (tarot_libtarot_version ());
}
inline std::string
strerror (error err)
inline std::string strerror (error err)
{
return std::string (tarot_strerror (err));
}
inline card
of (number n, suit s)
inline card of (number n, suit s)
{
card ret;
error err = tarot_of (n, s, &ret);
......@@ -227,116 +225,110 @@ namespace tarot {
}
throw err;
}
inline std::pair <number, suit>
decompose (card c)
{
number n;
suit s;
error err = tarot_decompose (c, &n, &s);
if (err == TAROT_OK)
{
return std::pair <number, suit> (n, s);
}
throw err;
}
class game
inline std::pair < number, suit > decompose (card c)
{
public:
game (unsigned int n_players, bool with_call)
{
const size_t required = tarot_game_init (n_players, with_call, 0, NULL);
char *memory = new char[required];
assert (memory != nullptr);
assert (tarot_game_init (n_players, with_call, required, memory) == required);
m_addr = (TarotGame *) memory;
}
virtual ~game ()
{
char *memory = (char *) m_addr;
delete[] memory;
}
void
options (unsigned int &n_players, bool &with_call) const
number n;
suit s;
error err = tarot_decompose (c, &n, &s);
if (err == TAROT_OK)
{
int w;
tarot_game_options (m_addr, &n_players, &w);
with_call = (w != 0);
return std::pair < number, suit > (n, s);
}
throw err;
}
class game
{
public:
game (unsigned int n_players, bool with_call)
{
const size_t required = tarot_game_init (n_players, with_call, 0, NULL);
char *memory = new char[required];
assert (memory != nullptr);
assert (tarot_game_init (n_players, with_call, required, memory) ==
required);
m_addr = (TarotGame *) memory;
}
virtual ~ game ()
{
char *memory = (char *) m_addr;
delete[]memory;
}
void options (unsigned int &n_players, bool & with_call) const
{
int w;
tarot_game_options (m_addr, &n_players, &w);
with_call = (w != 0);
}
void
state (step &step, unsigned int &i_trick, unsigned int &n_cards_in_trick) const
state (step & step, unsigned int &i_trick,
unsigned int &n_cards_in_trick) const
{
tarot_game_state (m_addr, &step, &i_trick, &n_cards_in_trick);
}
std::vector <card>
cards (player p) const
{
std::vector<card> ret;
unsigned int n;
const card *c_mem = tarot_game_cards (m_addr, p, &n);
ret.resize (n);
for (unsigned int i = 0; i < n; ++i)
{
ret[i] = c_mem[i];
}
return ret;
}
std::vector <bid_t>
bids (player &taker) const
{
std::vector <bid_t> ret;
unsigned int n;
const bid_t *bids = tarot_game_bids (m_addr, &n, &taker);
ret.resize (n);
for (unsigned int i = 0; i < n; ++i)
{
ret[i] = bids[i];
}
return ret;
}
bool
decl (player &p) const
{
return (tarot_game_decl (m_addr, &p) != 0);
}
call_t
call (card &call, player &partner) const
std::vector < card > cards (player p) const
{
std::vector < card > ret;
unsigned int n;
const card *c_mem = tarot_game_cards (m_addr, p, &n);
ret.resize (n);
for (unsigned int i = 0; i < n; ++i)
{
ret[i] = c_mem[i];
}
return ret;
}
std::vector < bid_t > bids (player & taker) const
{
std::vector < bid_t > ret;
unsigned int n;
const bid_t *bids = tarot_game_bids (m_addr, &n, &taker);
ret.resize (n);
for (unsigned int i = 0; i < n; ++i)
{
ret[i] = bids[i];
}
return ret;
}
bool decl (player & p) const
{
return (tarot_game_decl (m_addr, &p) != 0);
}
call_t call (card & call, player & partner) const
{
return tarot_game_call (m_addr, &call, &partner);
}
dog_t
dog (std::vector <card> &vec_cards) const
dog_t dog (std::vector < card > &vec_cards) const
{
const card *cards = NULL;
unsigned int n;
dog_t ret = tarot_game_dog (m_addr, (const card **) (&cards), &n);
vec_cards.resize (n);
vec_cards.resize (n);
for (unsigned int i = 0; i < n; ++i)
{
vec_cards[i] = cards[i];
}
return ret;
}
discard_t
discard (std::vector <card> &vec_cards) const
discard_t discard (std::vector < card > &vec_cards) const
{
const card *cards = NULL;
unsigned int n;
discard_t ret = tarot_game_discard (m_addr, (const card **) (&cards), &n);
vec_cards.resize (n);
discard_t ret =
tarot_game_discard (m_addr, (const card **) (&cards), &n);
vec_cards.resize (n);
for (unsigned int i = 0; i < n; ++i)
{
vec_cards[i] = cards[i];
}
return ret;
}
handful_t
handful (player p, std::vector <card> &vec_cards) const
handful_t handful (player p, std::vector < card > &vec_cards) const
{
unsigned int n;
card data[22];
card data[22];
handful_t ret = tarot_game_handful (m_addr, p, &n, data, 22);
assert (n <= 22);
vec_cards.resize (n);
assert (n <= 22);
vec_cards.resize (n);
for (unsigned int i = 0; i < n; ++i)
{
vec_cards[i] = data[i];
......@@ -344,26 +336,28 @@ namespace tarot {
return ret;
}
void
trick (unsigned int i, player &leader, bool &has_lead_suit, suit &suit, unsigned int &n_played, player &taker, team &team) const
trick (unsigned int i, player & leader, bool & has_lead_suit,
suit & suit, unsigned int &n_played, player & taker,
team & team) const
{
int hls;
tarot_game_trick (m_addr, i, &leader, &hls, &suit, &n_played, &taker, &team);
has_lead_suit = (hls != 0);
tarot_game_trick (m_addr, i, &leader, &hls, &suit, &n_played, &taker,
&team);
has_lead_suit = (hls != 0);
}
card
trick_card (unsigned int i, player p, hint *h) const
card trick_card (unsigned int i, player p, hint * h) const
{
return tarot_game_trick_card (m_addr, i, p, h);
}
bool
check_deal_one (const std::vector<card> &cards)
bool check_deal_one (const std::vector < card > &cards)
{
return (tarot_game_check_deal_one (m_addr, cards.size (), cards.data ()) != 0);
return (tarot_game_check_deal_one (m_addr, cards.size (), cards.data ())
!= 0);
}
private:
TarotGame *m_addr;
TarotGame * m_addr;
};
}
#endif /* cplusplus */
#endif /* cplusplus */
#endif /* not H_TAROT_INCLUDED */
#endif /* not H_TAROT_INCLUDED */
#include "tarot_private.h"
int
tarot_game_check_deal_one (const TarotGame *game,
unsigned int n,
const TarotCard *cards)
tarot_game_check_deal_one (const TarotGame * game,
unsigned int n, const TarotCard * cards)
{
unsigned int n_cards, n_dog;
_tarot_count_cards (game->n_players, &n_cards, &n_dog);
return (n_cards == n
&& _tarot_no_doubles (cards, n)
&& _tarot_no_petit_sec (cards, n));
&& _tarot_no_doubles (cards, n) && _tarot_no_petit_sec (cards, n));
}
......@@ -32,15 +32,15 @@ extern "C"
int _tarot_has_lead_suit (const TarotCard * cards, unsigned int n,
TarotSuit * suit);
const char * _tarot_localedir();
const char *_tarot_localedir ();
/* Return 0 if no trumps */
TarotNumber _tarot_strongest_trump (const TarotCard * cards,
unsigned int n);
int _tarot_no_doubles (const TarotCard *cards, unsigned int n);
int _tarot_no_doubles (const TarotCard * cards, unsigned int n);
int _tarot_no_petit_sec (const TarotCard *cards, unsigned int n);
int _tarot_no_petit_sec (const TarotCard * cards, unsigned int n);
struct TarotGame
{
......
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