//*****************************************
// Filename: game.h
// Author: Aaron Rogers
// Updated: 11/04/02
// Purpose: Hearts game AI
//*****************************************
// This file is part of HAM Tutorial Hearts
// Copyright 2002 Aaron Rogers
// See README.txt for more information
//*****************************************


#ifndef GAME_H
#define GAME_H

// Library Includes
#include "ai.h"
#include "mygba.h"

// Game Winner
#define NO_WINNER 0;
#define PLAYER1 1;
#define PLAYER2 2;

// Struct used for mouse pointers & squares on the board
struct Object
{
  u8 x_pos; // X-Position of the Object
  u8 y_pos; // Y-Position of the Object
  u8 slot; // Holds the slot in memory for the Object
};

// Struct used for playing cards
struct Card
{
  u8 number; // 2 - 14 (11 = J, ...)
  u8 suit; // 0 = Spade, 1 = Club, 2 = Heart, 3 = Diamond
};


class HEARTS
{
public:
  // Game States: 0 1 2 3 4 5 6
  enum states {START, MAIN, PLAY, SCORE, FINISH, OPTIONS, QUIT};
  
  // Default Constructor
  HEARTS();

  // Functions
  void init(); // Initialize the game

  // START functions
  void start_screen_init(); // Initialize the start screen
  void start_screen_query_keys(); // Check for input
  void start_screen_deinit(); // Deinitialize the start screen

  // MAIN functions
  void main_screen_init(); // Initialize the main screen
  void main_screen_query_keys(); // Check for input
  void main_screen_redraw(); // Update main screen
  void main_screen_deinit(); // Deinitialize the main screen
  
  // PLAY functions
  void in_game_init(); // Initialize game playing
  void in_game_query_keys(); // Check for input
  void in_game_redraw(); // Update sprites
  void in_game_deinit(); // Deinitialize game playing

  // SCORE functions
  void score_init(); // Initialize the scoring screen
  void score_query_keys(); // Check for input
  void score_redraw(); // Update sprites
  void score_deinit(); // Deinitialize score screen

  // FINISH functions
  void finish_init(); // Initialize the end of a game
  void finish_query_keys(); // Check for input
  void finish_deinit(); // Deitialize the end of a game

  // OPTIONS functions
  void options_init(); // Initialize the options screen
  void options_query_keys(); // Check for input
  void options_redraw(); // Update sprites
  void options_deinit(); // Deinitialize the options screen
  
  // Other functions
  bool is_winner(); // Checks to see if there was a winner
  states gs(); // Returns 'game_state'
  u8 gt(); // Returns 'turn'
  //u8 gw(); // Returns 'winner'
  u8 gsl(); // Returns 'suit_lead'
  u8 gl(); // Returns 'leader'
  u8 gtc(); // Returns 'trick_cards'
  u8 gtr(); // Returns 'tricks'

  u8 trick_number(u8 slot);
  u8 trick_suit(u8 slot);
  u8 player_number(u8 player, u8 slot);
  u8 player_suit(u8 player, u8 slot);

  u32 convert_card(u8 number, u8 suit); // Convert to array spot of card_deck bitmap
  u32 convert_card_64(u8 number, u8 suit); // Convert to array spot of card_deck_64 bitmap
  u32 convert_number(u8 number); // Convert to array spot of number bitmap
  void hand_sort(u8 player); // Sort a Player's hand
  u8 sort_card_value(u8 number, u8 suit);
  void setup_leader(); // Who goes first
  u8 trick_winner(); // Who won the trick
  void score_trick(); // Score each trick

  bool valid_move(u8 player, u8 slot); // Is it a valid move
  void pass_cards();

  // AI related functions
  void add_to_passed_cards(u8 slot, u8 value);
  void add_card(u8 player, u8 slot, u8 number, u8 suit);
  void add_card_to_trick(u8 slot);
  void remove_card(u8 player, u8 slot);
  Card get_card(u8 player, u8 slot);

  bool is_first_trick();

private:
  // Variables
  states game_state; // Current game state
  u8 curr_screen; // The current start screen slide
  u8 last_screen;
  u8 turn; // Current turn, 1 = Player 1, 2 = Player 2
  u8 winner; // The game winner, 0 = No one, 1 = P1, 2 = P2
  u8 players; // Number of players
  u8 skill; // 1: novice ... 5: expert
  u8 sound; // 0: off, 1: on
  u8 music; // 0: off, 1: on
  u32 vbl_count; // Keeps track of how many VBLs have passed
  u32 flash_count;
  map_fragment_info_ptr bg_one; // Used for one BG in any function
  Object P1[13]; // Used to show the players hand
  Object P2[13]; // Used to show the players hand
  Object P3[13]; // Used to show the players hand
  Object P4[13]; // Used to show the players hand
  Object *obj; // Pointer to an Object
  Object T[4]; // The trick objects
  Object HSt[4]; // Hand Score objects 'tens'
  Object HSo[4]; // Hand Score objects 'ones'
  Object HSh[4]; // Hand Score objects 'hundreds'
  Object TSt[4]; // Total Score objects 'tens'
  Object TSo[4]; // Total Score objects 'ones'
  Object TSh[4]; // Total Score objects 'hundreds'
  Object pass_xxx[1];
  Object opts[3]; // 0: skill level, 1: sound, 2: music
  Object Card_64[1];

  Card Deck[52]; // The deck of cards for the game
  Card Player1[13]; // Player 1's hand
  Card Player2[13]; // Player 2's hand
  Card Player3[13]; // Player 3's hand
  Card Player4[13]; // Player 4's hand
  Card Trick[4]; // The trick cards

  u8 Passed_Cards[12]; // P1:0-2, P2:3-5, P3:6-8, P4:9-11
  u8 Hand_Score[4]; // Keeps track of player's hand scores
  u8 Total_Score[4]; // Keeps track of player's total scores

  u8 deck_spot; // Used to cycle through the deck
  u8 my_pnt_card; // Keeps track of which card the pointer is on
  u8 pass_three; // How many cards have been chosen to pass
  u8 round; // 0:left, 1:right, 2:across, 3:no pass
  u8 suit_lead; // The suit that was lead
  u8 leader; // The person to go first
  u8 ai_card; // The card the computer chooses to play
  u8 trick_cards; // Number of trick cards
  u8 tricks; // Number of tricks (1-13)
  u32 graphic_spot;

  bool choose_three; // Have the three cards to pass been chosen
  bool first_trick; // First trick
  bool hearts_broken; // Have any Hearts been played yet
  bool seed; // Reseed the random function
  bool create_pass_xxx;
  bool delete_go;
  bool big_card;
  u8 flash_pass_xxx; // 0: not_created, 1: flash on, 2: flash off
  u8 flash_go; // 0: not_created, 1: flash on, 2: flash off

}; // End of class HEARTS


// Other (non-class) Functions
bool anykey();


#endif