Hello, I am trying to find a simplistic approach to get the “AI” to choose only 4 options.
The 4 options are button 1, 2, 3, and 4. If all buttons are active it would turn into a probability of button 1 least likely to be chosen and button 4 most likely to be chosen.
One of the solutions I thought could work was making a visual chart for when certain buttons are active and not actives.
Example 1 —> 1, 2, 3, 4 are active with 1: 5% , 2: 5%, 3: 10%, 4 : 80% chance to activate.
Example 2 —> 1, 2, 3 are active with 1: 10% , 2: 10%, 3: 80% chance to activate.
And so on to complete every possibility. But that comes out as 8 different possibilities and I would like to be able to easily change these and realized how quickly this would become very ugly and long tedious code.
Another solution I thought was maybe a priority with 10 slots. Let’s say if 4 is ever active it would always be an “8” priority and with the 10 slots it would fill 8 of them. And random generator would look through the 10 slots and randomly choose one.
Anyone have any better idea’s I could do this? This is my first time coding any AI and I have done a bit of research on it and couldn’t find anything that suited my needs. I would prefer to keep it “stupid simple” lol.
This is a scripting question, not a game design question. But I love both AI and coding challenges, so I’m going to answer anyway.
I think you’re on the right track with a “visual chart” idea. You can implement this as a lookup table that will be verey easy to change. There are 16 possible combinations of 4 buttons, so you can convert your four buttons to an integer this way:
Assuming that btn1, btn2, etc. are integers set to 1 when the button is pressed, and 0 when it’s not pressed. So now you have a value from 0-15 which represents the state of the buttons, and (if I understand you correctly) you need to look up some list of probabilities for the AI. So, just make an array of these:
int[][] choiceProbs = new int[][] {
new int[] {0,0,0,0}, // no buttons pressed
new int[] {100,0,0,0}, // only button 1 pressed
new int[] {0,100,0,0}, // 2 pressed
new int[] {70,30,0,0}, // 1 and 2 pressed
// etc.
};
There are certainly other ways to structure it, but this seems simple and maintainable to me.
Thanks for the help, I was working on more idea’s for it today. I couldn’t think of any better ways of doing it. The buttons are actually 1,2,3,4 in an array as [0,1,2,3,].