Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add files via upload #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions dominion/AssertCustom.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
// Created by Yuning on 2019/07/21.
//
#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"
#include "assertCustom.h"
#include <stdlib.h>

#define TRUE 1
#define FALSE 0
#define NUM_CARDS 27


void assertCustom(int boolean, char * message) {

if (boolean == TRUE) {

printf("TEST PASSED: %s\n", message);
}
if (boolean == FALSE) {

printf("TEST FAILED: %s\n", message);


}

}

void assertGameState(int player, struct gameState * oldG, struct gameState * newG) {
int failed = FALSE;
if (oldG->handCount[player] != newG->handCount[player]) {
printf("TEST FAILED: Hand Count for non-action player Changed\n");
failed = TRUE;
}
if (oldG->numPlayers != newG->numPlayers) {
printf("TEST FAILED: Number of Players in Game Changed\n");
failed = TRUE;
}
if (oldG->deckCount[player] != newG->deckCount[player]) {
printf("TEST FAILED: Deck Count for non-action player Changed\n");
failed = TRUE;
}
int i;
for (i = curse; i < NUM_CARDS; i++) {
if (oldG->supplyCount[i] != newG->supplyCount[i]) {
printf("TEST FAILED Card %d Supply Count Changed\n", i);
failed = TRUE;
}
if (oldG->embargoTokens[i] != newG->embargoTokens[i]) {
printf("TEST FAILED Embargo Token on Card %d Changed\n", i);
failed = TRUE;

}
}
if (!failed) {
printf("TEST PASSED: Game State Invariants\n");
}

}

15 changes: 15 additions & 0 deletions dominion/AssertCustom.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// Created by Yuning on 2019/07/21
//




#ifndef DOMINION_ASSERTCUSTOM_H
#define DOMINION_ASSERTCUSTOM_H

void assertCustom(int boolean, char * message);

void assertGameState(int player, struct gameState * oldG, struct gameState * newG);

#endif //DOMINION_ASSERTCUSTOM_H
58 changes: 58 additions & 0 deletions dominion/CardTest1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// Created by Yuning 2019/07/21
//

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"
#include "assertCustom.h"
#include <stdlib.h>

#define TESTCARD "ambassador"




int main() {
int newCards = 0;
int discarded = 1;
int xtraCoins = 0;
int shuffledCards = 0;
int numBuys = 0;
int numActions = 0;

int handpos = 0, choice1 = 0, choice2 = 0, choice3 = 0, bonus = 0;
int seed = 1000;
int numPlayers = 2;
int thisPlayer = 0;
struct gameState G, testG;
int k[5] = { minion, ambassador, tribute, mine, baron };

// initialize a game state and player cards
initializeGame(numPlayers, k, seed, &G);
printf("----------------- Testing Ambassador Card: %s ----------------\n", TESTCARD);
//ambassador should receive exactly 3-cards
//copy game state
memcpy(&testG, &G, sizeof(struct gameState));

cardEffect(ambassador, choice1, choice2, choice3, &testG, handpos, &bonus);
newCards = 3;
xtraCoins = 0;


assertCustom(testG.handCount[thisPlayer] == G.handCount[thisPlayer] + newCards - discarded, "Receives 3 cards");
assertCustom(testG.deckCount[thisPlayer] == G.deckCount[thisPlayer] - newCards + shuffledCards, "Deck has 3 less Cards");
assertCustom(testG.coins == G.coins + xtraCoins, "No extra coins received");
assertCustom(testG.whoseTurn == G.whoseTurn, "Same Players Turn");
assertCustom(testG.numActions == G.numActions, "Number of actions");
assertCustom(testG.numBuys == G.numBuys, "Number of Buys");
assertCustom(testG.playedCardCount == G.playedCardCount + discarded, "Number of Cards Discarded");
assertGameState(thisPlayer + 1, &G, &testG);



return 0;
}
62 changes: 62 additions & 0 deletions dominion/CardTest2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// Created by Yuning 2019/07/21
//


