The Struggle Of Creating A Realistic Basketball Simulation Game
5/14/2024
The idea always starts off simple. Basketball players have baseline player attributes, like three point ability or passing skill. You then need some grouping of these players to make up a basketball roster, then a bunch of teams to go against each other. Before you know it, we’re pretty much there! But wait? How do we have teams play against each other? How do we implement fouls? Building the concept of a basketball simulation has been an adventure in all kinds of ways. The key word here being “simulation”, means a couple of things. Defining what this term means in necessary for clarity, so let’s begin there.
The simulation game genre is surprisingly diverse, consisting of a selection of games designed to mimic or closely pattern activities that we do in real life. The Sims series is probably the most popular/successful member of this category. Although I never really played the Sims, my personal favorite simulation game was RollerCoaster Tycoon 2. You control everything in that game. There are endless layers of immersion, and it makes you feel like you are truly running an amusement park business. Seriously, one of my favorite activities of Rollercoaster Tycoon was strategizing the best pathing from the highest thrill rollercoasters to the nearest first-aid station or bathroom.
Back to basketball. What are good ways to simulate a basketball game? Breaking down the actual goal, a basketball game is a series of offensive and defensive possessions. Each team roughly has the same number of possessions, and chances to score. My earliest iteration of playing possessions looked something like the following:
What this method does is pretty simple: each team has a offensive score for the team on offense, and the defensive score for the team on defense. These scores are basically averages of the offensive/defensive attributes of all the players on each team. In each possession, we randomly pick a number between 0 and the offense or defense score. We use that as a DND-like roll to determine success. Success here meaning a two-point score, and failure would be no points. Straightforward right? I still think fondly of this playPossession method for its simplicity and ease of understanding. Even though we can easily see a number of issues with this approach:
- This logic doesn’t support three-pointers as is. We could take the average three-point attribute of the offensive team, and weigh that against the average perimeter defense attribute for the defensive team as a stopgap, but this might be hard to balance.
- Balancing this will be super tough depending on the composition of rosters. Teams with weak aggregate offensive scores will hardly put up points against teams with great defensive scores, while weak defenses wouldn’t be able to stop anyone.
- This manner of playing possessions lacks real depth, failing to highlight the specific skills/weaknesses of any one player. All that matters is the overall team score. And that’s pretty dull.
Ignoring these limiting flaws, this iteration succeeds as a baseline foundation for implementing a simulated basketball possession. In contrast, take a look at a snippet of how Basketball Coach simulates a basketball possession:
Above you see a 33-line snippet of an almost 1000-line file, dedicated to implementing multiple layers of a basketball possession. I guess the actual startPossession method is only about 300 lines, to be fair. However, I introduced multiple layers into the simulation. In any given possession:
- The class variable this.pointsScored allows for us to support how many points were scored on the possession. A free throw being 1, an inside shot being 2, and a three pointer being 3 points.
- The class variable this.offensivePlayer dictates who currently has the ball, and we can determine the outcome of specific actions based on the offensive skills of this player. Patterning this is the class method this.setDefenderForOffensivePlayer, which has the responsibility of assigning the appropriate defender for the current offensive player. This approach involves more specificity, mirroring the impact that individual basketball players have in real life.
- This snippet also includes playcalling, where specific actions are run in the possession. Again, this achieves a new level of immersion into the simulation experience.
The basketball possession simulation logic of Basketball Coach has a bit more complexity than I’ve shown in this snippet. Regardless of complexity, both methods I have shown succeed in their goal: simulating a basketball possession. The core of software development is tackling a problem and weighing the tradeoffs of different solutions. A streamlined, easy-to-build simulation experience comes at the cost of being dull fast, and not giving the player enough options to make impactful game decisions. A complicated, multi-layered simulation game can be really fun to play, but really hard to develop and maintain its logic. In summary, this is an ongoing struggle. But the struggle is worth it, when you can build cool things that you enjoy sharing with the world.