int intelligence(){ srand(time(NULL)); int poption; int moption; int phits, mhits; int pdam, mdam; int escape = 0; if(hp <= 0){ mhp = 30; printf("You lost\n"); gameworld(); } if(mhp <= 0){ printf("You won\n"); mhp = 30; exp += 1; player(); } printf("Chose your action:\n 1.Attack 2.Magic attack\n"); scanf("%d", &poption); //How many hits phits = agi / 3; //Damage done by normal attack if (poption == 1){ (phits == 1)? printf("You have hit once\n"):printf("You have hit %d times\n", phits); //Damage amount pdam = str * phits; mhp -= (pdam - mdef); printf("Monsters health is:%d\n", mhp); } else if (poption == 2){ //Damage done by magic attack mhp -= (mp - mmp); } if(mhp <= 0){ printf("You won\n"); exp += 1; mhp = 30; player(); } if (mhp > 0){ moption = rand() % 2; if (moption == 0 || moption == 1){ hp = hp - (mstr - def); printf("Your current health is: %d\n", hp); escape++; intelligence(); } if (moption == 2 && escape == 0 ){ printf("Monster has escaped\n"); gameworld(); } } }
void AIPaddle::update(const GameTime& gameTime, GLuint topBound, GLuint bottomBound, const Point2& ballPos) { BasePaddle::update(gameTime, topBound, bottomBound); intelligence(ballPos); }
int sampleMethod() { int val,i,j,k; int * retVal; setPropertyFileName(".\\stackgameclient.properties"); printf("Waiting for handshake ... ...\n"); retVal = handShake(); printf("The response is: %d %d %d\n",retVal[0],retVal[1],retVal[2]); if (retVal[1] == RED_COINS) { Op = 4; Iam = 3; } else { Iam = 4; Op = 3; } if(retVal[2] == PLAY_SECOND) { printf("I am playing Second\n"); play =2; retVal = readMoves(); printf("The response is: %d %d %d %d %d %d\n",retVal[0],retVal[1],retVal[2],retVal[3],retVal[4],retVal[5]); retVal[1]-=1; retVal[2]-=1; retVal[4]-=1; retVal[5]-=1; update_board(retVal,1); for(i=0;i<8;i++) for(j=0;j<8;j++) for(k=0;k<5;k++) board[i][j][k] = t_board[i][j][k]; for(i=0;i<8;i++) for(j=0;j<8;j++) top[i][j] = t_top[i][j]; res = t_res; cap = t_cap; opp_res = t_opp_res; opp_cap = t_opp_cap; } else { play=1; printf("I am playing First\n"); } while(1) { val = intelligence(); for(i=0;i<8;i++) for(j=0;j<8;j++) for(k=0;k<5;k++) t_board[i][j][k] = board[i][j][k]; for(i=0;i<8;i++) for(j=0;j<8;j++) t_top[i][j] = top[i][j]; t_res = res; t_cap = cap; t_opp_res = opp_res; t_opp_cap = opp_cap; update_board(all_moves[val],0); for(i=0;i<8;i++) for(j=0;j<8;j++) for(k=0;k<5;k++) board[i][j][k] = t_board[i][j][k]; for(i=0;i<8;i++) for(j=0;j<8;j++) top[i][j] = t_top[i][j]; res = t_res; cap = t_cap; opp_res = t_opp_res; opp_cap = t_opp_cap; writeMoves(all_moves[val][0],all_moves[val][1]+1,all_moves[val][2]+1,all_moves[val][3],all_moves[val][4]+1,all_moves[val][5]+1); printf("Waiting for response ... ...\n"); retVal = readMoves(); printf("The response is: %d %d %d %d %d %d\n",retVal[0],retVal[1],retVal[2],retVal[3],retVal[4],retVal[5]); retVal[1]-=1; retVal[2]-=1; retVal[4]-=1; retVal[5]-=1; for(i=0;i<8;i++) for(j=0;j<8;j++) for(k=0;k<5;k++) t_board[i][j][k] = board[i][j][k]; for(i=0;i<8;i++) for(j=0;j<8;j++) t_top[i][j] = top[i][j]; t_res = res; t_cap = cap; t_opp_res = opp_res; t_opp_cap = opp_cap; update_board(retVal,1); for(i=0;i<8;i++) for(j=0;j<8;j++) for(k=0;k<5;k++) board[i][j][k] = t_board[i][j][k]; for(i=0;i<8;i++) for(j=0;j<8;j++) top[i][j] = t_top[i][j]; res = t_res; cap = t_cap; opp_res = t_opp_res; opp_cap = t_opp_cap; if(retVal[0] !=0 && retVal[0] != 1) { if(retVal[0] == GAME_ENDED) { break; } else if(retVal[0] == GAME_RESET) { break; } else if(retVal[0] == INVALID_MOVE) { break; } } } }