Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
e8bc551
Added chess executable
GrantHaines Jan 18, 2020
5113aa1
Commented out AI printf statements
GrantHaines Jan 30, 2020
01bb1d0
Added exe for version without AI reports
GrantHaines Feb 6, 2020
0866055
Added testing files and readme
GrantHaines Feb 29, 2020
7e8bfe8
Added Test Cases
zachary-morello Mar 3, 2020
e0233fd
added tests for player 2 pawn movement and for queen (all 8 possible …
DolphinRidingACamel Mar 3, 2020
5917037
Added Knight Tests
zachary-morello Mar 3, 2020
c9500cf
Update UnitTests.c
DolphinRidingACamel Mar 3, 2020
aaef0a9
Update UnitTests.c
DolphinRidingACamel Mar 3, 2020
8a980b2
Tests for King Movement
Mar 3, 2020
a3ac073
Testing for Bishop movement
Mar 3, 2020
6d83137
7 pawn test cases and 5 taking pieces test cases
GrantHaines Mar 3, 2020
5aa265b
Remove redundant file
GrantHaines Mar 3, 2020
0669117
Merge Grant's Tests to master
GrantHaines Mar 3, 2020
03c5937
Merge branch 'master' into z99o-unit-testing
zachary-morello Mar 4, 2020
5cfcdc7
Merge branch 'master' into Matthew-testing
GrantHaines Mar 4, 2020
469a2c5
Merge pull request #2 from matthew1796/Matthew-testing
GrantHaines Mar 4, 2020
0391fe3
Merge branch 'master' into Gavin-Testing
GrantHaines Mar 4, 2020
f052dd5
Merge branch 'master' into Gavin-Testing
GrantHaines Mar 4, 2020
7f1a79a
Merge pull request #3 from matthew1796/Gavin-Testing
GrantHaines Mar 4, 2020
a7c353d
Fixed up a couple of errors
GrantHaines Mar 4, 2020
7468481
Update UnitTests.c
DolphinRidingACamel Mar 4, 2020
c849969
Merge branch 'Gavin-Testing' of https://github.com/matthew1796/ASCII-…
DolphinRidingACamel Mar 4, 2020
fa458ae
Merge pull request #4 from matthew1796/Gavin-Testing
DolphinRidingACamel Mar 4, 2020
5aac81b
Minor error fix
GrantHaines Mar 4, 2020
7646d75
Added test executable and grader guide to readme
GrantHaines Mar 4, 2020
124f28a
Code Optimization
zachary-morello Mar 12, 2020
674a781
Merge branch 'z99o-unit-testing'
zachary-morello Mar 12, 2020
c7e54d9
Replaced pawn rules with function checkPawnMove
GrantHaines Mar 13, 2020
2dc39cc
Renamed compute variables i1, j1, k1, l1
GrantHaines Mar 13, 2020
1ce7780
Fixed bishop/knight positions
GrantHaines Mar 13, 2020
b4f381c
Fixed formatting issue with functions
GrantHaines Mar 13, 2020
d35d8ad
Removed goto statement
GrantHaines Mar 13, 2020
e479f62
add checkBishopMove() function
Mar 16, 2020
5657b0a
Merge pull request #16 from matthew1796/bishop_patch
matthew1796 Mar 16, 2020
b15f44e
Added checkKingMove() patch
Mar 16, 2020
14de667
Merge pull request #17 from matthew1796/bishop_patch
matthew1796 Mar 16, 2020
75256f9
Fixed some compilation errors and made sure automated tests worked
GrantHaines Mar 16, 2020
eaef910
replaced coutning for loop with a sleep function
Mar 16, 2020
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
36 changes: 36 additions & 0 deletions TEST-README
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
By Grant Haines

FOR GRADERS:
To run the tests go into the "src" folder and run the command "testing --test"



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
18 changes: 18 additions & 0 deletions src/AllTests.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <stdio.h>

#include "CuTest.h"

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