/*
 *	File name:			strategy_random.c
 *	Purpose:			Defines a robot strategy for playing poker.
 *	Functions:			computer_bet, computer_draw, strategy_init,
 *						strategy_exit, computer_outcome, computer_hear.
 *	Created:			23 Nov 89
 *	Last Modified:		25 Jul 93
 *	Comments:
 *		"Strategy" files must contain six externally visible functions:
 *
 *		strategy_init - called once during startup.
 *		strategy_exit - called once upon orderly exit.
 *		computer_bet - called whenever a bet is needed.
 *		computer_draw - called whenever a draw of cards is needed.
 *		computer_outcome - called at the end of each hand.
 *		computer_hear - called whenever anyone sends a text message.
 *
 *		The interfaces to these six functions are well-defined and should 
 *		remain stable.  You can use this file to entirely alter the playing 
 *		methods of a robot player without being concerned with server 
 *		communication or anything else.
 *
 *	History:
 *		23 Nov 89/JVE	Created.
 *		25 Nov 89/JVE	Added strategy_init().
 *		25 Jul 93/JVE	Prototypes, new standard functions.
 */

# include	<stdlib.h>		/* for srand() */
# include	<time.h>		/* for time() */
# include	"cards.h"		/* for declaration of crandom() */
# include	"robot.h"
# include	"knowledge.h"
# include	"strategy_protos.h"


/*
 ***********************************************************************
 *
 * FUNCTION NAME:	computer_bet
 *
 * DESCRIPTION:		Make a bet.
 *
 * PARAMETERS: 
 *		NAME		I/O		DESCRIPTION
 *		----		---		-----------
 *		knowledge	 I		Everything we know about the current hand.
 *		me			 I		Index in knowledge[] of this robot.
 *		required	 I		Total $$ this hand to bet to stay in.
 *
 * RETURN CODES: 
 *	(int)		Amount of additional cash to bet.
 *	(-1)		Fold.
 *
 * COMMENTS:
 *		This exceedingly stupid function passes or calls 40% of the time,
 *		and raises by 10 the other 60% without even looking at the hand.
 *
 **********************************************************************
 */

int		computer_bet( KNOWLEDGE knowledge[], int me, int required )

{
int			add_bet;

if ( crandom( 10 ) > 4 )
	/* raise 10 */
	add_bet = required - knowledge[me].bet + 10;
else
	/* call or pass */
	add_bet = required - knowledge[me].bet;

return add_bet;
}


/*
 ***********************************************************************
 *
 * FUNCTION NAME:	computer_draw
 *
 * DESCRIPTION:		Discard some cards and draw others.
 *
 * PARAMETERS: 
 *		NAME		I/O		DESCRIPTION
 *		----		---		-----------
 *		knowledge	 I		Everything we know about the current hand.
 *		me			 I		Index in knowledge[] of this robot.
 *		cmd			 O		Constructed "discard" command.
 *
 * RETURN CODES: none
 *
 * COMMENTS:
 *
 **********************************************************************
 */

void	computer_draw( KNOWLEDGE knowledge[], int me, char *cmd )

{
standard_draw( knowledge[me].cards, cmd );
}



/****************************************************************************/
/*	FUNCTION:	strategy_init												*/
/*																			*/
/*	PURPOSE:	Any initialization this strategy requires.					*/
/*																			*/
/*	INPUT PARAMETERS:														*/
/*		NAME		I/O		DESCRIPTION										*/
/*		----		---		-----------										*/
/*																			*/
/*	RETURNS: TRUE -> I want to play.										*/
/*																			*/
/*	COMMENTS:																*/
/*		Since computer_bet uses random numbers in its strategy, we must		*/
/*		here initialize the random number generator.						*/
/*																			*/
/*	HISTORY:																*/
/*		1.	25 Nov 89		Created.										*/
/*																			*/
/****************************************************************************/

int strategy_init(void)

{
# ifdef sun
srandom( (int) time( 0 ) ^ getpid() );
# endif
# if _AMIGA
srand( time( 0 ) );
# endif
return TRUE;
}

/*
 ****************************************************************************
 *	FUNCTION:	strategy_exit
 *
 *	PURPOSE:	Called as this program exits.
 *
 *	INPUT PARAMETERS:
 *		NAME		I/O		DESCRIPTION
 *		----		---		-----------
 *
 *	RETURNS: none
 *
 *	COMMENTS:
 *
 *	HISTORY:
 *		1.	13 Mar 93/JVE		Created.
 *
 ****************************************************************************
 */

void strategy_exit(void)

{
}

/*
 ****************************************************************************
 *	FUNCTION:	computer_hear
 *
 *	PURPOSE:	Called when someone at the table speaks.
 *
 *	INPUT PARAMETERS:
 *		NAME		I/O		DESCRIPTION
 *		----		---		-----------
 *
 *	RETURNS: none
 *
 *	COMMENTS:
 *
 *	HISTORY:
 *		1.	13 Mar 93/JVE		Created.
 *
 ****************************************************************************
 */

void computer_hear(KNOWLEDGE knowledge[], char *from, char *text)

{
}

/*
 ****************************************************************************
 *	FUNCTION:	computer_outcome
 *
 *	PURPOSE:	Tells us the result of the hand.
 *
 *	INPUT PARAMETERS:
 *		NAME		I/O		DESCRIPTION
 *		----		---		-----------
 *
 *	RETURNS: none
 *
 *	COMMENTS:
 *
 *	HISTORY:
 *		1.	13 Mar 93/JVE		Created.
 *
 ****************************************************************************
 */

void computer_outcome(KNOWLEDGE knowledge[], int me, int winner)

{
}
