/************************************************************************** * ___ __ __ ___ _ __ * * / _ \\ \/ // _ \ '_ \ * * | (_) |> <| __/ | | | * * \___//_/\_\\___|_| |_| * * * * The card game * * * * Copyright (C) 2011, Reiner Herrmann * * Mario Kilies * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 3 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see . * * * **************************************************************************/ #include "card_stack.h" #include #include /** * Calculates the points of a card stack. This will be the sum of the points of all cards contained in the card stack. * @param[in] cs The card stack fir which the points will be calculated */ uint32_t card_stack_get_points(const card_stack_t *cs) { assert(cs != NULL); uint32_t points = 0; for(uint8_t i = 0; i < MAX_CARD_STACK_SIZE; i++) { if(cs->cards[i] > 0) points += card_get_points(cs->cards[i]); } return points; } /** * Determines the uppermost card on a card stack. The card will not be removed from the stack. * @param[in] cs The card stack from which the uppermost card will be retrieved */ const card card_stack_top(const card_stack_t *cs) { assert(cs != NULL); for(int i = 0; i < MAX_CARD_STACK_SIZE; i++) { card cur = cs->cards[MAX_CARD_STACK_SIZE-1-i]; if(cur != 0) return cur; } return 0; } /** * Places a card on top of a card stack. * @param[in] cs The card stack to place the card on * @param[in] c The card to place */ void card_stack_push(card_stack_t *cs, const card c) { assert(cs != NULL); for(int i = 0; i < MAX_CARD_STACK_SIZE; i++) { if(cs->cards[i] != 0) continue; cs->cards[i] = c; break; } } /** * Replaces a card stack with a single card. All cards within the card stack will be removed and the first card will be set to a given card. * @param[in] cs The card stack to replace * @param[in] new_card The new first card */ void card_stack_replace(card_stack_t *cs, const card new_card) { assert(cs != NULL); for(int i = 0; i < MAX_CARD_STACK_SIZE; i++) cs->cards[i] = 0; cs->cards[0] = new_card; }