#ifndef TIMMILOGIC_HH #define TIMMILOGIC_HH #include #include #include #include //----------------- // Simple datatypes enum Suit {NOSUIT = 0, CLUBS, SPADES, HEARTS, DIAMONDS}; enum Rank {NORANK = 0, ACE = 1, R2 = 2, R3 = 3, R4 = 4, R5 = 5, R6 = 6, \ R7 = 7, R8 = 8, R9 = 9, R10 = 10, JACK = 11, QUEEN = 12, KING = 13}; class Card { public: Suit suit; Rank rank; bool operator==(const Card &other) const; }; enum MoveType {PICKUP, HIT, BEAT, MOVE, OVER}; struct Move { int player; MoveType movetype; Card owncard; Card othercard; // Only with movetype == BEAT }; struct TableCard { Card tobeat; Card beater; }; //-------------------- // GameState datatypes enum PlayerState {PREGAME, INGAME, DISCONNECTED, OBSERVER}; struct Player { int id; std::string name; std::vector hand; PlayerState state; bool let_go_over; ClientSocket *socket; }; struct GameState { std::vector players; std::vector table; int turn; time_t time_to_go_over; std::vector deck; std::vector winners; Suit trump; int c_cards_in_hand; int c_over_delay; int c_deck_count; }; //----------------------- // Card-related functions // Card has actual rank and suit, not NORANK nor NOSUIT bool is_card(const Card &); // First card can be beaten with second, when suit is trump bool can_beat(const Card &, const Card &, Suit); // First rank is higher than second bool rank_higher(Rank, Rank); //----------------------------------- // Vector of cards -related functions // Add one full deck of cards to vector void init_deck(std::vector &); // Fill hands of active players void fill_hands(GameState &); // Remove first occurring card from a vector of cards void remove_card(std::vector &, Card); // Shuffle vector of cards void shuffle_deck(std::vector &deck); //---------------------------------------- // Vector of TableCards -related functions // All cards on table have been beaten bool all_beaten(const std::vector &); // Card to beat is on table and is not beaten yet bool card_on_table(const std::vector &, const Card &); // Card on table are of only one rank and none are beaten bool one_rank_only(const std::vector &, Rank); //---------------------------- // GameState related functions // Apply move, assume legal void apply_move(GameState &, const Move &); // All players that could add let go over, or timeout bool can_go_over(const GameState &); // Check if someone has won and make them inactive void check_winners(GameState &); // Game is over bool game_ended(const GameState &); // Is move legal in current situation? bool legal_move(const GameState &, const Move &); // May card be added to table - count unbeaten cards and check rank exists bool may_add_card(const GameState &, const Card &); // Returns index of player next in turn int next_turn(const GameState &); // Check if player can add a card to table bool player_can_add(const Player &, const GameState &); // Put table over void put_over(GameState &); // Init deck, fill hands, init turn void start_game(GameState &); // All beaten - init go over delay void start_go_over(GameState &); #endif