SIO2 Posted October 13, 2022 Share Posted October 13, 2022 This is a routine from Frogus (a Frogger type game) that I am working on (in 7800 basic). There are five lanes of traffic with up to three cars in each lane. Within each lane there are seven slots where a car could potentially be placed. This routine randomly places cars into the slots in each lane. It works but is rather long. I am interested to know if anyone has ideas that might make it more compact? build_cars.txt Quote Link to comment Share on other sites More sharing options...
+splendidnut Posted October 13, 2022 Share Posted October 13, 2022 Why are you not using loops? The key benefit to having things in an array is that you can easily loop over them. 2 Quote Link to comment Share on other sites More sharing options...
+SmittyB Posted October 13, 2022 Share Posted October 13, 2022 The biggest improvement I can see is in how you're reducing your random values to the range of 1-7. Instead of running through each of those checks you can store your random value to a temp variable, then use a bitwise AND of 7 to cut it down to a range of 0-7, and then check that if it's zero you can try randomising it again or set it to something specific. Once that's done, store it back to your array and then move on to the next one. Doing the above then let's you easily loop through all of your lanes by incrementing which index in the array you're storing to when you get a valid random value. Thirdly, I'm not sure how good 7800basic is at 'remembering' which array entry you're working with, so essentially every time you mention an array entry it has to reload memory. You can avoid that by reading the array once into a temp variable and working with that. Lastly, this is the sort of thing that assembly would be really good at optimising if you want to give it a go. 1 Quote Link to comment Share on other sites More sharing options...
SIO2 Posted October 14, 2022 Author Share Posted October 14, 2022 Excellent suggestions. Thank you both. It is often a long while between times that I program so, still clearing the cobwebs. I appreciate the responses. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.