Horse Race

This project will simulate a fantasy horse race in which there are 1000 horses and the user specifies odds they want to bet on. Unlike a real horse race where people bet on specific horses, in this race, the user simply specifies the odds and the program randomly tags winning horses based off the odds. Get ready, set, go!

The user will start with $100 at the beginning of the game and will indicate the bet amount and odds:

bet amount - any whole number in the range 1 through their current holdings
odds - either 1:1, 3:1, 7:1, 15:1, 30:1, 99:1 - the user will enter 1, 3, 7, 15, 30 or 99

After the user enters the above information, the horse race begins. Initially, the game starts out with 1000 horses, and based on the odds selected, a certain number of horses will be tagged as winners. The game continually cuts the number of horses in half randomly until either a) there are no more winning horses left (in this case, the user looses their bet amount) or b) there is only one horse left (in this case, if the remaining horse is a winner, the user wins money based on the odds, otherwise, the user looses their bet amount).

The program should include a Horse object that stores: id (the id of the horse) and isWinner (true if the horse is tagged as a winner, false otherwise). The horses will be assigned a unique id in the range 1..1000 and should be loaded into a LinkedList in ascending order based off their id. To tag horses as winners, the program should generate N unique random numbers (N will be based off the odds selected) in the range 1..1000 and place those numbers into an array. To generate N unique random numbers, you could load the numbers 1..1000 into an array, randomly get a value out of the array, remove that entry, then repeat the appropriate number of times. Once you have your N unique random numbers, you can tag the appropriate horses in the LinkedList as winners. From an efficiency standpoint, it would be best to order the random numbers in ascending order (use Collection.sort) then use a ListIterator to go through the LinkedList to tag the winners.

Here are the possible odds with the respective number of winning horses:

1:1 - 500 winners
3:1 - 250 winners
7:1 - 125 winners
15:1 - 63 winners
30:1 - 31 winners
99:1 - 10 winners

The game board should display the winning horses with a 1 and the loosing horses with a 0. The game board will display at most 100 horses in a single row. Therefore, the board with 1000 horses will be 100x10. After the first cut, there will be 500 horses (100x5), then 250 (100x2 plus 50 on the last row), then 125 (100 plus 25 on the last row), then 63, 31, 16, 8, 4, 2, 1.

If the user bets $10 and wins with 30:1 odds, that means the user wins 30 times their bet amount, or $300.

Here is example game play:

Welcome to CS Horse Racing!

Here are your odd options:

1:1 (500 winning horses)
3:1 (250 winning horses)
7:1 (125 winning horses)
15:1 (63 winning horses)
30:1 (31 winning horses)
99:1 (10 winning horses)

Your current money amount is: $100
Please enter your bet amount (1-100, or 0 to quit): 10
Please enter your odds (1, 3, 7, 15, 30, or 99): 30

0000000000000000000000000000000000000000000000000000000000001111100000000000000000000000000000000000
0000000000011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000001111100000000000000000000000000000000000
0000000000000100000000000000000000000000011000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000111110000000000000000
0000000001000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000011000000000000000000000000000000
0000001000000000000000000000000000000000100000000000000010000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000001011000000000000000000000000000000000000000000000000000000000000

Reducing horses...    (pause a little while for suspense)

0000000000000000000000000000000000000000000000000000000000001111100000000000000000000000000000000000
0000000000011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000001111100000000000000000000000000000000000
0000000000000100000000000000000000000000011000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000111110000000000000000

Reducing horses...    (pause a little while for suspense)

0000000000000000000000000000000000000000000000000000000000001111100000000000000000000000000000000000
0000000000011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000

Reducing horses...    (pause a little while for suspense)

000000000000000000000000000000000000000000000000001110000000000

Reducing horses...    (pause a little while for suspense)

0001010000000000000000000000000

Reducing horses...    (pause a little while for suspense)

0000010000000000

Reducing horses...    (pause a little while for suspense)

00100000

Reducing horses...    (pause a little while for suspense)

0100

Reducing horses...    (pause a little while for suspense)

10

Reducing horses...    (pause a little while for suspense)

1

WINNER!! You won $300

Your current money amount is: $400
Please enter your bet amount (1-400, or 0 to quit): 0

Thank you for playing!

To cut horses, the program should create an array with values 1..1000 placed randomly within it. You can use the shuffle method in the Collection class for this. For the first reduction, then, the program will take the first 500 values out the array and place them into a new array. That array will then be sorted using the Collections.sort method so you can efficiently iterate through the LinkedList and remove the appropriate horses. For the second cut, the program will take the next 250 values out of the array, and continue the same process as in the first cut. Here are the number of horses that should be cut:

1st cut - 500
2nd cut - 250
3rd cut - 125
4th cut - 63
5th cut - 31
6th cut - 16
7th cut - 8
8th cut - 4
9th cut - 2
10th cut - 1

You can use Thread.sleep(2000); to pause. In this case, 2000 indicates 2000 milliseconds or 2 seconds.

You should write your code in such a way that your LinkedList can be easily switched to ArrayLists, and you should answer the following questions: How long does a full round take when a LinkedList is used? How long does a full round take when an ArrayList is used? You should start the timer after the user enters their bet amount and odds, then stop the timer once the round is over. You should only record rounds that finish with 1 horse remaining.

If the user runs out of money during game play, the game is over. Otherwise, the game will continue until the user indicates s/he wants to quit.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License