-
Notifications
You must be signed in to change notification settings - Fork 0
/
randomtestadventure.c.gcov
74 lines (74 loc) · 3.37 KB
/
randomtestadventure.c.gcov
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
-: 0:Source:randomtestadventure.c
-: 0:Graph:randomtestadventure.gcno
-: 0:Data:randomtestadventure.gcda
-: 0:Runs:1
-: 0:Programs:1
-: 1:#include "dominion.h"
-: 2:#include "dominion_helpers.h"
-: 3:#include <string.h>
-: 4:#include <stdio.h>
-: 5:#include <assert.h>
-: 6:#include <stdlib.h>
-: 7:#include <time.h>
-: 8:#include "rngs.h"
-: 9:
-: 10:
-: 11:
-: 12:#define DEBUG 0
-: 13:#define NOISY_TEST 1
-: 14:
-: 15:int adventurerCard(int *drawntreasure, struct gameState *state, int *cardDrawn, int *currentPlayer, int *temphand, int *z);
-: 16:
-: 17:
440133: 18:int random_number(int min_num, int max_num){
440133: 19: int result=0,low_num=0,hi_num=0;
440133: 20: if(min_num<max_num)
-: 21: {
440133: 22: low_num=min_num;
440133: 23: hi_num=max_num+1; // this is done to include max_num in output.
-: 24: }else{
#####: 25: low_num=max_num+1;// this is done to include max_num in output.
#####: 26: hi_num=min_num;
-: 27: }
440133: 28: srand(time(NULL));
440133: 29: result = (rand()%(hi_num-low_num))+low_num;
440133: 30: return result;
-: 31:}
-: 32:
1: 33:int main(int argc, char const *argv[]){
-: 34:
-: 35: struct gameState game;
-: 36:
-: 37: int i, j;
1: 38: int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy};
-: 39:
-: 40: //adventurecard specific variables
-: 41: int drawntreasure;
-: 42: int currentplayer;
-: 43: int temphand[MAX_HAND]; //array of 500
-: 44: int z;
-: 45: int cardDrawn;
-: 46: int myCard;
-: 47: int tempcoins;
-: 48:
-: 49:
45: 50: for (i = 0; i < random_number(0, 100); i ++){ //Loops a random number of times <100
44: 51: initializeGame(random_number(2,4), k, random_number(1, 9), &game); //initializes a game with a random seed
-: 52: //between 1-9
-: 53:
44: 54: currentplayer = game.whoseTurn; //initialize the player
-: 55:
440044: 56: for (j = 0; j < 10000; j++){ // run 10000 times with random variables in this game state
440000: 57: drawntreasure = random_number(0, 10); //What happens if you start with drawntreasure
-: 58: //drawCard(currentplayer, &game); //What happens if you draw a card prematurely
-: 59: //z = random_number(0, 500); //If z is higher than 0, it produces a significant access error
440000: 60: tempcoins = game.coins;
-: 61:
440000: 62: myCard = adventurerCard(&drawntreasure, &game, &cardDrawn, ¤tplayer, temphand, &z);
440000: 63: if (tempcoins > game.coins)
#####: 64: printf("Error: tempcoins [%d] game.coins[%d]\n", tempcoins, game.coins);
-: 65: }
-: 66: }
-: 67:
1: 68: return 0;
-: 69:}