The TORCS Racing Board
Username: Password: Remember Me?
Lost Password Register
Author: alassio | Created: 2017-06-13 16:11:28
Subject: How to find out if pit is occupied
Hi all
With pit sharing enabled and some simple rules on damage thresholds creates situations where both my cars try to pit at the same time.
How do you identify whether the pit is currently occupied and you should wait? (instead of killing your car by hitting your mate)

Thanks, Rico
Last Edited: 2017-06-13 16:11:28 by alassio
    Author: firechief | Created: 2017-06-13 16:25:37
    Subject: Re: How to find out if pit is occupied
    There's a couple of parts to this. Firstly, when your cars are starting to run low on fuel your code should look to see which robot has the most damage and pit that car second - you don't want it to pit first & be occupying the pits when the other car's running empty. If the race is on an unusually short track and both cars are damaged, this could mean pitting the first one a lap or two earlier. But that's the first step - your strategy code needs to plan one car pitting ahead of the other, and this will separate them most of the time.

    There'll still be occasions when your logic doesn't succeed in making them pit on different laps (its hard to account for every eventuality), and in that case you need a fallback. Obviously you check the team-mate's car for (car->_state & RM_CAR_STATE_PIT) as that tells you if they're already occupying a pit and can be used to stop the second car trying to pit. It won't work though if a car is in the pit lane en route to the pits & hasn't arrived there yet, and your 2nd car commits to pit as well.

    For this instance I added a very simple low-tech feature to Axiom this year (Axiom was sporadically double-pitting last year). Whenever a car decided it needed to pit, its headlights are turned on - and when its emerged from the pitstop it turns them off again. Hence before pitting a car I just need to check if the team-mate has his lights on. If he doesn't, I pit, if he does, I don't. I think I used shared memory in USR for this, I don't remember as it was quite a while ago that I worked on that part of the code.
    Last Edited: 2017-06-13 16:25:37 by firechief
      Author: fa1 | Created: 2017-06-15 18:08:38
      Subject: Re: How to find out if pit is occupied
      Using the lights to communicate is a smart idea ...
      Last Edited: 2017-06-15 18:08:38 by fa1