#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"
#include "assertCustom.h"
#include <stdlib.h>

#define TESTCARD "tribute"




int main() {
int newCards = 0;
int discarded = 1;
int xtraCoins = 0;
int shuffledCards = 0;
int numBuys = 0;
int numActions = 0;

int i, j, m;
int handpos = 0, choice1 = 0, choice2 = 0, choice3 = 0, bonus = 0;
int remove1, remove2;
int seed = 1000;
int numPlayers = 2;
int thisPlayer = 0;
struct gameState G, testG;
int k[5] = { minion, ambassador, tribute, mine, baron };

// initialize a game state and player cards
initializeGame(numPlayers, k, seed, &G);
printf("----------------- Testing tribute Card: %s ----------------\n", TESTCARD);
//Tribute should receive one card and one action
//copy game state
memcpy(&testG, &G, sizeof(struct gameState));

cardEffect(tribute, choice1, choice2, choice3, &testG, handpos, &bonus);
newCards = 1;
xtraCoins = 0;
numActions = 1;


assertCustom(testG.handCount[thisPlayer] == G.handCount[thisPlayer] + newCards - discarded, "Receives 1 cards");
assertCustom(testG.deckCount[thisPlayer] == G.deckCount[thisPlayer] - newCards + shuffledCards, "Deck has 1 less Cards");
assertCustom(testG.coins == G.coins + xtraCoins, "No extra coins received");
assertCustom(testG.whoseTurn == G.whoseTurn, "Same Player's Turn");
assertCustom(testG.numActions == G.numActions + numActions, "Number of actions");
assertCustom(testG.numBuys == G.numBuys + numBuys, "Number of Buys");
assertCustom(testG.playedCardCount == G.playedCardCount + discarded, "Number of Cards Discarded");
assertGameState(thisPlayer + 1, &G, &testG);



return 0;
}
58 changes: 58 additions & 0 deletions dominion/CardTest3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// Created by Yuning 2019/07/21
//

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"
#include "assertCustom.h"
#include <stdlib.h>

#define TESTCARD "mine"




int main() {
int newCards = 0;
int discarded = 1;
int xtraCoins = 0;
int shuffledCards = 0;
int numBuys = 0;
int numActions = 0;

int handpos = 0, choice1 = 0, choice2 = 0, choice3 = 0, bonus = 0;
int seed = 1000;
int numPlayers = 2;
int thisPlayer = 0;
struct gameState G, testG;
int k[5] = { minion, ambassador, tribute, mine, baron };

// initialize a game state and player cards
initializeGame(numPlayers, k, seed, &G);
printf("----------------- Testing Mine Card: %s ----------------\n", TESTCARD);
//mine should receive exactly 3-cards
//copy game state
memcpy(&testG, &G, sizeof(struct gameState));

cardEffect(mine, choice1, choice2, choice3, &testG, handpos, &bonus);
newCards = 3;
xtraCoins = 0;


assertCustom(testG.handCount[thisPlayer] == G.handCount[thisPlayer] + newCards - discarded, "Receives 3 cards");
assertCustom(testG.deckCount[thisPlayer] == G.deckCount[thisPlayer] - newCards + shuffledCards, "Deck has 3 less Cards");
assertCustom(testG.coins == G.coins + xtraCoins, "No extra coins received");
assertCustom(testG.whoseTurn == G.whoseTurn, "Same Players Turn");
assertCustom(testG.numActions == G.numActions, "Number of actions");
assertCustom(testG.numBuys == G.numBuys, "Number of Buys");
assertCustom(testG.playedCardCount == G.playedCardCount + discarded, "Number of Cards Discarded");
assertGameState(thisPlayer + 1, &G, &testG);



return 0;
}
119 changes: 119 additions & 0 deletions dominion/CardTest4.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
//
// Created by Yuning 2019/07/21
//

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"
#include "assertCustom.h"
#include <stdlib.h>

#define TESTCARD "baron"




