Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- int usernum, compnum, matchtotal, startplayer, z, takematch, maxcomp, maxhumen, randcomp;
- takematch = 0, compnum =1;
- printf("how many matches do you want to play (10-100)? \n");
- scanf("%d", &matchtotal);
- if (matchtotal < 10)
- {
- matchtotal = 10;
- }
- else if (matchtotal > 100)
- {
- matchtotal = 100;
- }
- printf("Who will move in the first turn? (1-Computer, 2-Man): \n");
- scanf("%d" , &startplayer);
- if (startplayer != 2)
- {
- /*Any else input other than 2 means comp starts */
- startplayer = 1;
- }
- while (matchtotal > 0)
- {
- if (startplayer == 2)
- {
- while (matchtotal > 0)
- {
- printf("there are %d matches on the table \n", matchtotal);
- if (takematch == 0)
- {
- maxcomp = 2 * compnum;
- }
- else
- {
- maxcomp = 2 * randcomp;
- }
- printf("possbile move is[1..%d] matches..... \n", maxcomp);
- printf("how many do u wish to take?");
- scanf("%d", &takematch);
- if (takematch < 1 || takematch > maxcomp)
- {
- printf("Illegal please retry \n");
- }
- while (takematch < 1 || takematch > maxcomp)
- {
- printf("possbile move is[1..%d] matches..... \n", maxcomp);
- printf("how many do u wish to take?");
- scanf("%d", &takematch);
- if (takematch < 1 || takematch > maxcomp)
- {
- printf("Illegal please retry \n");
- }
- }
- matchtotal = matchtotal - takematch;
- if (matchtotal <= 0)
- {
- printf("Computer wins!");
- matchtotal = 0;
- }
- maxhumen = 2 * takematch;
- printf("there are %d matches on the table \n", matchtotal);
- printf("possbile move is[1..%d] matches..... \n", maxhumen);
- randcomp = rand() % maxhumen + 1;
- if (maxhumen >= matchtotal)
- {
- printf("computer wins! \n");
- matchtotal = 0;
- }
- else
- {
- printf("computer takes %d\n", randcomp);
- matchtotal = matchtotal - randcomp;
- if (matchtotal <= 0)
- {
- printf("Humen wins! \n");
- }
- }
- }
- }
- if (startplayer == 1)
- {
- printf("there are %d matches on the table \n", matchtotal);
- if (takematch == 0)
- {
- maxhumen = 2 * compnum;
- }
- else
- {
- maxhumen = 2 * takematch;
- }
- printf("possbile move is[1..%d] matches..... \n", maxhumen);
- randcomp = rand() % maxhumen + 1;
- if (maxhumen >= matchtotal)
- {
- printf("humen wins! \n");
- matchtotal = 0;
- }
- else
- {
- printf("computer takes %d\n", randcomp);
- matchtotal = matchtotal - randcomp;
- if (matchtotal <= 0)
- {
- printf("computer wins! \n");
- }
- }
- maxcomp = 2 * randcomp;
- printf("there are %d matches on the table \n", matchtotal);
- printf("possbile move is[1..%d] matches..... \n", maxcomp);
- printf("how many do u wish to take?");
- scanf("%d", &takematch);
- if (takematch < 1 || takematch > maxcomp)
- {
- printf("Illegal please retry \n");
- }
- while (takematch < 1 || takematch > maxcomp)
- {
- printf("possbile move is[1..%d] matches..... \n", maxcomp);
- printf("how many do u wish to take?");
- scanf("%d", &takematch);
- if (takematch < 1 || takematch > maxcomp)
- {
- printf("Illegal please retry \n");
- }
- }
- matchtotal = matchtotal - takematch;
- if (matchtotal <= 0)
- {
- printf("humen wins!");
- matchtotal = 0;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement