Now that we have our game state we can move on to working out what move we should make. We could, if we wanted, just click randomly on the game board and hope for results but that wouldn't really be in keeping with the project's aim, we want the system to actually play the game.
Deciding what the best move is depends on what we feel best means. Imagine a shoot'em up game where we are flying through space blasting aliens. We might decide it is best to go for the power up first and then dispatch the enemies or we might decide it is better to clear the screen of enemies and think of power-ups as a secondary objective. If we really wanted we could create a machine leaning algorithm that decides itself what is best based on experience, but that is for another day! For now we will stick to deciding ourselves what our goal is and that will help us decide what the best way to achieve it is.
For now I'm going to go with a simple goal, to clear a set of blocks from the screen with every click. This is a good goal as it will score us lots of points with each move and hopefully lead to us getting a high score come the end of the game. In the future we will have a more complex goal but we can use what we develop here as part of a bigger reasoner in the future as well and this tends to be how large A.I. systems work, lots of small reasoners working out simple things and then a larger reasoner combining all the results and deciding upon the best course of action.
So to work out which game piece will remove blocks from the board we need to find the a chain of connected, matching pieces in our game state. In keeping with our new, tidy code we'll put the code to do this into a separate function and call it from our main call in our JNI method. This is also going to be our first foray into pointers in C since I want to return 2 ints marking the row and column of the piece for our move but as we have learnt returning an array in C is a no no.
So this is going to be our function prototype:
void getMove(vector<vector<int> > gameState, int *row, int *column);
We pass in our gameState, a place to store the row to click on and a place to store the column to click on. Fairly simple, the hard task is filling this with the logic.
This is what our gameState current holds:
Our game state. |
How to find developers for your project? Here are some tips to help you to find the right developer and assemble the perfect development team.
ReplyDelete