!***************************************************************************!
!									    !
!				 HORSES.BAS				    !
!		       Bet on the horses at the track.			    !
!									    !
!***************************************************************************!
!Copyright (C) 1986 by Centauri.  All Rights Reserved.
!(512) 631-9141
!Written by: Scot Brinkley
!
!Edit History:
!1.0 01-Mar-83 created.	/SB

	PROGRAM HORSES,1.0

	RANDOMIZE
BEGIN:
	MAP1 REPLY,S,1
	MAP1 CHANGES,S,1
	MAP1 HYPHEN,S,80
	MAP1 CRITTER1,S,4,"~/\'"
	MAP1 CRITTER2,S,4,"~>>'"
	MAP1 CRITTER'SPACE,S,4,"    "
	MAP1 JOBNAM,S,6

	MAP1 HOSS(5),S,1
	MAP1 PLACED(5),F
	MAP1 TABLE(5,2),F
	 TABLE(1,1) = 1	: TABLE(1,2) = 0
	 TABLE(2,1) = 1	: TABLE(2,2) = 0
	 TABLE(3,1) = 1	: TABLE(3,2) = 0
	 TABLE(4,1) = 1	: TABLE(4,2) = 0
	 TABLE(5,1) = 1	: TABLE(5,2) = 0
	
	MAP1 STALL(5),S,20
	 STALL(1)   = "#1  ED'S FOLLEY     "
	 STALL(2)   = "#2  MARY'S CHOICE   "
	 STALL(3)   = "#3  LAGGING LAURIE  "
	 STALL(4)   = "#4  EAGER ELAINE    "
	 STALL(5)   = "#5  ANEVA'S SONG    "

 	?TAB(-1,0);TAB(-1,29);
	FOR CCSI = 1 TO 20
	 ?TAB(12,20);" C E N T A U R I   S T A K E S"
	 FOR CCSII = 1 TO 800 : NEXT CCSII
	 ?TAB(12,20);"C E N T A U R I   S T A K E S "
	NEXT CCSI
	 ?TAB(12,20);"C E N T A U R I   S T A K E S "
	 ?TAB(14,20);"      by  Scot Brinkley       "
	FOR CCSIII = 1 TO 10000 : NEXT CCSIII

 	?TAB(-1,0);TAB(-1,28);
	REPLY   = " "
	?TAB(10,10);"DO YOU PREFER TO ENTER HORSES NAMES, YOURSELF <Y/N> :";:INPUT REPLY
	IF UCS(REPLY[1,1]) <> "Y" GOTO AROUND5
RENAME:
	CHANGES = " "
	?TAB(12,20);"ENTER NAME OF HORSE #1 : ";:INPUT STALL(1) : STALL(1) = "#1  " + STALL(1)
	?TAB(13,20);"ENTER NAME OF HORSE #2 : ";:INPUT STALL(2) : STALL(2) = "#2  " + STALL(2)
	?TAB(14,20);"ENTER NAME OF HORSE #3 : ";:INPUT STALL(3) : STALL(3) = "#3  " + STALL(3)
	?TAB(15,20);"ENTER NAME OF HORSE #4 : ";:INPUT STALL(4) : STALL(4) = "#4  " + STALL(4)
	?TAB(16,20);"ENTER NAME OF HORSE #5 : ";:INPUT STALL(5) : STALL(5) = "#5  " + STALL(5)
	?TAB(22,1);"ANY CHANGE ";:INPUT CHANGES
	IF UCS(CHANGES[1,1]) = "Y" GOTO RENAME
AROUND5:
 	?TAB(-1,0);TAB(-1,29);

ODDS'CAL:
	FOR HOSS = 1 TO 5
      REHOSS:
	 ODDS = INT(RND(HOSS)*100)
	 IF ODDS <1 OR ODDS >20 GOTO REHOSS
	 TABLE(HOSS,2) = ODDS
	NEXT HOSS


	FOR X = 1 TO 10
	 HYPHEN = HYPHEN + "--------"
	NEXT X

	XCALL JOBNAM,JOBNAM
	XCALL STRIP,JOBNAM
	LOOKUP JOBNAM+".RAC",FOUND
	IF FOUND CALL OLD'MONEY
	IF WINNINGS=0 WINNINGS = 100

BEGIN1:
	IF WINNINGS < -200 CALL BIT'THE'BIG'ONE : NO = 99 : GOTO BYE'BYE
	COUNTER = COUNTER + 1
	RUNS   = 0
	PLACES = 0
	SWITCH = 0
	CALL GROUND
	IF COUNTER = 1 THEN CALL CROWD : CALL SHOW'BAL
	CALL HORSES
	CALL BETS
	GOTO RACE
