How to determine optimal route across keyboard

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



How to determine optimal route across keyboard



I'm trying to automate the typing process in a video game. Players are given an on-screen QWERTY keyboard layout that they can navigate with the control stick (up, down, left, right) in order to select a letter to type. I was wondering if there was a module for Python (or some other resource I could explore) that would help my program find a path across the keyboard as it types each letter in a given message. In other words, if the first letter typed was "A" and the next letter was "B", the module would know that the program should move 1 space down on the keyboard and 4 spaces to the right.



Currently, I have the program resetting to the "G" key after each letter is typed (allowing me to use fixed-directions as the program parses each character in the desired message). As you can imagine, this is quite inefficient and defeats the purpose of automating the typing in the first place.





You can initially do a bfs from each key to get optimal route to the other keys, then use that in your computations.
– juvian
13 mins ago





Couldn't you just abstract the keyboard as a grid of letters and then apply the Manhatten Distance?
– timgeb
24 secs ago




1 Answer
1



Associate to each letter a position.



For example, Q would be (0,0), W (0,1), Z is (0,2), ... A (1,0) ...



This way it is very simple to find the shortest path (simple vectors substraction)



To compute the path Q -> S :



(0,0) - (1,1) = (-1,-1) so you need to do 1 down then 1 right.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS