//AI.java
//Game Initialization and Player-Turn group
//Carrie Hazelton, Aileen Platt, Ameilia Apolonio, Lauren Hamburg
//CS371 HW4

import javax.swing.*;
import java.util.Vector;

/**
 * This class models all aspects of the AI."
 * You can read more about the class
 * AI in its <A href="doc-files/GameGroup.html#ai"">
 * design documentation</A>.
 */

public class AI extends Player{


   /**
    * Initial shot at constructor for AI player; requires:
    *  1) reference to the units owned by AI player
    *  2) number of force points accounted to AI player
    *         can be 0 if not applicable
    *  3) reference to the planets ONLY that the AI controls
    */

   public void AI( Group AIUnits, int forcePts, Planet Iplanets[]){
      playerUnits = AIUnits;
      forcePoints = forcePts;
      planets = Iplanets;
   }



   /**
    * A very boring function which can be called
    * until such time as we code in better AI decision-
    * making algorithms.  This function just returns
    * an int from 0 to x-1, which can be used to 
    * make a decision directly or as an index into
    * an array of possible decisions.
    */
   public static int makeDecision(int x ){
       return ( (int)(Math.random() * x ) );
   }



   /**
    * Rebel turn; operations; enemy reaction phase:
    *  1) AI checks for location of detected rebels/militia
    *  2) AI compares these to locations of imperial militia
    *  3) AI randomly moves a unit to the rebel-occupied
    *     environ 75% of the time
    */

   public void react(){ 

      
   }


   /**
    * Rebel turn; operations; combat phase:
    * Imperial turn; operations; combat phase:
    *  1) AI checks if combat is possible; if not, returns
    *  2) AI makes list of all environs where combat is possible
    *  3) AI steps through, removing from it environs where imperial
    *     forces are outnumbered 3:1
    *  4) AI steps through list, assigning leaders where available 
    *  5) AI calls combat for each environ in the list
    */

   public void tryCombat(){
      
  
   }

   /** 
    * Rebel turn; search:
    *   1) AI makes or uses a list of detected rebels (if one is available)
    *      in same location as imperial units
    *   2) AI searches for any/all rebels in the list
    *   3) Successful search will always lead to combat
    */
    public void search(){

    }

   /**
    * Calls happy little window for AI to taunt human player
    */
    public void showTaunt(){
       tauntWindow t = new tauntWindow();
       t.show();
    }


      public int GroupDecision(int n){ 
         return(n);
      }

   /**
    * Selects a character from an array
    * of available characters 
    */
   public char makeDecision(char[] m){
      char[] available = new char[m.length];
      int j, k=0;
      for( int i = 0; i < m.length; i++ ){
         //if( Missions.missionAvailable(m[i])){
         //  available[k] = m[i];
         //  k++;
         // }
      }
      j = (int)(Math.random()*k);
      return available[j];
   }


   /**
    * Calls slightly less happy window when AI loses to human player
    */
    public void admitDefeat(){

    }


   /**
    * Imperial turn; operations; movement:
    *  AI stacks characters with military units or space ships
    *  AI lists units which are eligible to be moved
    *  AI first moves unstacked characters ie. environ to environ
    *    this is randomly done 50% of the time
    *  AI then moves characters/military between planets
    *    these are also moved 50% of the time
    *    the target location is chosen first based on where the loyalty
    *    has fallen below some base line and second randomly to any planet
    */


    public static boolean CheckLethal() {
	return true;
	
	// Soon to actually hold more decision making elements.
    }

    public static boolean CheckRange() {
	return false;

	// Soon to hold decision making based on game type and advantage
    }

    /** Function for deciding when imperial characters are active.
	This function will b responsible for toggling the activity of
	any character that must be toggled.  */
    public void ToggleActive(CharacterGroup units, int adv) {

	// 1. Check number of characters in group
	// 2. If > 1, check for toggles
	// 3. Find character with lowest combat rating
	// 4. If < 1 (including wounds), make inactive
	// 5. Check next lowest character until one is not toggled
	// 6. If none have been toggled, check adv (advantage)
	// 7. If rebels have large advantage, toggle one character
	//    (with the lowest combat rating) to inactive
	// 8. Check for prisoners
	// 9. If a prisoner is stacked with group, toggle one imperial
	//    inactive for easier break away
    }
}
