DEV Community

Discussion on: JavaScript Baseball

Collapse
 
raddevus profile image
raddevus

This is an interesting idea. With just a bit of enhancement you could have it so it will (in increasing amount of difficulty) :
1) randomly calculate for a hit also -- so it's not just a strike-out or walk
2) automatically select two real MLB teams and list them as playing
3) put a timer in so it "plays" an entire game and the user can just watch.
Nice idea and article. thanks for sharing

Collapse
 
denvercoder profile image
Tim Myers

It already calculates for a hit. How would there be any runs if there are not hits. 😂

There is a random chance of:

  1. hit
  2. Strike
  3. Ball
  4. Foul

It will actually advance innings and score runs if there are more than 3 hits in an inning.

Collapse
 
raddevus profile image
raddevus

Yeah, that makes sense. I think it's because the article didn't mention the possibility of a hit, just this :

Then a random number generator will either make that pitch a "strike", or a "ball". Once you get to 4 balls the batter is "walked". If you get 3 "strikes" the batter is out.

Collapse
 
denvercoder profile image
Tim Myers

One of the things I thought of doing is have a "Team" array with Players that all have different ratings. So like in REAL baseball a batter with a .500 average is going to get more hits than a batter with a .300 average. I thought about factoring in that percentage. Then you could let them pick their own team by having a maximum number of "points". Maybe you start with 20 points. A batter with a .500 average is 10 points so that would be almost all of your points so you would have to fill your roster with .125 average batters. So there would be some skill in optimizing your roster of players.