!	GOTO END
LOOP1:

      GROUND:
	FOR X = 3 TO 18 STEP 3
	 ?TAB(X,1);HYPHEN[1,78]
	NEXT X
	FOR ME = 1 TO 5
	 TABLE(ME,1) = 1
	 HOSS(ME)    = "0"
	 PLACED(ME)  = 0
	NEXT ME
      RETURN

      HORSES:
	S = 1
	FOR H = 5 TO 17 STEP 3
	 ?TAB(H,1);SPACE(80);
	 ?TAB(H,1);CRITTER1;
	 IF TABLE(S,2) < 1 THEN TABLE(S,2) = 1
	 IF TABLE(S,2) >20 THEN TABLE(S,2) = 20
	 ?TAB(H-1,1);STALL(S);" ODDS : ";TABLE(S,2);" TO 1";
	 S = S + 1
	NEXT H
      RETURN

      CROWD:
	FOR A = 1 TO 50
      RERAND:
 	 R=INT(RND(A)*100) !: ?TAB(1,60);"ROW = ";R;
 	 C=INT(RND(A)*100) !: ?TAB(2,60);"COL = ";C;
	 IF R < 1 OR R > 2 GOTO RERAND	
	 IF C < 1 OR C > 78 GOTO RERAND	
	 IF A/30 = INT(A/30) THEN ?TAB(R,C);"~o";: GOTO BYE'CRD
	 IF A/20 = INT(A/20) THEN ?TAB(R,C);"\o/";: GOTO BYE'CRD
	 IF A/10 = INT(A/10) THEN ?TAB(R,C);"o|";: GOTO BYE'CRD
	 ?TAB(R,C);"o";
      BYE'CRD:
	NEXT A
      RETURN

      BETS:
	BET = 0
	?TAB(19,1);SPACE(78)
	?TAB(19,1);"(Enter 99 to exit)";TAB(-1,28);
	?TAB(21,1);"PLACE YOUR BETS :    1)  HORSE #";:INPUT NO
      BYE'BYE:
	IF NO = 99 CALL EXIT
	IF NO < 1 OR NO > 5 GOTO BETS
	FOR PLACET = 4 TO 16 STEP 3
	 ?TAB(PLACET,4);SPACE(50);
	 FOR X = 1 TO 800 : NEXT X	!Delay loop.
	NEXT PLACET
	?TAB(19,1);SPACE(20)
      REODD:
	ODDS = TABLE(NO,2)
	IF ODDS <2 THEN ODDS = 2
	IF ODDS >20 THEN ODDS = 20
	IF ODDS = 2 : GOTO AFTER
	?TAB(21,48);"ODDS ON HORSE #";NO;" ARE ";ODDS;"-TO-1";
	GOTO WAYAFTER
      AFTER:
	?TAB(21,48);"ODDS ON HORSE #";NO;" ARE EVEN.";
      WAYAFTER:
	?TAB(22,1);SPACE(80)
	?TAB(22,1);"                     2)  WAGER $";:INPUT BET
	?TAB(23,1);SPACE(35)
	IF BET <= 0 GOTO BETS
	IF BET > WINNINGS AND WINNINGS > 0 CALL BAD'WAGER : GOTO BETS
	PAYOFF = (BET*ODDS)	
	?TAB(22,48);"PAYOFF : ";PAYOFF USING "$#,###,###,###,###.##";
	?TAB(-1,29);
      RETURN

      RACE:
	RUNS   = RUNS + 1
      OVER:
	 HORSE = INT(RND(RUNS)*100)
	 IF HORSE <1 OR HORSE >5 GOTO OVER
	 SWITCH = 1
	 FOR TIMES = 1 TO 5
	  IF HOSS(TIMES) = "0" THEN SWITCH = 0
	 NEXT TIMES
	 IF SWITCH = 1 GOTO END
	 IF HOSS(HORSE) = "1" GOTO OVER
	 IF (RUNS/2) = INT(RUNS/2) THEN ?TAB((HORSE*3)+2,TABLE(HORSE,1)+4);CRITTER1;: GOTO BYE
	 ?TAB((HORSE*3)+2,TABLE(HORSE,1)+4);CRITTER2;
      BYE:
	 ?TAB((HORSE*3)+2,TABLE(HORSE,1));CRITTER'SPACE;
	 TABLE(HORSE,1) = TABLE(HORSE,1) + 1
	 IF TABLE(HORSE,1) > 72 THEN HOSS(HORSE) = "1" : PLACES = PLACES + 1 :  PLACED(HORSE) = PLACES
	 IF PLACED(HORSE) = 1 THEN ?TAB(5+(HORSE*3)-3,30);"WIN";: WINNER = HORSE
	 IF PLACED(HORSE) = 2 THEN ?TAB(5+(HORSE*3)-3,29);"PLACE";: PLACER = HORSE
	 IF PLACED(HORSE) = 3 THEN ?TAB(5+(HORSE*3)-3,30);"SHOW";: SHOWER = HORSE
	 IF PLACED(HORSE) = 4 THEN LOSSER1 = HORSE
	 IF PLACED(HORSE) = 5 THEN LOSSER2 = HORSE
	GOTO RACE
