back to scratko.xyz
aboutsummaryrefslogtreecommitdiff
path: root/client/card_stack.c
diff options
context:
space:
mode:
authorscratko <m@scratko.xyz>2024-08-14 02:35:56 +0300
committerscratko <m@scratko.xyz>2024-08-14 02:35:56 +0300
commit880b8be2c28d761505b2eecc1386919d5add6f2f (patch)
tree63e965c3f82bcd09bb07baf9b669a736293dddc7 /client/card_stack.c
parenta2d696dea797faaa3157046c8ae89cd70e965bff (diff)
downloaddurak-880b8be2c28d761505b2eecc1386919d5add6f2f.tar.gz
durak-880b8be2c28d761505b2eecc1386919d5add6f2f.tar.bz2
durak-880b8be2c28d761505b2eecc1386919d5add6f2f.zip
Global fixes v1.0
Defense hint now only takes into account unbeaten cards. The client accounts for sticky data in one packet via TCP. Changed delimiter when sending data related to cards on the table and the queue (from '0' to '='). Accepting cards from a client (verification_client_input.c) is heavily patched. Cards are taken from the stack at the hint's prompt. Added pop_stack(). The trump card is retrieved from the end of the array. Changed the check of the defender's ability to beat all cards.
Diffstat (limited to 'client/card_stack.c')
-rw-r--r--client/card_stack.c39
1 files changed, 32 insertions, 7 deletions
diff --git a/client/card_stack.c b/client/card_stack.c
index 5d0700b..d9dc273 100644
--- a/client/card_stack.c
+++ b/client/card_stack.c
@@ -81,11 +81,32 @@ void add_hint_letters_stack(player_cards deck)
}
}
+static int check_no_attackers_cards_marked(player_cards deck)
+{
+ while(deck) {
+ if(deck->is_usable)
+ return 0;
+ deck = deck->next;
+ }
+ return 1;
+}
+
+static void mark_all_card_stack(player_cards deck)
+{
+ player_cards tmp_deck = deck;
+
+ while(tmp_deck) {
+ tmp_deck->is_usable = 1;
+ tmp_deck = tmp_deck->next;
+ }
+}
+
void mark_card_for_attackers_stack(player_cards deck)
{
char *card = NULL, *found_card;
struct card_stack_item *search_deck = NULL;
int target_rank, found_rank;
+ player_cards tmp_begin_deck = deck;
while(deck) {
/* is the card already marked? */
@@ -103,12 +124,16 @@ void mark_card_for_attackers_stack(player_cards deck)
}
found_card = search_deck->str;
found_rank = convert_rank_to_int(found_card);
- if(found_rank == target_rank)
+ if(found_rank == target_rank) {
+ deck->is_usable = 1;
search_deck->is_usable = 1;
+ }
search_deck = search_deck->next;
}
deck = deck->next;
}
+ if(check_no_attackers_cards_marked(tmp_begin_deck))
+ mark_all_card_stack(tmp_begin_deck);
}
#if 0
static int is_card_beaten(const char *attack_card, const char *defend_card,
@@ -142,8 +167,8 @@ void mark_card_for_defenders_stack(player_cards deck,
while(deck) {
for(i = 0; i <= cot->card_arr_idx; ++i)
- if((i == 0 || !(i % 3)) && is_card_beaten(cot->card_arr[i],
- deck->str, trump_suit))
+ if(((i == 0 || !(i % 3)) && cot->card_arr[i+2][0] == '-') &&
+ is_card_beaten(cot->card_arr[i], deck->str, trump_suit))
{
deck->is_usable = 1;
break;
@@ -179,15 +204,15 @@ void mark_card_for_tossing_stack(player_cards deck, struct cards_on_table *cot)
deck = deck->next;
}
}
-
-int card_search_by_letter(player_cards deck, int letter)
+/* rename: and_unmarked */
+char* card_search_by_letter(player_cards deck, int letter)
{
while(deck) {
if(deck->tip == letter && deck->is_usable) {
deck->is_usable = 0;
- return 1;
+ return deck->str;
}
deck = deck->next;
}
- return 0;
+ return NULL;
}