TravelTimN / oregon-trail-python

Oregon Trail, in Python
2 stars 0 forks source link

Oregon Trail Wagon

The Oregon Trail (Python)

Features

Wagon Animation

Using text-image to convert an image to ASCII art, I've created a 4-second animation of the traditional "Oregon Trail ox and wagon" trekking across the screen.

Original image used:

Oregon Trail Wagon

Output:

          .^7?!^...      :~7~~:    .~~^~:..         . .:^!JY7::::.              
 .^..:^~!?YGPYPG5PP?7~~7JY5PPBGY77YPG#BBBYGPY7:.:^~!~~7JJYPGG55P5Y?~~^.   .:^~^7
JYY??JYY5YYY7~?JJJ?~!?JYYYYJ?~^~7JYJJJYYYYPPYJ!~7!?Y?!?YYY?7JJJYYJYY5G55G5Y5P55P
J??!!!!!!!^^:  ........^^^^..   ......:^^^^~:.!!^!????7!!!!!!~^~~!!?YYJJJ7!~^^^^
                                                                    ...         
                                              :YGGBGGBPJJ!^.~~~.^?JJYGGGBY      
                                              .GG!B@@@@@@@#G@@@G#@@@@@@@@P      
                                               :#7 Y@@@@@@#B@@@B#@@@@@@@G       
                             :^.:7.             !&~ #@@@@@#B@@@B#@@@@@@G:       
                             ~5##@J75P557Y5Y!.  .J~:5PPGBG55GGG5PPPGBGG!        
                             7J5BBB&@@@@@@@@G^^^^7J?~?5?JPJJ7JY?~J5?JPJ7        
                                .J@@BY5Y7##&5    :~ ^Y?GG5JY.~! ^GJGG55G.       
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^~G555^::JB!5&J^^^^:^^7PG?PY~^^:^^!PBJ5P!^^^^^^^^
YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY

Additionally, I used a larger version for the "welcome" art.

