### Coursework Help

Hi, for my second semester coursework we've been given a piece of code which is a darts game between two players Joe and Sid. Here is the code we were given :-

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209`` `````` // Darts part 1 // rules brushup, 2 lads called Joe and Sid are playing. Joe goes first and they can only throw one dart per turn. The game //can only be won/end by throwing a //bullseye on 50, anything else gets discounted. #include #include #include #include // rand/srand #include using namespace std; int r = rand()%100; int rnd_Joe = rand()%70; int rnd_Sid = rand()%72; int r_Single_Joe = rand()%100; int r_Single_Sid = rand()%100; int counts[51], i; // loop counter for J int Count[51], l; // loop counter for Sid int bull_throw_J(int); // Bull throw for Jay int bull_throw_S(int); // Bull throw for Sid int turn = 0; // will decide the turn of the player, if turn = 0 then its Joe, if it = 1 then its Sids turn :) int score [2] = {301,301}; int board[22] = {20, 1, 18, 4, 13, 6, 10, 15, 2, 17, 3, 19, 7, 16, 8, 11, 14, 9, 12, 5, 20, 1}; int single = board[0]; int X = -50 + score[2]; // logic to dictate what to aim for once score is less than 70 but more than 50 int throw_single_Joe(int single) //Throwing for single function (board) for Joe { if(rand()%100 < 80) // hit { return single; } else // miss { //to find neighbours search for single in board i = 0; do { i++; } while(board[i] != single); // now return left or right neighbour, each equally likely if(rand()%2==0) return board[i-1]; else return board[i+1]; } } int throw_single_Sid(int single) //Throwing for single function (board) for Sid { if(rand()%100<80) // hit { return single; } else // miss { //to find neighbours search for single in board l = 0; do { l++; } while(board[l] != single); // now return left or right neighbour, each equally likely if(rand()%2==0) return board[l-1]; else return board[l+1]; } } int bull_throw_J() //Bull Function (return 50 or 1 to 20) For Joe { if (r0) && (score [1] > 0)) //for( int h = 0; h<10000 ; h++) { if (((turn%2) == 0 ) && (score[0] > 70)) // 1st turn Joe { single = throw_single_Joe(20); // turn++; score[0] = score[0] - single; } if (((turn%2) == 1 ) && (score[1]>70)) // Sid { single = throw_single_Sid(20); //turn++; score[1] = score[1] - single; } if (((turn%2) == 0 ) && (score[0] < 70) && (score[0] > 50)) //if Joe's turn & his score is 51-69 { single = throw_single_Joe(score[0]-50); // turn++; if ((single == score[0] - 50) || (score[0] - single > 50)) { score[0] = score[0] - single; } } if (((turn%2) == 1 ) && (score[1] < 70) && (score[1] > 50)) //if Sid's turn & his score is 51-69 { single = throw_single_Sid(score[1]-50); // turn++; if ((single == score[1] - 50) || (score[1] - single > 50)) { score[1] = score[1] - single; } } if (((turn%2) == 0 ) && (score[0] == 50)) // Joe's Bull { single = bull_throw_J(); if (single == 50) { score[0] = 0; } } if (((turn%2) == 1 ) && (score[1] == 50)) // Sid's Bull { single = bull_throw_S(); if (single == 50) { score[1] = 0; } } if ((turn%2) == 0) { cout << "Joe hit" << single << "\n"; cout << "His score is " << score[0] << "\n"; } if ((turn%2) == 1) { cout << "Sid hit" << single << "\n"; cout << "His score is " << score[1] << "\n"; } turn++; } if (score[0] == 0) cout << "Joe won"; else cout << "Sid won"; cin >> turn; return 0; }``````

Our task is to make it so:-

- each player now has 3 darts and can throw 3 each turn instead of 1.
- the players can hit the double and treble areas.
- players must finish exactly on either a double or the bull.

Our lecturer gave us some functions to use for a double throw and a treble throw (which I will paste below) but I unsure how to implement them. If anyone could help on how I should implement these now features it would be greatly appreciated.

 ``1234567891011121314151617181920212223`` ``````int throw_treble(int d, int p) { // return result of throwing for treble d with accuracy p% (o<90) // Board neighbours ignoring slot zero int bd[2][21]={{0,20,15,17,18,12,13,19,16,14,6,8,9,4,11,10,7,2,1,3,5}, {0,18,17,19,13,20,10,16,11,12,15,14,5,6,9,2,8,3,4,7,1}}; int r = rand()%100; if(r

 ``123456789101112131415161718192021222324`` ``````int throw_double(int d) { // return result of throwing for double d with accuracy 80% // Board neighbours ignoring slot zero int bd[2][21]={{0,20,15,17,18,12,13,19,16,14,6,8,9,4,11,10,7,2,1,3,5}, {0,18,17,19,13,20,10,16,11,12,15,14,5,6,9,2,8,3,4,7,1}}; int r = rand()%100; if(r<80) return 2*d; else if(r<85) return 0; else if(r<90) return d; else if (r<93) return 2*bd[0][d]; else if(r<96) return 2*bd[1][d]; else if (r<98) return bd[0][d]; else return bd[1][d]; }``````
Topic archived. No new replies allowed.