END:
 	FOR SHOW = 1 TO 5
	 IF PLACED(SHOW) = 1 THEN TABLE(SHOW,2) = (TABLE(SHOW,2)-5)
	 IF PLACED(SHOW) = 2 THEN TABLE(SHOW,2) = (TABLE(SHOW,2)-2)
	 IF PLACED(SHOW) = 3 THEN TABLE(SHOW,2) = (TABLE(SHOW,2)-0)
	 IF PLACED(SHOW) = 4 THEN TABLE(SHOW,2) = (TABLE(SHOW,2)+2)
	 IF PLACED(SHOW) = 5 THEN TABLE(SHOW,2) = (TABLE(SHOW,2)+5)
 	NEXT SHOW
	IF WINNER = NO THEN ?TAB(19,30);"YOU'RE A WINNER !!!" : WINNINGS = ((WINNINGS + PAYOFF) - BET)
	IF PLACER = NO THEN ?TAB(19,30);"YOU PLACED !!!     " : WINNINGS = ((WINNINGS + (PAYOFF*.30)) - BET)
	IF SHOWER = NO THEN ?TAB(19,30);"YOU SHOWED !!!     " : WINNINGS = ((WINNINGS + (PAYOFF*.10)) - BET)
	IF NO <> WINNER AND NO <> PLACER AND NO <> SHOWER THEN WINNINGS = (WINNINGS - BET)
	IF WINNINGS < 0 GOTO GO'TO1
	?TAB(23,1);SPACE(80);
	?TAB(23,1);"WINNINGS ARE : $";WINNINGS USING "#,###,###,###.##"
	GOTO GO'TO2
GO'TO1:
	?TAB(23,1);"LOSSES ARE   : $";WINNINGS USING "#,###,###,###.##"
GO'TO2:
	?TAB(-1,28);
	?TAB(23,65);"CR TO CONTINUE";:INPUT LINE, A$
	?TAB(23,50);SPACE(31);
	?TAB(21,48);SPACE(33);
	?TAB(22,1);SPACE(10);
	?TAB(22,48);SPACE(33);
	?TAB(21,34);SPACE(2);
	?TAB(5,29);SPACE(10);
	?TAB(8,29);SPACE(10);
	?TAB(11,29);SPACE(10);
	?TAB(14,29);SPACE(10);
	?TAB(17,29);SPACE(10);
	GOTO BEGIN1
BIT'THE'BIG'ONE:
	?TAB(18,1);SPACE(80);
	?TAB(19,1);SPACE(80);
	?TAB(20,1);SPACE(80);
	?TAB(21,1);SPACE(80);
	?TAB(22,1);SPACE(80);
	?TAB(23,1);SPACE(75);
	?TAB(20,20);"YOU BIT IT - NO MORE CREDIT  (AL WILL BE LOOKING FOR YOU!)"
	?TAB(22,20);"   LOSSES : ";WINNINGS USING "$ #,###.##"
	FOR DELAY = 1 TO 15000 : NEXT DELAY
	RETURN
BAD'WAGER:
	?TAB(19,30);"CAN'T BET MORE THAN YOU HAVE !"
	CALL SHOW'BAL
	FOR DELAY = 1 TO 15000 : NEXT DELAY
	?TAB(19,20);SPACE(50)
	RETURN
SHOW'BAL:
	?TAB(23,1);SPACE(80);
	?TAB(23,1);"HOLDINGS ARE : $";WINNINGS USING " #,###,###,###.##"
	?TAB(22,1);
	RETURN
OLD'MONEY:
	IF WINNINGS=100 RETURN
	OPEN #1,JOBNAM+".RAC",INPUT
	INPUT LINE #1,WINNINGS
	CLOSE #1
	RETURN
EXIT:
	?TAB(24,1);TAB(-1,10);TAB(-1,28);
	?TAB(24,79);TAB(-1,33);TAB(24,1);TAB(-1,32);
	IF WINNINGS>1000 &
	?"----------*-------   CHICKEN!  --------*-------";
	IF WINNINGS<0 &
	?"<<<<<<<<<   YOU'RE IN BIG TROUBLE NOW!!!!  >>>>>>>>>";
	IF WINNINGS=0 &
	?"*******  THE BANK WILL OFFER CREDIT IF YOU WANT TO PLAY AGAIN. ****";
	IF WINNINGS<1000 AND WINNINGS>0 &
	?"^^^^^   SORRY, CAN'T TAKE YOUR WINNINGS WITH YOU!  ^^^^";
	?CHR(7);
	FOR DELAY = 1 TO 10000 : NEXT DELAY
	OPEN #1,JOBNAM+".RAC",OUTPUT
	PRINT #1,WINNINGS
	CLOSE #1
	END