// This file is part of Timmi. // // Timmi 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. #ifndef TIMMILOGIC_HH #define TIMMILOGIC_HH #include #include #include #include #include //----------------- // Simple datatypes enum MoveType {NOMOVE, PICKUP, HIT, BEAT, MOVE}; struct Move { int player; MoveType movetype; Card owncard; Card othercard; // Only with movetype == BEAT }; //-------------------- // GameState datatypes enum PlayerState {ACTIVE, DISCONNECTED, OBSERVER}; struct Player { int id; std::string name; std::vector hand; PlayerState state; bool let_go_over; }; struct GameState { std::map players; std::vector table; int turn; time_t time_to_go_over; time_t time_game_started; std::vector deck; std::vector winners; Card trump; int c_cards_in_hand; int c_over_delay; int c_deck_count; int c_allow_jokers; }; //---------------------------- // GameState related functions // Apply move, assume legal void apply_move(GameState &, const Move &); enum OverType {NOT_OVER = 0, OVER_CANTADD, OVER_LETGOOVER, OVER_TIMEOUT}; // All players that could add let go over, or timeout OverType can_go_over(const GameState &); // Check if someone has won and make them inactive void check_winners(GameState &); // Fill hands of active players void fill_hands(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 &); // Reset let_go_over -variables when board state changes void reset_let_go_over(GameState &); // Init deck, fill hands, init turn void start_game(GameState &); #endif