How to store interaction using Hashtable and use AI to act on it
I found out there is a hashtable function in Unity, and I have been figuring out how to implement it in my game.
My game has a series of obstacles and requires a player to navigate and maneuver themselves to reach the finish line. I was wondering how I could make it so that when the player reaches an obstacle and do for example: Move right, Jump, Move Right, Move Left; it will be stored as a value on the hashtable for that specific obstacle.
Should I make it so the obstacle have a motion so that it can be stored as a key in the hashtable or are there alternatives in doing this?
I will be using the key-value from the hashtable as a basis for my AI to act based on the player's behaviour.
When I want unique keys for a set of numerical representations I usually bitshift the values into a ulong and use the ulong as the key. So if right = 10, jump = 14, left = 13 I would bitshift these 8-bit numbers into a 64-bit number. So first I would do something like (in pseudocode) Int16 newInt16 = ((Int16) right << 8) + (Int16)jump
to get a 16-bit number. Then I would add two 16 bit numbers into a 32-bit number and two 32-bit into a 64-bit number.
Can you explain a bit more? I have to declare right,jump, and left as an ulong value?
I'm quite lost in your explanation as I am new to Unity
I just mean that you can encode a series of actions this way :) Ins$$anonymous$$d of e.g. adding them to a list. Adding an encoded ulong to a hashset in C# (or a Unity hashtable, I suppose they work the same way). I only have experience from C# and in C# you can't use e.g. an array as the key (it can't differenciate between two arrays depending on the objects IN the array). So you have to come up with a way to encode your array/list of commands into a single values. This is where bitshifting your command into a single ulong comes in handy. So your commands/movements should be 8-bit values (range 0-255). You then encode them in order of input to a "total input" ulong (by first bitshifting them into a 16-bit value, then a 32-bit value and last a 64-bit value). So you would be able to fit 64/8 = 8 inputs into a single ulong. So if you need longer sequences of input this won't work for you.
Your answer
Follow this Question
Related Questions
Genetic Algorithm OverflowException: Number overflow: 1 Answer
how in order to pursue many targets? 0 Answers
How can I check for an inputted word against a list of words in a text file? 0 Answers
Choosing non null values from arrays for pathfinding 2 Answers
Need assistance with an primitive AI. 0 Answers