Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Tarot
tarot
Commits
8fa1125c
Commit
8fa1125c
authored
Oct 13, 2019
by
Vivien Kraus
Browse files
Revert "Cheaper game_copy_as"
This reverts commit
13e9904c
.
parent
dc770088
Changes
7
Hide whitespace changes
Inline
Side-by-side
src/libtarot/call/tarot/call_private.h
View file @
8fa1125c
...
...
@@ -42,7 +42,6 @@ extern "C"
static
int
call_trick_card
(
TarotCall
*
call
,
TarotPlayer
owner
,
TarotCard
c
);
static
int
call_doscard_card
(
TarotCall
*
call
,
TarotCard
c
);
static
int
call_forget_player
(
TarotCall
*
call
);
#ifdef __cplusplus
}
...
...
src/libtarot/call/tarot/call_private_impl.h
View file @
8fa1125c
...
...
@@ -178,7 +178,7 @@ call_owned_by (TarotCall * call, TarotPlayer owner, TarotCard c)
{
if
(
!
_call_get_has_started
(
call
)
||
!
call_card_known
(
call
))
{
return
1
;
return
0
;
}
if
(
c
==
_call_get_call
(
call
))
{
...
...
@@ -205,14 +205,3 @@ call_doscard_card (TarotCall * call, TarotCard c)
{
return
call_owned_by
(
call
,
_call_get_taker
(
call
),
c
);
}
static
int
call_forget_player
(
TarotCall
*
call
)
{
if
(
!
_call_get_has_started
(
call
)
||
!
call_card_known
(
call
))
{
return
1
;
}
_call_set_has_player
(
call
,
0
);
return
0
;
}
src/libtarot/doscard/tarot/doscard_private.h
View file @
8fa1125c
...
...
@@ -38,9 +38,6 @@ extern "C"
size_t
n_players
);
static
int
doscard_copy
(
TarotDoscardHandle
*
dest
,
const
TarotDoscardHandle
*
source
);
static
int
doscard_copy_as
(
TarotDoscardHandle
*
dest
,
const
TarotDoscardHandle
*
source
,
TarotPlayer
who
);
static
TarotBid
doscard_contract
(
const
TarotDoscardHandle
*
doscard
);
static
int
doscard_set_contract
(
TarotDoscardHandle
*
doscard
,
TarotBid
contract
);
...
...
src/libtarot/doscard/tarot/doscard_private_impl.h
View file @
8fa1125c
...
...
@@ -149,58 +149,6 @@ doscard_copy (TarotDoscardHandle * dest, const TarotDoscardHandle * source)
return
0
;
}
static
inline
int
doscard_copy_as
(
TarotDoscardHandle
*
dest
,
const
TarotDoscardHandle
*
source
,
TarotPlayer
who
)
{
assert
(
dest
->
n_players
==
source
->
n_players
);
if
(
doscard_copy
(
dest
,
source
)
!=
0
)
{
return
1
;
}
if
(
_doscard_get_discard_done
(
dest
)
&&
_doscard_get_contract
(
dest
)
<
TAROT_STRAIGHT_KEEP
)
{
int
fully_known
=
(
*
(
dest
->
discard
.
n
)
>=
dest
->
discard
.
n_max
);
/* If who is the taker and the discard is not fully known, then
* we have to abort */
if
(
doscard_taker
(
dest
)
==
who
&&
!
fully_known
)
{
return
1
;
}
/* If who is not the taker and the discard is fully known, then
* we need to restrict it */
if
(
doscard_taker
(
dest
)
!=
who
&&
fully_known
)
{
TarotCard
full_discard
[
6
];
size_t
n_full_discard
=
hand_get
(
&
(
dest
->
discard
),
6
,
full_discard
);
TarotCard
restricted_discard
[
6
];
size_t
n_restricted_discard
=
0
;
size_t
i
;
assert
(
n_full_discard
<=
6
);
for
(
i
=
0
;
i
<
n_full_discard
;
i
++
)
{
if
(
full_discard
[
i
]
>=
TAROT_PETIT
)
{
assert
(
full_discard
[
i
]
!=
TAROT_PETIT
);
assert
(
full_discard
[
i
]
!=
TAROT_TWENTYONE
);
assert
(
full_discard
[
i
]
!=
TAROT_EXCUSE
);
restricted_discard
[
n_restricted_discard
++
]
=
full_discard
[
i
];
}
}
if
(
hand_set
(
&
(
dest
->
discard
),
restricted_discard
,
n_restricted_discard
)
!=
0
)
{
assert
(
0
);
}
}
}
return
0
;
}
static
inline
int
doscard_start
(
TarotDoscardHandle
*
doscard
)
{
...
...
src/libtarot/game/tarot/game_private_impl.h
View file @
8fa1125c
...
...
@@ -302,92 +302,88 @@ game_copy (TarotGame * dest, const TarotGame * source)
static
inline
TarotGameError
game_copy_as
(
TarotGame
*
dest
,
const
TarotGame
*
source
,
TarotPlayer
who
)
{
TarotGameHandle
hdest
,
hsource
;
if
(
game_step
(
source
)
==
TAROT_END
)
{
game_copy
(
dest
,
source
);
return
TAROT_GAME_OK
;
}
game_initialize
(
dest
,
source
->
opt
.
n_players
,
source
->
opt
.
with_call
);
game_generalize
(
dest
,
&
hdest
);
game_generalize
((
TarotGame
*
)
source
,
&
hsource
);
game_set_dealt
(
&
hdest
,
who
);
game_set_step
(
&
hdest
,
game_get_step
(
&
hsource
));
if
(
hands_copy_as
(
&
(
hdest
.
hands
),
&
(
hsource
.
hands
),
who
)
!=
0
)
{
return
TAROT_GAME_NA
;
}
if
(
bids_copy
(
hdest
.
bids
,
hsource
.
bids
)
!=
0
)
{
assert
(
0
);
}
if
(
decls_copy
(
hdest
.
decls
,
hsource
.
decls
)
!=
0
)
{
assert
(
0
);
}
if
(
hsource
.
opt
.
with_call
)
{
if
(
call_copy
(
hdest
.
call
,
hsource
.
call
)
!=
0
)
{
assert
(
0
);
TarotGame
rebuilt
;
TarotGameIterator
i
;
const
TarotGameEvent
*
e
;
/* The number of players and call will be overwritten */
game_initialize
(
&
rebuilt
,
4
,
0
);
game_iterator_setup
(
&
i
,
source
);
while
((
e
=
game_iterator_next_value
(
&
i
))
!=
NULL
)
{
TarotPlayer
dealt
;
size_t
n
;
if
(
event_get_deal
(
e
,
&
dealt
,
&
n
,
0
,
0
,
NULL
)
==
TAROT_EVENT_OK
||
event_get_deal_all
(
e
,
&
n
,
0
,
0
,
NULL
)
==
TAROT_EVENT_OK
)
{
TarotGameEvent
my_deal
;
unsigned
int
data
[
78
];
TarotCard
my_hand
[
78
];
size_t
j
;
if
(
game_get_deal_of
(
source
,
who
,
&
n
,
0
,
78
,
my_hand
)
!=
TAROT_GAME_OK
)
{
return
TAROT_GAME_NA
;
}
assert
(
n
<=
78
);
for
(
j
=
0
;
j
<
n
;
j
++
)
{
data
[
j
]
=
my_hand
[
j
];
}
my_deal
.
n
=
n
;
my_deal
.
data
=
data
;
my_deal
.
t
=
TAROT_DEAL_EVENT
;
my_deal
.
u
.
deal
=
who
;
if
(
game_add_event
(
&
rebuilt
,
&
my_deal
)
!=
TAROT_GAME_OK
)
{
assert
(
0
);
}
}
}
if
(
doscard_copy_as
(
&
(
hdest
.
doscard
),
&
(
hsource
.
doscard
),
who
)
!=
0
)
{
return
TAROT_GAME_NA
;
}
if
(
handfuls_copy
(
hdest
.
handfuls
,
hsource
.
handfuls
)
!=
0
)
{
assert
(
0
);
}
if
(
tricks_copy
(
&
(
hdest
.
tricks
),
&
(
hsource
.
tricks
))
!=
0
)
{
assert
(
0
);
}
/* Now we need to know if the partner is still known. */
if
(
hsource
.
opt
.
with_call
&&
call_card_known
(
hsource
.
call
))
{
/* /who/ would forget the call if it was in the taker's hand.
* Moreover, it would know the call if it were in /who/'s
* cards */
TarotCard
called_card
=
call_card
(
hsource
.
call
);
const
TarotHand
*
hand
;
TarotPlayer
taker
=
bids_taker
(
hsource
.
bids
);
int
has_taker
=
bids_has_taker
(
hsource
.
bids
,
hsource
.
opt
.
n_players
);
if
(
has_taker
&&
hands_known
(
&
(
hsource
.
hands
),
taker
)
&&
call_partner_known
(
hdest
.
call
))
{
size_t
i
;
hand
=
&
(
hsource
.
hands
.
hands
[
taker
]);
for
(
i
=
0
;
i
<
*
(
hand
->
n
);
i
++
)
else
if
(
event_get_discard
(
e
,
&
n
,
0
,
0
,
NULL
)
==
TAROT_EVENT_OK
)
{
TarotGameEvent
my_discard
;
unsigned
int
data
[
6
];
TarotCard
my_cards
[
6
];
size_t
j
;
TarotPlayer
taker
;
if
(
game_get_taker
(
source
,
&
taker
)
!=
TAROT_GAME_OK
)
{
TarotCard
c
=
hand
->
buffer
[
i
];
if
(
c
==
called_card
)
assert
(
0
);
}
if
(
taker
==
who
)
{
if
(
game_get_full_discard
(
source
,
&
n
,
0
,
6
,
my_cards
)
!=
TAROT_GAME_OK
)
{
if
(
call_forget_player
(
hdest
.
call
)
!=
0
)
{
assert
(
0
);
}
return
TAROT_GAME_NA
;
}
}
}
if
(
!
call_partner_known
(
hdest
.
call
))
{
size_t
i
;
hand
=
&
(
hdest
.
hands
.
hands
[
who
]);
for
(
i
=
0
;
i
<
*
(
hand
->
n
);
i
++
)
else
{
TarotCard
c
=
hand
->
buffer
[
i
];
if
(
c
==
called_card
)
if
(
game_get_public_discard
(
source
,
&
n
,
0
,
6
,
my_cards
)
!=
TAROT_GAME_OK
)
{
if
(
call_owned_card
(
hdest
.
call
,
who
,
c
)
!=
0
)
{
assert
(
0
);
}
return
TAROT_GAME_NA
;
}
}
assert
(
n
<=
6
);
for
(
j
=
0
;
j
<
6
;
j
++
)
{
data
[
j
]
=
my_cards
[
j
];
}
my_discard
.
n
=
n
;
my_discard
.
data
=
data
;
my_discard
.
t
=
TAROT_DISCARD_EVENT
;
if
(
game_add_event
(
&
rebuilt
,
&
my_discard
)
!=
TAROT_GAME_OK
)
{
assert
(
0
);
}
}
else
if
(
game_add_event
(
&
rebuilt
,
e
)
!=
TAROT_GAME_OK
)
{
assert
(
0
);
}
}
game_copy
(
dest
,
&
rebuilt
);
return
TAROT_GAME_OK
;
}
...
...
src/libtarot/hands/tarot/hands_private.h
View file @
8fa1125c
...
...
@@ -37,8 +37,6 @@ extern "C"
static
void
hands_initialize
(
TarotHandsHandle
*
hands
,
size_t
n_players
);
static
void
hands_copy
(
TarotHandsHandle
*
dest
,
const
TarotHandsHandle
*
source
);
static
int
hands_copy_as
(
TarotHandsHandle
*
dest
,
const
TarotHandsHandle
*
source
,
TarotPlayer
who
);
static
int
hands_known
(
const
TarotHandsHandle
*
hands
,
TarotPlayer
player
);
static
int
hands_set
(
TarotHandsHandle
*
hands
,
TarotPlayer
player
,
const
TarotHand
*
hand
);
...
...
src/libtarot/hands/tarot/hands_private_impl.h
View file @
8fa1125c
...
...
@@ -102,28 +102,6 @@ hands_copy (TarotHandsHandle * dest, const TarotHandsHandle * source)
}
}
static
inline
int
hands_copy_as
(
TarotHandsHandle
*
dest
,
const
TarotHandsHandle
*
source
,
TarotPlayer
who
)
{
size_t
i
=
0
;
assert
(
dest
->
n_players
==
source
->
n_players
);
if
(
!
hands_known
(
source
,
who
))
{
return
1
;
}
for
(
i
=
0
;
i
<
source
->
n_players
;
++
i
)
{
dest
->
known
[
i
]
=
0
;
}
dest
->
known
[
who
]
=
1
;
if
(
hand_copy
(
&
(
dest
->
hands
[
who
]),
&
(
source
->
hands
[
who
]))
!=
0
)
{
assert
(
0
);
}
return
0
;
}
static
inline
int
hands_known
(
const
TarotHandsHandle
*
hands
,
TarotPlayer
player
)
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment