42 #define BRAINCODE_MIN_MVB_SPACING 2
44 #define BRAINCODE_CONSTANT0_BIT (64)
45 #define BRAINCODE_CONSTANT1_BIT (128)
47 #define BRAINCODE_DATA_START BRAINCODE_DAT0
48 #define BRAINCODE_DATA_NUMBER (1 + BRAINCODE_DAT1 - BRAINCODE_DATA_START)
50 #define BRAINCODE_OPERATORS_START BRAINCODE_ADD
51 #define BRAINCODE_OPERATORS_NUMBER (1 + BRAINCODE_LTP - BRAINCODE_OPERATORS_START)
53 #define BRAINCODE_CONDITIONALS_START BRAINCODE_JMZ
54 #define BRAINCODE_CONDITIONALS_NUMBER (1 + BRAINCODE_SLT - BRAINCODE_CONDITIONALS_START)
56 #define BRAINCODE_SENSORS_START BRAINCODE_SEN
57 #define BRAINCODE_SENSORS_NUMBER (1 + BRAINCODE_SEN3 - BRAINCODE_SENSORS_START)
59 #define BRAINCODE_ACTUATORS_START BRAINCODE_ACT
60 #define BRAINCODE_ACTUATORS_NUMBER (1 + BRAINCODE_ANE - BRAINCODE_ACTUATORS_START)
62 #define BRAINCODE_INSTRUCTION(braincode,i) ((braincode[i] & (BRAINCODE_CONSTANT0_BIT-1)) % BRAINCODE_INSTRUCTIONS)
63 #define BRAINCODE_CONSTANT0(braincode,i) (braincode[i] & BRAINCODE_CONSTANT0_BIT)
64 #define BRAINCODE_CONSTANT1(braincode,i) (braincode[i] & BRAINCODE_CONSTANT1_BIT)
65 #define BRAINCODE_VALUE(braincode,i,n) (braincode[i+1+n])
69 #define B_SIZE (32768)
70 #define B_WR (B_SIZE - 1)
74 #define B_Z (B_SIZE - F_Z)
75 #define B_Y (B_SIZE - F_Y)
76 #define B_X (B_SIZE - F_X)
90 #define B_FN(ave, bra, obra) ((ave+bra-obra)>>10)
93 #define B_P_LH (br[loc+F_Z]+br[loc+F_Y]+br[loc+F_X])
94 #define B_P_UH (br[loc-F_X]+br[loc-F_Y]+br[loc-F_Z])
95 #define B_N_LH (br[(loc+F_X)&B_WR]+br[(loc+F_Y)&B_WR]+br[(loc+F_Z)&B_WR])
96 #define B_N_UH (br[(loc+B_Z)&B_WR]+br[(loc+B_Y)&B_WR]+br[(loc+B_X)&B_WR])
107 n_int l_a = constants[0];
108 n_int l_c = constants[2];
109 n_int l_b = constants[1] + l_c;
131 br[loc++] = (
n_byte)(average>>10);
139 average = br[loc-
F_Z];
140 average += br[loc-
F_Y];
141 average += br[loc-
F_X];
145 average += br[loc+
F_X];
146 average += br[loc+
F_Y];
147 average += br[loc+
F_Z];
155 br[loc++] = (
n_byte)(average>>10);
173 br[loc++] = (
n_byte)(average>>10);
186 #define BC_FORMAT_A 0
187 #define BC_FORMAT_C 1
188 #define BC_FORMAT_E 2
189 #define BC_FORMAT_F 3
190 #define BC_FORMAT_G 4
191 #define BC_FORMAT_H 5
258 if ((!is_constant0) && (!is_constant1))
272 if ((!is_constant0) && (!is_constant1))
294 if ((is_constant0) && (!is_constant1))
298 if ((is_constant0) && (is_constant1))
302 if ((!is_constant0) && (is_constant1))
395 output[0] = brain_vc((value >> 0) & 7,0);
396 output[1] = brain_vc((value >> 3) & 3,1);
397 output[2] = brain_vc((value >> 5) & 7,0);
408 n_byte command = response[0];
409 n_byte value0 = response[1];
410 n_byte value1 = response[2];
412 n_int format = brain_format(instruction, command, value0, value1);
444 n_byte command = response[0];
445 n_byte value0 = response[1];
446 n_byte value1 = response[2];
448 n_int format = brain_format(instruction, command, value0, value1);
452 brain_longword(first_word, value0);
453 brain_longword(second_word, value1);
461 io_string_write(
string, braincode_spoken_dictionary[instruction], &position);
467 io_string_write(
string, braincode_spoken_dictionary[instruction], &position);
472 io_string_write(
string, braincode_spoken_dictionary[instruction], &position);
491 switch(instruction_type)
513 n_int * no_of_sensors,
514 n_int * no_of_actuators,
515 n_int * no_of_operators,
516 n_int * no_of_conditionals,
520 n_int i,j,instruction;
523 *no_of_actuators = 0;
524 *no_of_operators = 0;
525 *no_of_conditionals = 0;
542 *no_of_sensors = *no_of_sensors + 1;
546 *no_of_actuators = *no_of_actuators + 1;
550 *no_of_operators = *no_of_operators + 1;
554 *no_of_conditionals = *no_of_conditionals + 1;
558 *no_of_data = *no_of_data + 1;
583 total = prob[0] + prob[1] + prob[2] + prob[3] + prob[4];
594 for (i=0; i<5; i++,total+=prob[i])
619 if (i == 0)
return 0;
631 static n_int get_actor_index_from_episode(
636 n_int i,actor_index=-1;
642 if (social_graph[i].family_name == episodic_event[episode_index].family_name)
645 if (social_graph[i].first_name == episodic_event[episode_index].first_name)
667 static n_int attention_similar(
n_int episode_index,
669 n_int * memory_visited,
670 n_int * carry_through,
676 n_int next_episode_index = -1;
677 if (visited_max<0) visited_max=0;
681 if (episodic[i].event == 0)
continue;
683 if (i != episode_index)
686 if (memory_visited[i] <= visited_max)
689 n_int diff =
function(&episodic[i], carry_through);
690 if (diff < 0) diff = -diff;
691 if ((min == -1) || (diff < min))
695 next_episode_index = i;
700 if (next_episode_index>-1)
703 memory_visited[next_episode_index] = memory_visited[episode_index]+1;
705 return next_episode_index;
731 static n_int attention_similar_time(
n_int episode_index,
733 n_int * memory_visited)
736 return attention_similar(episode_index, episodic, memory_visited, &time, similar_time);
761 static n_int attention_similar_affect(
n_int episode_index,
763 n_int * memory_visited)
766 return attention_similar(episode_index, episodic, memory_visited, &affect, similar_affect);
777 n_int similarity = 3;
782 if (values[0] == carry_through[0]) similarity--;
783 if (values[1] == carry_through[1]) similarity--;
796 static n_int attention_similar_name(
n_int episode_index,
799 n_int * memory_visited)
810 return attention_similar(episode_index, episodic, memory_visited, name, similar_name);
836 static n_int attention_similar_date(
n_int episode_index,
838 n_int * memory_visited)
841 return attention_similar(episode_index, episodic, memory_visited, &time, similar_date);
855 n_int da = (dx * dx) + (dy * dy);
866 static n_int attention_similar_place(
n_int episode_index,
868 n_int * memory_visited)
873 return attention_similar(episode_index, episodic, memory_visited, location, similar_place);
888 switch (switcher % 32)
915 return meeter_social_graph[actor_index].
familiarity&255;
917 return meeter_social_graph[actor_index].
friend_foe;
919 return meeter_social_graph[actor_index].
attraction;
1036 n_byte half_switcher = switcher >> 1;
1037 noble_being * important_being = ((switcher & 1) ? met_being : meeter_being);
1039 switch (half_switcher % 10)
1063 return_value = immune->
antigens[0];
1066 if (immune->
antigens[n]>return_value)
1068 return_value = immune->
antigens[n];
1072 return return_value;
1076 if ((
internal!=0) &&
1090 if (positive>255) positive=255;
1098 if (negative>255) negative=255;
1102 return additional_write[0];
1117 n_uint i,max_familiarity = 1;
1128 if (max_familiarity == 0)
1133 result = (
n_byte)(familiarity*255/max_familiarity);
1138 #define IS_CONST0 (is_constant0 ? value0 : addr0[0])
1139 #define IS_CONST1 (is_constant1 ? value1 : addr1[0])
1162 n_byte internal = (meeter_being == met_being);
1164 n_int i = 0, itt = 0;
1165 n_int actor_index, possible_actor_index;
1169 n_int anecdote_episode_index=-1;
1170 n_int intention_episode_index=-1;
1175 n_int max_itterations;
1189 if (meeter_being == met_being)
1204 memory_visited[i] = 0;
1209 while (itt<max_itterations)
1224 addr1[0] = brain_first_sense(sim,meeter_being, met_being, meeter_social_graph, actor_index, addr0[0]);
1229 n_int new_episode_index=-1;
1230 n_int switcher = addr0[0]%25;
1237 actor_index = get_actor_index(meeter_social_graph,
IS_CONST1 % SOCIAL_SIZE);
1255 new_episode_index = attention_similar_place(episode_index, episodic, memory_visited);
1258 new_episode_index = attention_similar_time(episode_index, episodic, memory_visited);
1261 new_episode_index = attention_similar_date(episode_index, episodic, memory_visited);
1264 new_episode_index = attention_similar_name(episode_index, episodic, meeter_being, memory_visited);
1267 new_episode_index = attention_similar_affect(episode_index, episodic, memory_visited);
1270 addr1[0] = episodic[episode_index].
event;
1273 addr1[0] = episodic[episode_index].
food;
1276 addr1[0] = episodic[episode_index].
affect&255;
1279 addr1[0] = episodic[episode_index].
arg&255;
1292 if (pressure > 100000) pressure = 100000;
1293 if (pressure < 0) pressure = 0;
1294 addr1[0] = (
n_byte)(pressure>>9);
1304 if (wind.
x<0) wind.
x=-wind.
x;
1305 if (wind.
y<0) wind.
y=-wind.
y;
1306 addr1[0] = (
n_byte)((wind.
x+wind.
y)>>7);
1324 addr1[0] = territory_familiarity(meeter_being,(
n_byte2)territory_index);
1328 addr1[0] = territory_familiarity(met_being,(
n_byte2)territory_index);
1379 if (carrying & obj_type)
1414 if (new_episode_index>-1)
1416 episode_index = new_episode_index;
1419 possible_actor_index = get_actor_index_from_episode(meeter_social_graph,episodic,episode_index);
1420 if (possible_actor_index>-1)
1422 actor_index = possible_actor_index;
1435 addr1[0] = brain_third_sense(sim,meeter_being, met_being,
internal, addr0[0], addr1);
1444 if ((awake != 0) && (addr0[0] > 127))
1473 if (fof0>(
n_byte)(fof1+85))
1475 if (meeter_social_graph[actor_index].friend_foe < 170)
1477 meeter_social_graph[actor_index].
friend_foe++;
1480 if (fof1>(
n_byte)(fof0+85))
1482 if (meeter_social_graph[actor_index].friend_foe > 85)
1484 meeter_social_graph[actor_index].
friend_foe--;
1492 n_byte att0=addr1[0],att1=pspace[0];
1494 if (att0>(
n_byte)(att1+85))
1496 if (meeter_social_graph[actor_index].attraction < 255)
1498 meeter_social_graph[actor_index].
attraction++;
1501 if (att1>(
n_byte)(att0+85))
1503 if (meeter_social_graph[actor_index].attraction > 16)
1505 meeter_social_graph[actor_index].
attraction--;
1513 if ((addr1[0]>100) && (addr1[0]<150))
1515 if (meeter_social_graph[actor_index].familiarity < 65535)
1521 if ((addr1[0]>150) && (addr1[0]<200))
1523 if (meeter_social_graph[actor_index].familiarity > 10)
1569 if ((
internal!=0) && (awake!=0) &&
1588 if (intention_episode_index != episode_index)
1594 intention_episode_index = episode_index;
1635 if ((prf > 55) && (prf<155))
1661 if (anecdote_episode_index != episode_index)
1665 anecdote_episode_index = episode_index;
1673 addr0, addr1, value0, &i,
1678 braincode_min_loop);