int main() {
int newCards = 0;
int discarded = 1;
int xtraCoins = 0;
int shuffledCards = 0;
int numBuys = 0;
int numActions = 0;
int handCount;
int deckcount;
int newDeckCount;
int i, j, m;
int handpos = 0, choice1 = 0, choice2 = 0, choice3 = 0, bonus = 0;
int remove1, remove2;
int seed = 1000;
int numPlayers = 2;
int thisPlayer = 0;
int nextPlayer = 1;
struct gameState G, testG;
int k[5] = { minion, ambassador, tribute, mine, baron };

// initialize a game state and player cards
initializeGame(numPlayers, k, seed, &G);
printf("----------------- Testing Baron Card State: %s ----------------\n", TESTCARD);
//Great Hall should receive one card and one action
//copy game state
memcpy(&testG, &G, sizeof(struct gameState));

deckcount = testG.deckCount[thisPlayer];


int newDeck1[] = { copper, copper, gold };
newDeckCount = 3;

for (i = 0; i < newDeckCount; i++) {
testG.deck[thisPlayer][--deckcount] = newDeck1[i];
}



cardEffect(baron, choice1, choice2, choice3, &testG, handpos, &bonus);
newCards = 2;
xtraCoins = 0;
numBuys = 0;
handCount = testG.handCount[thisPlayer];


assertCustom(testG.handCount[thisPlayer] == G.handCount[thisPlayer] + newCards - discarded, "Receives 2 cards");
assertCustom(testG.hand[thisPlayer][--handCount] == copper, "First Treasure is Copper");
assertCustom(testG.hand[thisPlayer][--handCount] == copper, "Second Treasure is Copper");
assertCustom(testG.deckCount[thisPlayer] == G.deckCount[thisPlayer] - newCards + shuffledCards, "Deck has 2 less Cards");
assertCustom(testG.coins == G.coins + xtraCoins, "No extra coins received");
assertCustom(testG.whoseTurn == G.whoseTurn, "Same Player's Turn");
assertCustom(testG.numActions == G.numActions, "Number of actions");
assertCustom(testG.numBuys == G.numBuys + numBuys, "Number of Buys");
assertCustom(testG.playedCardCount == G.playedCardCount + discarded, "Number of Cards Discarded");

assertGameState(nextPlayer, &G, &testG);



memcpy(&testG, &G, sizeof(struct gameState));

deckcount = testG.deckCount[thisPlayer];


printf("--------------------Test Case Gold, Province, Silver ------------");
int newDeck2[] = { silver, province, gold };
newDeckCount = 3;

for (i = 0; i < newDeckCount; i++) {
testG.deck[thisPlayer][--deckcount] = newDeck2[i];
}

cardEffect(baron, choice1, choice2, choice3, &testG, handpos, &bonus);
newCards = 2;
xtraCoins = 0;
numActions = 0;
numBuys = 0;
handCount = testG.handCount[thisPlayer];
discarded = 1;
//TODO FIX Council_ROOM Messages
assertCustom(testG.handCount[thisPlayer] == G.handCount[thisPlayer] + newCards - discarded, "Receives 2 cards");
assertCustom(testG.hand[thisPlayer][--handCount] == gold, "First Treasure is Gold");
assertCustom(testG.hand[thisPlayer][--handCount] == silver, "Second Treasure is Silver");
assertCustom(testG.deckCount[thisPlayer] == G.deckCount[thisPlayer] - newCards - 1 + shuffledCards, "Deck has 3 less Cards");
assertCustom(testG.coins == G.coins + xtraCoins, "No extra coins received");
assertCustom(testG.whoseTurn == G.whoseTurn, "Same Player's Turn");
assertCustom(testG.numActions == G.numActions, "Number of actions");
assertCustom(testG.numBuys == G.numBuys + numBuys, "Number of Buys");
assertCustom(testG.playedCardCount == G.playedCardCount + discarded + 1, "Number of Cards Discarded");




assertGameState(nextPlayer, &G, &testG);




return 0;
}
Loading