





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






const int num_territories = 5; const int adj[num_territories][num_territories]= {0,1,0,0,0, 1,0,1,1,0, 0,1,0,0,0, 0,1,0,0,1, 0,0,0,1,0}; const char *name[num_territories]={ "brighamCity", "logan", "paradise", "smithfield", "preston"}; const int num_continents =3; const int continent[num_territories]={0,1,1,1,2}; const char *continent_name[num_territories]={"Flatland","Cache","Potatoland"}; const int continent_worth[num_territories] = {1,4,1}; int next_turn_in_value = 5; int num_players = 0; const int max_num_players = 6; int territory_owner[num_territories] = {-1,-1,-1,-1,-1}; int num_armies[num_territories] = {0,0,0,0,0}; int num_cards[max_num_players] = {0,0,0,0,0,0};
// This function gets called at the times when you are allowed to place // an army on the board. There may be unassigned territories -- if so, // you must pick one of those territories. If there are no unassigned // territories, then you must pick a territory that you currently own. // The return type is the territory you have chosen. Failure to correctly // choose a territory results in forfeiture of your turn. // // The return value is the territory where you wish to place your army. // int place_army_0001( int player_num, // your player number int card_earned, // true if you've earned a card this turn int * from, // not used int * to, // not used int * num) // not used { int i; int min=1000000; int choice; //if there are unclaimed territories, pick one of those for(i=0;i<num_territories;++i) if(territory_owner[i]==-1) return i; //else find my weakest territory and put it there for(i=0;i<num_territories;++i){ if(territory_owner[i]==player_num && num_armies[i]<min) { min = num_armies[i]; choice = i; } } return choice; }
// move to that territory. The num must be a minimum of 1 and a // maximum of the number of armies in the from territory minus 1. // int action_0001( int player_num, // your player number int card_earned, // true if you've earned a card this turn int * from, // the "from" territory int * to, // the "to" territory int * num ){ // how many armies int i; int j; int action_type; action_type = 0; //try to attack if(action_type == 0){ for(i=0; i<num_territories;++i){ for(j=0;j<num_territories;++j){ if(adj[i][j] && territory_owner[i]==player_num && territory_owner[j]!=player_num && num_armies[i] > num_armies[j]){ //neighbor is hostile *from =i; *to = j; *num=num_armies[i]-1; return action_type; } } } } action_type = 1; for(i=0;i<num_territories;++i) if(territory_owner[i] == player_num && num_armies[i]>1){ for(j=0;j<num_territories;++j ){ if(adj[i][j] && territory_owner[j] == player_num){ *from = i; *to = j; *num=num_armies[i]-1; return action_type; } } } //no possible move action_type = 1; *num = 0; return action_type;