ascii ox & wagon

                                  .::::::::::-.                     .::::::-
                                .hmMMMMMMMMMMNddds\...//M\\.../hddddmMMMMMMNo
                                 :NM-/NMMMMMMMMMMMMM$$NMMMMm&&MMMMMMMMMMMMMMy
                                 .sm/`-yMMMMMMMMMMMM$$MMMMMN&&MMMMMMMMMMMMMh`
                                  -Nd`  :MMMMMMMMMMM$$MMMMMN&&MMMMMMMMMMMMh`
                                   -Nh` .yMMMMMMMMMM$$MMMMMN&&MMMMMMMMMMMm/
    `oo/``-hd:  ``                 .sNd  :MMMMMMMMMM$$MMMMMN&&MMMMMMMMMMm/
      .yNmMMh//+syysso-``````       -mh` :MMMMMMMMMM$$MMMMMN&&MMMMMMMMMMd
    .shMMMMN//dmNMMMMMMMMMMMMs`     `:```-o++++oooo+:/ooooo+:+o+++oooo++/
    `///omh//dMMMMMMMMMMMMMMMN/:::::/+ooso--/ydh//+s+/ossssso:--syN///os:
          /MMMMMMMMMMMMMMMMMMd.     `/++-.-yy/...osydh/-+oo:-`o//...oyodh+
          -hMMmssddd+:dMMmNMMh.     `.-=mmk.//^^^\\.^^`:++:^^o://^^^\\`::
          .sMMmo.    -dMd--:mN/`           ||--X--||          ||--X--||
........../yddy/:...+hmo-...hdd:............\\=v=//............\\=v=//.........

Stopping to Rest

During game play, you can stop to rest between 1-9 days.

Resting will continue to deplete your food, and the normal day/weather cycles persist for each day.

Trading

During game play, you can attempt to trade.

Crossing Rivers

During game play, there are four (4) river crossings. Depending on the weather and river data, the crossing can vary anywhere between harmless and cause of death.

Possible river crossing outcomes:

https://www.died-of-dysentery.com/stories/crossing-rivers.html

Original Algorithms

fording a river

Algorithm for fording a river:

fording algorithm

Hiring an Indian:

river swiftness

Bottom Types

River Type Value
Kansas Smooth and Firm 0
Big Blue Muddy 1
Green Rocky and Uneven 2
Snake Rocky and Uneven 2

Fording the River

Unless the player is crossing an extremely shallow river, fording a river always has a 0% chance of success. The chance of success can be raised using the same methods as when the player caulks the wagon.

if D < 2.5:
    if BT == 0:  # smooth
        # You made the crossing successfully.
    elif BT == 1:  # muddy
        # 40% chance of getting stuck in mud
        if stuck_in_mud:
            # You become stuck in the mud. Lose 1 day.
        else:
            # It was a muddy crossing, but you did not get stuck.
    elif BT == 2:  # rocky
        # 16% chance of overturning
        if overturned:
            # Risk factor V between 10%-40%.
            # For each category of supplies that you still own,
            # V determines the odds that you lose something in that category.
            # For each category that you lose some supplies,
            # your actual loss is a random value between 0%-100% for that category.
elif D >= 2.5 and D < 3:
    # Your supplies get wet, and you lose a day.
    # Never gets stuck, and never overturns.
    # (unrealistic irl, but simplifies the algorithm)
elif D >= 3:
    # Wagon tips over.
    # Three different risk factors are computed.
    # The risk of losing something in each category of supplies is (D/10)/IX,
    # where IX=1 if you have no guide, and IX=5 if you have a guide.
    # Therefore, if the river is >=10ft deep and you have no guide,
    # then there is a 100% chance of loss in each category of supplies,
    # although the actual loss in each category is a random value between 0%-100%.
    # The risk of losing oxen is ((D-1)/10)IX for each ox.
    # The risk of losing a party member is ((D-2.5)/10)/IX.
    # Therefore, if the river is >=12.5ft deep, and you try to ford it without a guide,
    # you are guaranteed to lose a party member.

# NOTE: Most of these risks are reduced by 80% if you hire a Native American guide.

Floating Across / Caulking

The chances of successfully caulking the wagon to cross a river depends on the water level, speed of the current, and condition of the wagon. Also, like the "ford" option, the player can rest before crossing the river to wait for more suitable crossing conditions.

if D < 1.5:
    # The river is too shallow to float across.
elif D >= 1.5:
    # Spend one day (caulking, etc.)
    if D <= 2.5:
        # You had no trouble floating the wagon across.
    elif D > 2.5:
        # Risk of tipping over is (S/20)/IX.
        if wagon_tips_over:
            # Risk of losses is based on S.
            # Risk of losing something in each category of supplies is (0.4+S/25)/IX.
            # For each category in which you lose supplies, the loss is a random value between 0%-100% of that category.
            # No oxen are lost, because they were not hitched to the wagon.
            # The risk of losing a party member is ((S-3)/15)/IX.
            # Therefore, if the river swiftness is >= 18,
            # then you are guaranteed to lose someone in your party.

Taking the Ferry / Hire an Indian

The ferry costs money to use, although the odds of crossing are significantly higher by using a ferry. The cost of a ferry crossing is $5. The cost of hiring an Indian is between 2-6 sets of clothing. Also, like the "ford" and "float" options, the player can rest before crossing the river to wait for more suitable crossing conditions.

if D < 2.5:
    # The ferry is not operating today because the river is too shallow.
elif D >= 2.5:
    # The ferry operator says that he will charge you $5.00 and that you will have to wait 2-6 days. Are you willing to do this?
    if cash < 5:
        # You do not have enough money to pay for the ferry.
    else:
        if S <= 5:
            # The ferry got your party and wagon safely across.
        elif S > 5 and S <= 10:
            # Risk of a problem is 5%*.
        elif S > 10:
            # Risk of a problem is 15%*.

# * Risk:
# The ferry broke loose from moorings. You lose: (list)
# The risk of losing something in each category of supplies is 80%.
# For each category in which you lose supplies,
# the loss is a random value between 0%-100% in that category.
# The risk of losing oxen is 50% for each ox.
# The risk of losing a party member is 20%.

Order of operations to display lost supplies:


Random Names

Should you decide not to select your family/friends' names, there's a predefined list of names:

Females Males
Anna Henry
Beth Jed
Emily Joey
Mary John
Sara Zeke

Supplies

You will be required to carry supplies with you to help make the arduous journey to Oregon.

Resource Min Max Notes
wagon 1 1
oxen yoke 1 10 1 yoke = 2 oxen
food 1,000 2,000 pounds of food
clothing 10 200 sets of clothing
ammunition 1 10,000 1 box = 20 bullets
wagon wheel 0 3
wagon axel 0 3
wagon tongue 0 3

Hunting

Sounds

Onomatopoeia words for gunfire/shots:

Animals

Animal Speed Location Weight
Bison slow plains 852-991 lbs
Bear slow mountains 104-170 lbs
Deer medium anywhere 54-74 lbs
Rabbit fast anywhere 2lbs
Squirrel fast anywhere 1lb

Health

While alive, there are four (4) different health states you and your party can encounter: good / fair / poor / very poor.

There's a global health points system in place, that can fluctuate drastically from many aspects of the game play.

Players start with 0 points, which is the ideal health.

Health Points
good 0-34
fair 35-78
poor 79-104
very poor 105-139

Remaining party members all die in a matter of days, if the points are above 140+.

Each day the health value is decremented by 10% naturally.

Health (based on Weather)

The weather also causes health to fluctuate.

Weather Points Notes
Very Hot +2
Hot +1
Cool +0 Ideal weather, no change
Warm +0 Ideal weather, no change
Cold +0 if at least 2+ sets of clothing per person
+1 if at least 1 set of clothing per person
+2 if 0 sets of clothing per person
Very Cold +0 if at least 4+ sets of clothing per person
+1 if at least 3 sets of clothing per person
+2 if at least 2 sets of clothing per person
+3 if at least 1 set of clothing per person
+4 if 0 sets of clothing per person

Sliding scale: Math.floor(sets of clothing / persons alive)

Health (based on Food rations)

The player's food rations also causes health to fluctuate.

Rations Points
Filling +0
Meager +2
Bear Bones +4
No Food +6

Health (based on Travel Pace)

The player's travel pace also causes health to fluctuate.

Pace Points
Rest Day +0
Steady +2
Strenuous +4
Grueling +6

Health (based on Random Events)

Random events can also cause health to fluctuate.

Misfortune Points Notes
Bad water +20
Very little water +10
Diseased party member +20 only when the desease first happens
Rough trail +10

Travel Pace

During game play, you are able to adjust the pace at which your party travels to Oregon.

Pace Distance (miles per day)
steady 18 mi/day
strenuous 30 mi/day
grueling 36 mi/day

Food Consumption

During game play, you are able to adjust the food rationing; the rate at which your party consumes food.

Ration Amount Consumed (pounds per person, per day)
filling meals are large and generous 3 lbs/pp/day
meager meals are small, but adequate 2 lbs/pp/day
bare bones meals are very small; everyone stays hungry 1 lb/pp/day

Climate and Weather

As the player travels along the trail, each day’s weather is based on the current month, and the player’s current location along the trail.

The simulation retrieves the corresponding average temperature, and adds or subtracts a random deviation. The simulation also retrieves the odds of rainfall, and then generates conditions that may be dry, rainy, or very rainy. If the weather is very cold, then snow replaces rain.

Weather can have affect many aspects of the game, including river levels, health, forward progress, random events, etc.

To be as realistic as possible to generate temperatures and rainfall, your current location on the trail, and time of year, are based on six distinct geographical zones.

Zone Starting Landmark Ending Landmark Data based on...
1 Independence, MO Fort Kearney Kansas City, MO
2 Fort Kearney Fort Laramie North Platte, NE
3 Fort Laramie Independence Rock Casper, WY
4 Independence Rock Fort Hall Lander, WY
5 Fort Hall The Dalles Boise, ID
6 The Dalles Willamette Valley, OR Portland, OR

Each of the six zones contain climate data for each of the 12 months of the year. This includes average daily temperatures, and average monthly precipitation.

For daily weather, the script extracts the average temperature for that month/zone combo (in Fahrenheit), and then randomly chooses a value between -20 and +20 (from that average temperature), to determine the actual temperature for that day.

Weather Temperature
Very Hot > 90°F
Hot 70°F-90°F
Warm 50°F-70°F
Cool 30°F-50°F
Cold 10°F-30°F
Very Cold < 10°F

To determine the probability of it raining on a particular day, the script will extract the average monthly precipitation for that month/zone combo (in inches), and then is multiplied by 3%.

For example, the if the average monthly rainfall in a zone was 4.8 inches, then 4.8 * 3% gives you a 14.4% chance that it will rain on any given day in that month, in that zone.

Once the percentage is calculated, then there is a 30% chance that it will be a "heavy" rain (0.8 inches), and a 70% chance that it will be a "light" rain (0.2 inches). If the current temperature is "cold" or "very cold", then snow falls instead of rain (8 inches for heavy snow, and 2 inches for light snow). On rainy or snowy days, the weather is reported to the player as "rainy", "very rainy", "snowy", or "very snowy".

To make the weather a bit more realistic, there's one final twist to the weather data. On each daily cycle, the application will decide whether to generate "new" weather, or to repeat the previous day's weather. There is a 50% chance of repeating the previous day's weather, and therefore a 50% chance that new weather will be generated. The new weather could potentially be the same as the old weather, regardless.

Snowfall accumulates on the ground, and rainfall accumulates as ground and surface water. Each day, 10% of the accumulated rainfall disappears, and then today's rainfall (if any) is added in.

If the accumulated rainfall drops below 0.2 inches, then drought occurs. If the accumulated rainfall drops below 0.1 inches, then the drought becomes severe, and the player is given drought messages ("insufficient grass", "inadequate water", "bad water").

Each day, 3% of the accumulated snowfall disappears if the weather is very cold, cold, or cool, but not very rainy. If the weather is warm, hot, very hot, or very rainy, then 5 inches of snow melts, and is converted to 0.5 inches of water.


Random Events / Misfortunes

Event Probability Notes
Indians help find food 5% If you are completely out of food, then there is a 5% chance each day that local Indians will give you 30 pounds of food.
Severe thunderstorms varies The probability is based on the average precipitation for your current location and current month.
Severe blizzard 15% There is a 15% chance each day in which the temperature is either cold or very cold.
Heavy fog 6% After Fort Hall, a 6% chance each day, except when the temperature is very hot. 50% chance of also losing a day's travel.
Hail storm 6% Before Fort Hall, a 6% chance each day in which the temperature is very hot.
Injured or dead ox 2%-3.5% 2% each day on the prairie; 3.5% chance each day in the mountains. If all oxen are healthy, then one becomes injured; otherwise, the sick ox dies.
Injured party member 2%-3.5% (broken arm or leg) 2% chance each day on the prairie; 3.5% chance each day in the mountains. The person who gets injured is chosen randomly.
Snake bite 0.7% 0.7% chance each day.
Lose trail 2% 2% chance each day.
Wrong trail 1% 1% chance each day.
Rough trail 2.5% In mountains only; 2.5% chance each day.
Impassible trail 2.5% In mountains only; 2.5% chance each day.
Finding wild fruit 4% May to September only; 4% chance each day. The food supply is increased by 20 pounds.
Fire in the wagon 2% Some supplies are lost.
Lost party member 1% Lose up to 5 days.
Ox wanders off 1% Lose up to 3 days.
Finding an abandoned wagon 2% Some supplies are gained.
Thief comes during the night 2% Some supplies are lost.
Bad water 10% 10% chance each day in which the accumulated rainfall is below 0.1 inch.
Inadequate water 20% 20% chance each day in which the accumulated rainfall is below 0.1 inch.
Insufficient grass 20% 20% chance each day in which the accumulated rainfall is below 0.1 inch.
Illness 0%-40% Depending upon the health of the party. The person and the disease are chosen randomly.

Landmarks

There are three branch points in the game, where the player must decide whether to go left or right. Consequently there are 20 trail segments in the network connecting these 18 points. However, in a typical game, the player passes just 16 landmarks and travels 15 trail segments.

ID Landmark Type Region Next Landmark Next Landmark Buy Supplies Hire Indian Hire Ferry
L01 Independence, Missouri START Prairie Kansas River Crossing 102 miles
L02 Kansas River Crossing River Prairie Big Blue River Crossing 82 miles
L03 Big Blue River Crossing River Prairie Fort Kearney 118 miles
L04 Fort Kearney Fort Prairie Chimney Rock 250 miles
L05 Chimney Rock Misc Prairie Fort Laramie 86 miles
L06 Fort Laramie Fort Prairie Independence Rock 190 miles
L07 Independence Rock Misc Prairie South Pass 102 miles
L08 South Pass Misc Mountains Green River Crossing 57 miles
Mountains Fort Bridger 125 miles
L09 Green River Crossing River Mountains Soda Springs 143 miles
L10 Fort Bridger Fort Mountains Soda Springs 162 miles
L11 Soda Springs Misc Mountains Fort Hall 57 miles
L12 Fort Hall Fort Mountains Snake River Crossing 182 miles
L13 Snake River Crossing River Mountains Fort Boise 113 miles
L14 Fort Boise Fort Mountains Blue Mountains 160 miles
L15 Blue Mountains Misc Mountains Fort Walla Walla 55 miles
Mountains The Dalles 125 miles
L16 Fort Walla Walla Fort Mountains The Dalles 120 miles
L17 The Dalles Misc Mountains Willamette Valley, Oregon 100 miles
L18 Willamette Valley, Oregon END Mountains

Independence, Missouri

Attempt to Trade

Talk to People

Buy Supplies

Resource Price Amount
Oxen $20.00 per ox
Clothing $10.00 per set
Ammunition $2.00 per box of 20
Wagon wheels $10.00 per wheel
Wagon axles $10.00 per axle
Wagon tongues $10.00 per tongue
Food $0.20 per pound

Kansas River

Choices:

Attempt to Trade

Talk to People

Big Blue River

Choices:

Attempt to Trade

Talk to People

Fort Kearney

Attempt to Trade

Talk to People

Buy Supplies

Resource Price Amount
Oxen $25.00 per ox
Clothing $12.50 per set
Ammunition $2.50 per box of 20
Wagon wheels $12.50 per wheel
Wagon axles $12.50 per axle
Wagon tongues $12.50 per tongue
Food $0.25 per pound

Chimney Rock

Attempt to Trade

Talk to People

Fort Laramie

Attempt to Trade

Talk to People

Buy Supplies

Resource Price Amount
Oxen $30.00 per ox
Clothing $15.00 per set
Ammunition $3.00 per box of 20
Wagon wheels $15.00 per wheel
Wagon axles $15.00 per axle
Wagon tongues $15.00 per tongue
Food $0.30 per pound

Independence Rock

Attempt to Trade

Talk to People

South Pass

Attempt to Trade

Talk to People

The trail divides here. You may:

What is your choice?

Green River Crossing

Choices:

Attempt to Trade

Talk to People

Fort Bridger

Attempt to Trade

Talk to People

Buy Supplies

Resource Price Amount
Oxen $35.00 per ox
Clothing $17.50 per set
Ammunition $3.50 per box of 20
Wagon wheels $17.50 per wheel
Wagon axles $17.50 per axle
Wagon tongues $17.50 per tongue
Food $0.35 per pound

Soda Springs

Attempt to Trade

Talk to People

Fort Hall

Attempt to Trade

Talk to People

Buy Supplies

Resource Price Amount
Oxen $40.00 per ox
Clothing $20.00 per set
Ammunition $4.00 per box of 20
Wagon wheels $20.00 per wheel
Wagon axles $20.00 per axle
Wagon tongues $20.0 per tongue
Food $0.40 per pound

Snake River

Choices:

Attempt to Trade

Talk to People

Fort Boise

Attempt to Trade

Talk to People

Buy Supplies

Resource Price Amount
Oxen $45.00 per ox
Clothing $22.50 per set
Ammunition $4.50 per box of 20
Wagon wheels $22.50 per wheel
Wagon axles $22.50 per axle
Wagon tongues $22.50 per tongue
Food $0.45 per pound

Blue Mountains

Attempt to Trade

Talk to People

The trail divides here. You may:

What is your choice?

Fort Walla Walla

Attempt to Trade

Talk to People

Buy Supplies

Resource Price Amount
Oxen $50.00 per ox
Clothing $25.00 per set
Ammunition $5.00 per box of 20
Wagon wheels $25.00 per wheel
Wagon axles $25.00 per axle
Wagon tongues $25.00 per tongue
Food $0.50 per pound

The Dalles

Attempt to Trade

Talk to People

The trail divides here. You may:

What is your choice?

Willamette Valley, Oregon

If you get to the end and your points aren't enough to make the top 10, then you get the following message:

You have accumulated XXXX points. This is not enough to qualify for the Oregon Top Ten.


Scoring

On arriving in Oregon, your most important resources is the people you have with you. You receive points for each member of your party who arrives safely; you receive more points if they arrive in good health!

Health of Party Points per Person
good 500
fair 400
poor 300
very poor 200

On arriving in Oregon, the resources you arrive with will help you get started in the new land. You receive points for each item you bring safely to Oregon.

Resources of Party Points per Item
wagon 50
ox 4
spare wagon part 2
set of clothing 2
bullets (each 50) 1
food (each 25 pounds) 1
cash (each 5 dollars) 1

On arriving in Oregon, you receive points for your occupation in the new land. Because more farmers and carpenters were needed than bankers, you receive double points upon arriving in Oregon as a carpenter, and triple points for arriving as a farmer.


Colors

Color HEX RGB Notes
aqua #00FFFF 0, 255, 255 Credits & River Crossings
blue #0000FF 0, 0, 255 Links
gold #D4AF37 212, 175, 55 Leaderboard
green #00FF00 0, 255, 0 Game Play
grey #BBBBBB 187, 187, 187 Press ENTER to continue
orange #D46300 212, 99, 0 Logo & Titles
pink #FFB6C1 255, 182, 193 Talking to People
red #FF0000 255, 0, 0 Error Messages & Matt's General Store
yellow #FFFF00 255, 255, 0 Learning & Info

Credits

Source (URL) Notes
fontspace The Oregon Trail logo
Wikimedia Python logo
text-image ASCII ox/wagon (small)
mathstodon ASCII ox/wagon (large)
StackOverflow Centering text 80-wide
StackOverflow Clearing the terminal
StackOverflow Alignment with decimal points
StackOverflow Filter list of dicts by key
StackOverflow Get/Set object attributes dynamically
StackOverflow random.shuffle returns None
StackOverflow Trades: randomize with weights/ratios
Amazon R. Philip Bouchard
archive.org DOS Emulator of 1990 game

Reminders

Creating the Heroku app

When you create the app, you will need to add two buildpacks from the Settings tab. The ordering is as follows:

  1. heroku/python
  2. heroku/nodejs

You must then create a Config Var called PORT. Set this to 8000

If you have credentials, such as in the Love Sandwiches project, you must create another Config Var called CREDS and paste the JSON into the value field.

Connect your GitHub repository and deploy as normal.

Constraints

The deployment terminal is set to 80 columns by 24 rows. That means that each line of text needs to be 80 characters or less otherwise it will be wrapped onto a second line.


Happy coding!