Artificial intelligence (AI) often has such a problem, that is what I want to do? What am I supposed to do? What do I need? So what is called intelligence here is the judgment given to an AI object, and the corresponding response it receives from judgment. Like, you go to the store to buy things, enough money to sell you, not enough to sell you, here will trigger two results, if you want to buy, then the clerk may have a corresponding measure. In fact, the clerk here is equivalent to what we call artificial intelligence, but the reaction and action of the Clerk is based on his own thinking, artificial intelligence also has the process of thinking, but more than the clerk thought much less. The process of thinking, that is, the process of logical setting and processing, then what is the state node?
Game
Logical setting (logic) 1, internal interface Creation (Setup)
The logical setting initializes the corresponding type, based on the method of creation in the passed-in script ID.
Get action (Get action)
Find the corresponding action pointer based on the ID of the action, and note that the action list here is the data in the logical setting object.
Get status (Get state)
Finds the corresponding state data pointer in the object's state table, based on the state.
Get initialization status (GET init state)
Gets the state of the initialization setting.
Get the script ID (get scripts ID)
Gets the current script ID.
Invoke action (call action)
Depending on the role of the object pointer, as well as the action handler, invoke the appropriate method of the script and return to the next action.
2. Lua Interface creation action (new action)
In Lua, two parameters are passed in: The Action ID and the action's key (callback), and the action is added to the manager based on these two parameters.
Add status (new state)
A state is passed in from Lua and added to the state table.
Set initialization status (SET init state)
A state is passed in the script and the state is set to its initial state.
Registered user Action (Register users action)
Two parameters: The key of the action callback, the method string of the action callback, and the two data are added to the User Action table.
Status node (state) 1, internal interface get event callback (get event handler) output status information (print state info) 2, LUA interface processing event (handle event) algorithm (matrix algorithm) inverse spiral matrix Code.
#include <stdio.h>#include<stdint.h>/** * Anti-spiral Matrix * For example: 5x5 anti-Spiral Matrix * *-0 1 2 3 4----as column ordinal * ———————————————————— * 0 | 1 16 15 14 13 * 1 | 2 17 24 23 12 * 2 | 3 18 25 22 11 * 3 | 4 19 20 21 10 * 4 | 5 6 7 8 9 * | * | * As Line ordinal * * This matrix can be treated as an array of array[5][5] based on rows and columns * First we need to know the rule of the anti-spiral, that is, starting at a certain point in 1 counterclockwise direction to increase by 1 * Second we all know the spiral, divided into a circle, then a spiral has its lap number, Unlike a circle, the matrix * is divided into 4 directions, the top, left, bottom, and right (the data that makes up a circle) * then the rules for analyzing ordinal numbers from the direction of data increment * Left: line number is incremented to 1, column number is unchanged * Bottom: column number is incremented to 1, row number is unchanged * Right: line number is decremented to 1, column number is unchanged * Top: Column Number is decremented to 1, the line number is unchanged * If the definition line number is I, the column number is J, the number of laps is K, then the three data in each lap is not a similar rule? * First we need to determine the number of laps, it is related to the size of the matrix, that is, if it is a matrix of nxn, the number of laps m= (N + 1)/2 * With the number of laps, we are sure that we need several loops to form the data per lap * We set the outermost lap of the lap to 0, so that it loops to the last lap as K-1 * false The variable to set the data is value, starting from 1 * data from 1 to 1 from the outermost layer, and sequentially from the left, bottom, right, the formation of the circle of data, to the last layer so far * data law on the left: the number of rows from the number of laps K, followed by 1, the number is equal to the number of laps K = k; i < n-k; ++i) array[i][k] = value++; * The following data rule: The column number starts with the number of laps, k+1 to less than the data n-k, and its number of rows is n-k-1 * for (j = k + 1; j < n-k; ++j) array[n-k-1][J] = value++; * Data rule on the left: line number starts at N-k-2, loops to no less than K, and its number of columns is n-k-1 * for (i = n-k-2; I <= K; i.) ARRAY[I][N-K-1] = value++; * Above Data Law: column number starting from N-k-2, loop to K, the number of rows is K * for (j = n-k-2; j > k;--j) array[k][j] = value++;*/ #defineArray_max 100//maximum number of supported matrices//Build MatrixvoidGenerate_array (int32_t Array[array_max][array_max], int32_t length);//Print MatrixvoidDisplay_array (int32_t Array[array_max][array_max], int32_t length);voidGenerate_array (int32_t Array[array_max][array_max], int32_t length) {int32_t I, j, K; int32_t value, Circle_count; Value=1; int32_t&n =length; Circle_count= (n +1) /2; for(k =0; K < Circle_count; ++k) { for(i = k; i < n-k; ++i) array[i][k] = value++;// Left for(j = k +1; J < N-k; ++J) Array[n-k-1][J] = value++;//Bottom for(i = n-k-2; I >= K; -I.) ARRAY[I][N-K-1] = value++;// Right for(j = n-k-2; J > k; --J) Array[k][j] = value++;//Top }}voidDisplay_array (int32_t Array[array_max][array_max], int32_t length) {int32_t I, J; for(i =0; i < length; ++i) { for(j =0; J < length; ++J) printf ("%4d", Array[i][j]); printf ("\ n"); }};int32_t Main (int32_t argc,Char*argv[]) {int32_t n=0; int32_t Array[array_max][array_max]; while(N <=0|| n >Array_max) {printf ("Please input a unsigned int number (less than 0 and not above%d):", Array_max); scanf ("%d", &N); } generate_array (array, n); printf ("The anti spiral array is: \ n"); Display_array (array, n); return 0;}
Result.
Member recruitment (long-term validity)
If you are also interested in open source knowledge, if you are interested in Web applications or online games, if you are interested in the framework, you can join our QQ group (348477824).
Welcome to the group to exchange learning with each other, but also welcome all friends to the framework for their own efforts.
Plain Framework Business Edition core membership recruitment
Please join the above Framework QQ group, the commercial core members of the recruitment eligibility and form will be published in the form of blogs or documents (confirmed candidates within 14 years).
MMORPG large game design and development (server AI logic settings and Status nodes)