简体   繁体   中英

Android specific order flow game algorithm?

This is my first time developing an android game. I want to create a flow game in which specific nodes must be connected in a particular order only. for eg a computer will connect to a modem and then the modem will connect to a router (its a network based game). So far the algorithms that i have come across do not deal with specific order free flow.(Refer this or this .) Is there an existing algorithm for this? PS I am making use of libGDX. 在此处输入图片说明

the game will be similar to this.

You will need to implement a simple finite state machine.

For implementation details, you can have a look at How to implement a FSM - Finite State Machine in Java

This has to be integrated into any algorithm (referred by you) to check validity.

Hope this helps. Good luck.

You won't be able to find an algorithm that is created just for this specific problem. What you are looking is a search algorithm, for example BFS and modify it to use in this game.

In BFS, you start with a cell and add valid neighbor cells into a queue and iterate through this queue until you reach to destination or queue is empty (you didn't reach the destination).

For this game, first you have to define which neighbors are valid. There are 7 types of cells

empty cells : never valid
destination : always valid, end algorithm here
source: never valid, you don't want to move source square back
vertical tunnel: only valid if previous cell is also a vertical tunnel or one of modem, router, source
horizontal tunnel: only valid if previous cell is also a horizontal tunnel or one of modem, router, source

modem and router cells will be a little trickier, while iterating through queue, you also need to push type of current path. Current path will be initially "source", if you pass through a modem it will be "modem" and if you pass through router it will be "router". With this in mind, rules for router and modem are

modem: only valid if current path is source or modem
router: only valid if current path is modem or router

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM