Skip to content
Open
31 changes: 31 additions & 0 deletions TEST-README
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
By Grant Haines

To add a new test, do the following:
1) Write test in "UnitTests.c" (you can use the existing test as a template)
Use the following assert functions:

#define CuFail(tc, message)
#define CuAssert(tc, message, condition)
#define CuAssertTrue(tc, condition)

#define CuAssertStrEquals(tc,expected,actual)
#define CuAssertStrEquals_Msg(tc,message,expected,actual)

#define CuAssertIntEquals(tc,expected,actual)
#define CuAssertIntEquals_Msg(tc,message,expected,actual)
#define CuAssertDblEquals(tc,expected,actual,dl)
#define CuAssertDblEquals_Msg(tc,message,expected,actual,dl)

#define CuAssertPtrEquals(tc,expected,actual)
#define CuAssertPtrEquals_Msg(tc,message,expected,actual)
#define CuAssertPtrNotNull(tc,pointer)
#define CuAssertPtrNotNullMsg(tc,message,pointer)

Lines 59-90 of "CuTest.h" may have more details.

2) Add a line to the CuGetSuite() function in "UnitTests.c" of the form:
SUITE_ADD_TEST(suite, YOUR_TEST_HERE);

To run the test suite, do the following:
1) Run the command "gcc AllTests.c chess3.c AI.h CuTest.c CuTest.h UnitTests.c"
2) Run "a.out --test" (just "a.out" will start the game)
Binary file added chess
Binary file not shown.
Binary file added chess-noprint
Binary file not shown.
26 changes: 13 additions & 13 deletions src/AI.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void assign_ent(char side, node* branch, char swap[2][8][8])

void PawnAI(char swap[2][8][8], char side, int i,int j, node* root)
{
printf("pawn %d %d %c\n",i,j,side);
//printf("pawn %d %d %c\n",i,j,side);
int outer;
int inner;
if(side== '1')
Expand Down Expand Up @@ -154,7 +154,7 @@ void PawnAI(char swap[2][8][8], char side, int i,int j, node* root)

void KnightAI(char swap[2][8][8], char side, int i, int j, node* root)
{
printf("knight %d %d %c\n",i,j,side);
//printf("knight %d %d %c\n",i,j,side);
int moves[16] = {i+2,j-1,i+2,j+1,i-2,j-1,i-2,j+1,i+1,j+2,i+1,j-2,i-1,j+2,i-1,j-2};
int outer = 0;
int inner =1;
Expand Down Expand Up @@ -187,7 +187,7 @@ void KnightAI(char swap[2][8][8], char side, int i, int j, node* root)

void BishopAI(char swap[2][8][8],char side, int i, int j, node* root)
{
printf("bishop %d %d %c\n",i,j,side);
//printf("bishop %d %d %c\n",i,j,side);
int moves[56];
int i1=i;
int j1=j;
Expand Down Expand Up @@ -262,7 +262,7 @@ void BishopAI(char swap[2][8][8],char side, int i, int j, node* root)

void RookAI(char swap[2][8][8], char side, int i, int j, node* root)
{
printf("rook %d %d %c\n",i,j,side);
//printf("rook %d %d %c\n",i,j,side);
int moves[56];
int i1,i2,i3,i4 = i;
int j1,j2,j3,j4 = j;
Expand Down Expand Up @@ -324,15 +324,15 @@ void RookAI(char swap[2][8][8], char side, int i, int j, node* root)

void QueenAI(char swap[2][8][8], char side, int i, int j, node *root)
{
printf("queen %d %d %c\n",i,j,side);
//printf("queen %d %d %c\n",i,j,side);
BishopAI(swap,side,i,j,root);
RookAI(swap,side,i,j,root);
printf("queen ends %d %d %c\n",i,j,side);
//printf("queen ends %d %d %c\n",i,j,side);
}

void KingAI(char swap[2][8][8],char side, int i, int j,node *root)
{
printf("king %d %d %c\n",i,j,side);
//printf("king %d %d %c\n",i,j,side);
int moves[16] = {i+1,j,i+1,j+1,i+1,j-1,i,j-1,i,j+1,i-1,j,i-1,j-1,i-1,j+1};
int outer = 0;
int inner =1;
Expand Down Expand Up @@ -372,7 +372,7 @@ void common_init(int i1, int j1, int k1, int l1, char swap[2][8][8], node *root,
char finl_ent = swap[0][k1][l1];

int error = compute(init_ent, i1, j1, k1, l1, 1, swap);
printf("error %d ",error);
//printf("error %d ",error);

if(error == 0)
{
Expand Down Expand Up @@ -559,7 +559,7 @@ void AIfunc(char origin[2][8][8])
else
maxim_val = 3*maxim_val;

printf("maxim_val %d\n",maxim_val);
//printf("maxim_val %d\n",maxim_val);
z =0;

for(z;z<=99; z++)
Expand Down Expand Up @@ -657,7 +657,7 @@ void AIfunc(char origin[2][8][8])
}
};

printf("min_dcntr = %d\n",min_dcntr);
//printf("min_dcntr = %d\n",min_dcntr);
int ind_array[60];
z =0;
for(z; z<=59; z++)
Expand Down Expand Up @@ -823,13 +823,13 @@ void AIfunc(char origin[2][8][8])
}
};

printf("i am here\n"); /*produces a random number for selecting*/
//printf("i am here\n"); /*produces a random number for selecting*/
end_array--; /*a move amongst equiprobable choices*/
srand(time(NULL));
z=0;
z = rand()%(end_array+1);
vic_shell=root->array[ind_rand[z]];
printf("i am there\n");
//printf("i am there\n");

if(ult_vic_shell!=NULL)
{
Expand All @@ -850,7 +850,7 @@ void AIfunc(char origin[2][8][8])
}

init_ent = origin[0][i1][j1];
printf("i1%d j1%d k1%d l1%d\n",i1,j1,k1,l1);
//printf("i1%d j1%d k1%d l1%d\n",i1,j1,k1,l1);
z = compute(init_ent, i1, j1 ,k1, l1, 0, origin);

FreeAll(root);
Expand Down
19 changes: 19 additions & 0 deletions src/AllTests.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <stdio.h>

#include "CuTest.h"

CuSuite* CuGetSuite();
CuSuite* CuGetSuite();

void RunAllTests(void)
{
CuString *output = CuStringNew();
CuSuite* suite = CuSuiteNew();

CuSuiteAddSuite(suite, CuGetSuite());

CuSuiteRun(suite);
CuSuiteSummary(suite, output);
CuSuiteDetails(suite, output);
printf("%s\n", output->buffer);
}
Loading