I(ps.rdflags), SA(ps.stats, MAX_STATS), SZ(pers.userinfo, MAX_INFO_STRING), SZ(pers.netname, 16), I(pers.hand), I(pers.connected), I(pers.health), I(pers.max_health), I(pers.savedFlags), I(pers.selected_item), IA(pers.inventory, MAX_ITEMS), I(pers.max_bullets), I(pers.max_shells), I(pers.max_rockets), I(pers.max_grenades), I(pers.max_cells), I(pers.max_slugs), T(pers.weapon), T(pers.lastweapon), I(pers.power_cubes), I(pers.score), I(pers.game_helpchanged),
void MovimentaMonstros(Monstros Monstros[], Heroi Heroi, int QtdMonstros) { //Cria os objetos só para passar para a funcao. Não faz nada com eles. MagiasHeroi MagiasHeroi; MagiasMonstros MagiasMonstros; NPC NPC; Itens Itens; int i; int AuxPosy; Estado = normal; //Inicia o Estado NORMAL da IA (Não faz nada). for (i = 0; i < QtdMonstros; i++) //Roda o array monstros { if (Monstros[i].Vivo && Monstros[i].Andar) //Verifica se o monstro esta vivo { IA(Monstros[i], Heroi); switch (Estado) { case perseguindo: // Perseguindo /* Correção do Bug da Movimentação do Monstro */ /* ------------------------------------------------- */ if (Heroi.y - Monstros[i].y < Monstros[i].Velocidade && Heroi.y - Monstros[i].y > (Monstros[i].Velocidade) * -1) { AuxPosy = Heroi.y - Monstros[i].y; if (AuxPosy < 0) Monstros[i].y += AuxPosy; else Monstros[i].y -= AuxPosy; } /* ------------------------------------------------- */ if (Monstros[i].y > Heroi.y) Monstros[i].Sentido = up; else if (Monstros[i].y < Heroi.y) Monstros[i].Sentido = down; else if (Monstros[i].x > Heroi.x) Monstros[i].Sentido = left; else if (Monstros[i].x < Heroi.x) Monstros[i].Sentido = right; if (Monstros[i].Sentido == up) { Monstros[i].y -= Monstros[i].Velocidade; Monstros[i].LinhaAnimacao = 3; break; } else if (Monstros[i].Sentido == Down) { Monstros[i].y += Monstros[i].Velocidade; Monstros[i].LinhaAnimacao = 0; break; } else if (Monstros[i].Sentido == left) { Monstros[i].x -= Monstros[i].Velocidade; Monstros[i].LinhaAnimacao = 1; break; } else if (Monstros[i].Sentido == right) { Monstros[i].x += Monstros[i].Velocidade; Monstros[i].LinhaAnimacao = 2; break; } break; case fugindo: // Fugindo Monstros[i].Sentido = -1; if (Monstros[i].y < Heroi.y) { //UP Monstros[i].y -= Monstros[i].Velocidade; Monstros[i].LinhaAnimacao = 3; break; } if (Monstros[i].x < Heroi.x) { //Esquerda Monstros[i].x -= Monstros[i].Velocidade; Monstros[i].LinhaAnimacao = 1; break; } if (Monstros[i].x > Heroi.x) { //Direita Monstros[i].x += Monstros[i].Velocidade; Monstros[i].LinhaAnimacao = 2; break; } if (Monstros[i].y > Heroi.y) { //Down Monstros[i].y += Monstros[i].Velocidade; Monstros[i].LinhaAnimacao = 0; break; } break; } /* Colisão do Monstro com o Personagem */ if (Estado != normal) { if (ColisaoTotal(Heroi, Monstros[i], MagiasHeroi, MagiasMonstros, Itens, NPC, Movimentacao, MonstrosEHeroi)) //|| ColisaoMonstroMonstro(Monstros, QtdMonstros)) { if (Monstros[i].Sentido == up) Monstros[i].y += Monstros[i].Velocidade; if (Monstros[i].Sentido == down) Monstros[i].y -= Monstros[i].Velocidade; if (Monstros[i].Sentido == left) Monstros[i].x += Monstros[i].Velocidade; if (Monstros[i].Sentido == right) Monstros[i].x -= Monstros[i].Velocidade; } } if (++Monstros[i].frameCount >= Monstros[i].frameDelay) { Monstros[i].curFrame += Monstros[i].animationDirection; if (Monstros[i].curFrame >= Monstros[i].maxFrame) Monstros[i].curFrame = Monstros[i].curFramePadrao; else if (Monstros[i].curFrame <= Monstros[i].curFramePadrao) Monstros[i].curFrame = Monstros[i].maxFrame - 1; Monstros[i].frameCount = 0; } redraw = true; } } }
int IA(int player,int depth,int lx,int ly,int w1x,int w1y,int w2x,int w2y,int w3x,int w3y,int w4x,int w4y,int w5x,int w5y) { int count = 0,k; t_association pawn[6]={{NULL,{lx,ly}},{NULL,{w1x,w1y}},{NULL,{w2x,w2y}},{NULL,{w3x,w3y}},{NULL,{w4x,w4y}},{NULL,{w5x,w5y}}}; //printf("mouton %d:%d , loups : %d:%d %d:%d %d:%d %d:%d %d:%d\n",lx,ly,w1x,w1y,w2x,w2y,w3x,w3y,w4x,w4y,w5x,w5y); if(game_is_over(pawn)) { if(lamb_won(pawn)) { return importance(depth); } else { return (-1 * importance(depth)); } } if(depth == 0) return 0; if(player == LAMB) { if(possible_and_free(lx+1,ly+1,pawn) && isnt_too_far(lx+1,ly+1,pawn)) count += IA(WOLF,depth - 1,lx+1,ly+1,w1x,w1y,w2x,w2y,w3x,w3y,w4x,w4y,w5x,w5y); if(possible_and_free(lx+1,ly-1,pawn) && isnt_too_far(lx+1,ly-1,pawn)) count += IA(WOLF,depth - 1,lx+1,ly-1,w1x,w1y,w2x,w2y,w3x,w3y,w4x,w4y,w5x,w5y); if(possible_and_free(lx-1,ly+1,pawn) && isnt_too_far(lx-1,ly+1,pawn)) count += IA(WOLF,depth - 1,lx-1,ly+1,w1x,w1y,w2x,w2y,w3x,w3y,w4x,w4y,w5x,w5y); if(possible_and_free(lx-1,ly-1,pawn) && isnt_too_far(lx-1,ly-1,pawn)) count += IA(WOLF,depth - 1,lx-1,ly-1,w1x,w1y,w2x,w2y,w3x,w3y,w4x,w4y,w5x,w5y); } else { for(k=1;k<6;k++) { if(possible_and_free(pawn[k].position.x+1,pawn[k].position.y-1,pawn)) { switch(k) { case 1: count += IA(LAMB,depth - 1,lx,ly,w1x+1,w1y-1,w2x,w2y,w3x,w3y,w4x,w4y,w5x,w5y); break; case 2: count += IA(LAMB,depth - 1,lx,ly,w1x,w1y,w2x+1,w2y-1,w3x,w3y,w4x,w4y,w5x,w5y); break; case 3: count += IA(LAMB,depth - 1,lx,ly,w1x,w1y,w2x,w2y,w3x+1,w3y-1,w4x,w4y,w5x,w5y); break; case 4: count += IA(LAMB,depth - 1,lx,ly,w1x,w1y,w2x,w2y,w3x,w3y,w4x+1,w4y-1,w5x,w5y); break; case 5: count += IA(LAMB,depth - 1,lx,ly,w1x,w1y,w2x,w2y,w3x,w3y,w4x,w4y,w5x+1,w5y-1); break; } } if(possible_and_free(pawn[k].position.x-1,pawn[k].position.y-1,pawn)) { switch(k) { case 1: count += IA(LAMB,depth - 1,lx,ly,w1x-1,w1y-1,w2x,w2y,w3x,w3y,w4x,w4y,w5x,w5y); break; case 2: count += IA(LAMB,depth - 1,lx,ly,w1x,w1y,w2x-1,w2y-1,w3x,w3y,w4x,w4y,w5x,w5y); break; case 3: count += IA(LAMB,depth - 1,lx,ly,w1x,w1y,w2x,w2y,w3x-1,w3y-1,w4x,w4y,w5x,w5y); break; case 4: count += IA(LAMB,depth - 1,lx,ly,w1x,w1y,w2x,w2y,w3x,w3y,w4x-1,w4y-1,w5x,w5y); break; case 5: count += IA(LAMB,depth - 1,lx,ly,w1x,w1y,w2x,w2y,w3x,w3y,w4x,w4y,w5x-1,w5y-1); break; } } } } return count; }
static void generate_round_keys(int rnds,uint32_t* K, uint32_t* x, uint32_t* z) { COMPUTE_Z; K[1]=S5[IA(z[2])]^S6[IB(z[2])]^S7[ID(z[1])]^S8[IC(z[1])]^S5[IC(z[0])]; K[2]=S5[IC(z[2])]^S6[ID(z[2])]^S7[IB(z[1])]^S8[IA(z[1])]^S6[IC(z[1])]; K[3]=S5[IA(z[3])]^S6[IB(z[3])]^S7[ID(z[0])]^S8[IC(z[0])]^S7[IB(z[2])]; K[4]=S5[IC(z[3])]^S6[ID(z[3])]^S7[IB(z[0])]^S8[IA(z[0])]^S8[IA(z[3])]; COMPUTE_X; K[5]=S5[ID(x[0])]^S6[IC(x[0])]^S7[IA(x[3])]^S8[IB(x[3])]^S5[IA(x[2])]; K[6]=S5[IB(x[0])]^S6[IA(x[0])]^S7[IC(x[3])]^S8[ID(x[3])]^S6[IB(x[3])]; K[7]=S5[ID(x[1])]^S6[IC(x[1])]^S7[IA(x[2])]^S8[IB(x[2])]^S7[ID(x[0])]; K[8]=S5[IB(x[1])]^S6[IA(x[1])]^S7[IC(x[2])]^S8[ID(x[2])]^S8[ID(x[1])]; COMPUTE_Z; K[9]=S5[ID(z[0])]^S6[IC(z[0])]^S7[IA(z[3])]^S8[IB(z[3])]^S5[IB(z[2])]; K[10]=S5[IB(z[0])]^S6[IA(z[0])]^S7[IC(z[3])]^S8[ID(z[3])]^S6[IA(z[3])]; K[11]=S5[ID(z[1])]^S6[IC(z[1])]^S7[IA(z[2])]^S8[IB(z[2])]^S7[IC(z[0])]; K[12]=S5[IB(z[1])]^S6[IA(z[1])]^S7[IC(z[2])]^S8[ID(z[2])]^S8[IC(z[1])]; COMPUTE_X; if (rnds==16) { K[13]=S5[IA(x[2])]^S6[IB(x[2])]^S7[ID(x[1])]^S8[IC(x[1])]^S5[ID(x[0])]; K[14]=S5[IC(x[2])]^S6[ID(x[2])]^S7[IB(x[1])]^S8[IA(x[1])]^S6[ID(x[1])]; K[15]=S5[IA(x[3])]^S6[IB(x[3])]^S7[ID(x[0])]^S8[IC(x[0])]^S7[IA(x[2])]; K[16]=S5[IC(x[3])]^S6[ID(x[3])]^S7[IB(x[0])]^S8[IA(x[0])]^S8[IB(x[3])]; } }
void preIA(t_game *game,int depth) { time_t t0,t; int topleft,topright,bottomleft[5],bottomright[5],sum,i; int player = game->data.now->curplayer; t_association *pawn=game->pawn; int lx = pawn[0].position.x; int ly = pawn[0].position.y; int w1x = pawn[1].position.x; int w1y = pawn[1].position.y; int w2x = pawn[2].position.x; int w2y = pawn[2].position.y; int w3x = pawn[3].position.x; int w3y = pawn[3].position.y; int w4x = pawn[4].position.x; int w4y = pawn[4].position.y; int w5x = pawn[5].position.x; int w5y = pawn[5].position.y; t0 = time(NULL); if(player == LAMB) { if(possible_and_free(lx-1,ly+1,pawn) && isnt_too_far(lx-1,ly+1,pawn)) topleft = IA(LAMB,depth,lx-1,ly+1,w1x,w1y,w2x,w2y,w3x,w3y,w4x,w4y,w5x,w5y); else topleft = 0; if(possible_and_free(lx+1,ly+1,pawn) && isnt_too_far(lx+1,ly+1,pawn)) topright = IA(LAMB,depth,lx+1,ly+1,w1x,w1y,w2x,w2y,w3x,w3y,w4x,w4y,w5x,w5y); else topright = 0; if(possible_and_free(lx-1,ly-1,pawn) && isnt_too_far(lx-1,ly-1,pawn)) bottomleft[0] = IA(LAMB,depth,lx-1,ly-1,w1x,w1y,w2x,w2y,w3x,w3y,w4x,w4y,w5x,w5y); else bottomleft[0] = 0; if(possible_and_free(lx+1,ly-1,pawn) && isnt_too_far(lx+1,ly-1,pawn)) bottomright[0] = IA(LAMB,depth,lx+1,ly-1,w1x,w1y,w2x,w2y,w3x,w3y,w4x,w4y,w5x,w5y); else bottomright[0] = 0; t = time(NULL); printf("%d %d\n%d %d\n%ld sec\n",topleft,topright,bottomleft[0],bottomright[0],t-t0); sum = topleft + topright + bottomleft[0] + bottomright[0]; /*topleft = topleft * 1000 / sum; topright = topright * 1000 / sum; bottomleft[0] = bottomleft[0] * 1000 / sum; bottomright[0] = bottomright[0] * 1000 / sum;*/ if(abs(sum)< 4000) { if(possible_and_free(lx+1,ly+1,pawn) && possible_and_free(lx-1,ly+1,pawn)) make_movement(game,lx,ly,9-lx,ly+1); else if(possible_and_free(lx-1,ly+1,pawn)) make_movement(game,lx,ly,lx-1,ly+1); else if(possible_and_free(lx+1,ly+1,pawn)) make_movement(game,lx,ly,lx+1,ly+1); else if(possible_and_free(lx-1,ly-1,pawn)) make_movement(game,lx,ly,lx-1,ly-1); else if(possible_and_free(lx+1,ly-1,pawn)) make_movement(game,lx,ly,lx+1,ly-1); } else if(sum>=199999900) { if(possible_and_free(lx-1,ly+1,pawn)) make_movement(game,lx,ly,lx-1,ly+1); else if(possible_and_free(lx+1,ly+1,pawn)) make_movement(game,lx,ly,lx+1,ly+1); else if(possible_and_free(lx-1,ly-1,pawn)) make_movement(game,lx,ly,lx-1,ly-1); else if(possible_and_free(lx+1,ly-1,pawn)) make_movement(game,lx,ly,lx+1,ly-1); } else { if(maxi(topleft,topright,bottomleft[0],bottomright[0])== topleft && possible_and_free(lx-1,ly+1,pawn)) make_movement(game,lx,ly,lx-1,ly+1); else if(maxi(topleft,topright,bottomleft[0],bottomright[0])== topright && possible_and_free(lx+1,ly+1,pawn)) make_movement(game,lx,ly,lx+1,ly+1); else if(maxi(topleft,topright,bottomleft[0],bottomright[0])== bottomleft[0] && possible_and_free(lx-1,ly-1,pawn)) make_movement(game,lx,ly,lx-1,ly-1); else if(maxi(topleft,topright,bottomleft[0],bottomright[0])== bottomright[0] && possible_and_free(lx+1,ly-1,pawn)) make_movement(game,lx,ly,lx+1,ly-1); else if(possible_and_free(lx-1,ly+1,pawn)) make_movement(game,lx,ly,lx-1,ly+1); else if(possible_and_free(lx+1,ly+1,pawn)) make_movement(game,lx,ly,lx+1,ly+1); else if(possible_and_free(lx-1,ly-1,pawn)) make_movement(game,lx,ly,lx-1,ly-1); else if(possible_and_free(lx+1,ly-1,pawn)) make_movement(game,lx,ly,lx+1,ly-1); } game->data.now->curplayer = !game->data.now->curplayer; } else { if(wolves_in_line(game->pawn)) { i = next_wolf_to_move_in_line(game->pawn); if(possible_and_free(game->pawn[i].position.x-1,game->pawn[i].position.y-1,pawn)) make_movement(game,game->pawn[i].position.x,game->pawn[i].position.y,game->pawn[i].position.x-1,game->pawn[i].position.y-1); else make_movement(game,game->pawn[i].position.x,game->pawn[i].position.y,game->pawn[i].position.x+1,game->pawn[i].position.y-1); game->data.now->curplayer = !game->data.now->curplayer; } else { for(i=1;i<6;i++) { if(possible_and_free(pawn[i].position.x-1,pawn[i].position.y-1,pawn)) bottomleft[i] = IA(WOLF,depth,pawn[i].position.x-1,pawn[i].position.y-1,w1x,w1y,w2x,w2y,w3x,w3y,w4x,w4y,w5x,w5y); else bottomleft[i] = 0; if(possible_and_free(pawn[i].position.x+1,pawn[i].position.y-1,pawn)) bottomright[i] = IA(WOLF,depth,pawn[i].position.x+1,pawn[i].position.y-1,w1x,w1y,w2x,w2y,w3x,w3y,w4x,w4y,w5x,w5y); else bottomright[i] = 0; printf("[%d][%d] ",bottomleft[i],bottomright[i]); } } } }