View Single Post
Old 09-14-2014, 07:25 PM   #38
Groundhog
Coordinator
 
Join Date: Dec 2003
Location: Sydney, Australia
A quick rundown on the work I've been doing re: court positions. Each step of a play, I define where the offensive players are on the court. As I've said above, the half-court is divided into 14 slices, and the below dictionary has the players position as a string - ie. "5" for the C - followed by his location on the court - ie. 6. I use strings for the player positions to make it easier for me to spot them in the code. PG/SG/etc. would've been even easier, but hey, hindsight :
Code:
offpos = {"pos": {"5": 6, "4": 3, "3": 14, "2": 10, "1": 12}}
To work out the defender's location, the sim first checks the defensive strategy, which is also stored in a dictionary, this is an excerpt of the home team's strategy:
Code:
strategydict = {"0": {"strategy": "m2m", "individualstrat": {100014: {"hedge": 0, "screen": 0, "insided": 1, "2ptd": 0, "3ptd": 0}, 100015: {"hedge": 0, "screen": 0, "insided": 1, "2ptd": 1, "3ptd": 0}, 100016: {"hedge": 1, "screen": 0, "insided": 0, "2ptd": 0, "3ptd": 0}, 100017: {"hedge": 1, "screen": 0, "insided": 0, "2ptd": 1, "3ptd": 0}, 100018: {"hedge": 1, "screen": 1, "insided": 0, "2ptd": 1, "3ptd": 1}}, "guard": {"1": "1", "2": "2", "3": "3", "4": "4", "5": "5"}, "threeonly": 0, "focus": 0, "tempo": 0, "autofoul": 0},
"Strategy": "m2m" and, as it's man-to-man, "guard" are the entries that will now dictate the defensive player's positions on the court, which builds the defpos dictionary (basically, identical to offpos above, but with an entry that dictates who is defending the ballhandler). It will then take the "individualstrat" entries - the 100014 are primary keys for the players on the other team - and check each offensive players position on the court and determine whether the player is being left open or guarded based on the "insided"/"2ptd"/"3ptd" entries - the defender's defensive awareness rating is also checked to see if a guy follows the defined strategy or not. An additional "isopen" dictionary is created and (not yet coded) a check will be made each step of a play to see if a pass is made to an open player, which would break from the scripted play.

If a team is playing zone defense it's a bit trickier. The method I came up with was to script the defense's court positions relative to the ballhandler. It took some work, but I'm pretty happy with how it turned out. The sim will check the location of the ball handler, then look that up in a function that returns the defender's position on the court, the player defending the ball, and then for each of the 14 spots on the court it tracks: 1) the player responsible for that location, 2) a secondary player responsible for the position too (for some zones it could be the 4 and 5 in front of the basket, etc.), and 3) how many areas removed from that space is the defender if he has to recover to a pass - ie. in the below example from the 3-2 zone with the ball in position 14 (left corner 3), the 5 man is responsible for the right corner 3 (position 10), but he would be 3 zones removed from that location, making him unlikely to recover to that spot if the ballhandler made a miraculous pass from one corner to the other.
Code:
elif ballpos == 14: {defpos: {"5": 1, "4": 9, "3": 3, "2": 7, "1": 8}, "ballhandler": "4"} {1: ("5", 0, 0), 2: ("5", 0, 1), 3: ("3", 0, 0), 4: ("5", 0, 1), 5: ("5", 0, 2), 6: ("2", 0, 1), 7: ("2", 0, 0), 8: ("1", 0, 0), 9: ("4", 0, 0), 10: ("5", 0, 3), 11: ("2", 0, 1), 12: ("2", 0, 1), 13: ("1", 0, 1), 14: ("4", 0, 1)}
I also didn't want guys throwing unrealistic passes to open players - ie. the example above, a pass from one corner to the other is very difficult. I created another dictionary that again takes a player's position on the court and assigns a rating of 0, 1, 2 to each area on the court with 0 being an easy pass, 1 difficult, and 2 very difficult. This effects both the player's decision to make the pass as well as the success of that pass.
__________________
Politics, n. Strife of interests masquerading as a contest of principles.
--Ambrose Bierce

Last edited by Groundhog : 09-14-2014 at 07:27 PM.
Groundhog is offline   Reply With Quote