diff --git a/TEST-README b/TEST-README new file mode 100644 index 0000000..9383542 --- /dev/null +++ b/TEST-README @@ -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) \ No newline at end of file diff --git a/chess b/chess new file mode 100755 index 0000000..fc3634f Binary files /dev/null and b/chess differ diff --git a/chess-noprint b/chess-noprint new file mode 100755 index 0000000..ae85b17 Binary files /dev/null and b/chess-noprint differ diff --git a/src/AI.h b/src/AI.h index b3d4779..943b764 100644 --- a/src/AI.h +++ b/src/AI.h @@ -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') @@ -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; @@ -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; @@ -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; @@ -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; @@ -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) { @@ -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++) @@ -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++) @@ -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) { @@ -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); diff --git a/src/AllTests.c b/src/AllTests.c new file mode 100644 index 0000000..3c8ed66 --- /dev/null +++ b/src/AllTests.c @@ -0,0 +1,18 @@ +#include + +#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); +} diff --git a/src/CuTest.c b/src/CuTest.c new file mode 100755 index 0000000..8f61199 --- /dev/null +++ b/src/CuTest.c @@ -0,0 +1,339 @@ +#include +#include +#include +#include +#include +#include + +#include "CuTest.h" + +/*-------------------------------------------------------------------------* + * CuStr + *-------------------------------------------------------------------------*/ + +char* CuStrAlloc(int size) +{ + char* newStr = (char*) malloc( sizeof(char) * (size) ); + return newStr; +} + +char* CuStrCopy(const char* old) +{ + int len = strlen(old); + char* newStr = CuStrAlloc(len + 1); + strcpy(newStr, old); + return newStr; +} + +/*-------------------------------------------------------------------------* + * CuString + *-------------------------------------------------------------------------*/ + +void CuStringInit(CuString* str) +{ + str->length = 0; + str->size = STRING_MAX; + str->buffer = (char*) malloc(sizeof(char) * str->size); + str->buffer[0] = '\0'; +} + +CuString* CuStringNew(void) +{ + CuString* str = (CuString*) malloc(sizeof(CuString)); + str->length = 0; + str->size = STRING_MAX; + str->buffer = (char*) malloc(sizeof(char) * str->size); + str->buffer[0] = '\0'; + return str; +} + +void CuStringDelete(CuString *str) +{ + if (!str) return; + free(str->buffer); + free(str); +} + +void CuStringResize(CuString* str, int newSize) +{ + str->buffer = (char*) realloc(str->buffer, sizeof(char) * newSize); + str->size = newSize; +} + +void CuStringAppend(CuString* str, const char* text) +{ + int length; + + if (text == NULL) { + text = "NULL"; + } + + length = strlen(text); + if (str->length + length + 1 >= str->size) + CuStringResize(str, str->length + length + 1 + STRING_INC); + str->length += length; + strcat(str->buffer, text); +} + +void CuStringAppendChar(CuString* str, char ch) +{ + char text[2]; + text[0] = ch; + text[1] = '\0'; + CuStringAppend(str, text); +} + +void CuStringAppendFormat(CuString* str, const char* format, ...) +{ + va_list argp; + char buf[HUGE_STRING_LEN]; + va_start(argp, format); + vsprintf(buf, format, argp); + va_end(argp); + CuStringAppend(str, buf); +} + +void CuStringInsert(CuString* str, const char* text, int pos) +{ + int length = strlen(text); + if (pos > str->length) + pos = str->length; + if (str->length + length + 1 >= str->size) + CuStringResize(str, str->length + length + 1 + STRING_INC); + memmove(str->buffer + pos + length, str->buffer + pos, (str->length - pos) + 1); + str->length += length; + memcpy(str->buffer + pos, text, length); +} + +/*-------------------------------------------------------------------------* + * CuTest + *-------------------------------------------------------------------------*/ + +void CuTestInit(CuTest* t, const char* name, TestFunction function) +{ + t->name = CuStrCopy(name); + t->failed = 0; + t->ran = 0; + t->message = NULL; + t->function = function; + t->jumpBuf = NULL; +} + +CuTest* CuTestNew(const char* name, TestFunction function) +{ + CuTest* tc = CU_ALLOC(CuTest); + CuTestInit(tc, name, function); + return tc; +} + +void CuTestDelete(CuTest *t) +{ + if (!t) return; + free(t->name); + free(t); +} + +void CuTestRun(CuTest* tc) +{ + jmp_buf buf; + tc->jumpBuf = &buf; + if (setjmp(buf) == 0) + { + tc->ran = 1; + (tc->function)(tc); + } + tc->jumpBuf = 0; +} + +static void CuFailInternal(CuTest* tc, const char* file, int line, CuString* string) +{ + char buf[HUGE_STRING_LEN]; + + sprintf(buf, "%s:%d: ", file, line); + CuStringInsert(string, buf, 0); + + tc->failed = 1; + tc->message = string->buffer; + if (tc->jumpBuf != 0) longjmp(*(tc->jumpBuf), 0); +} + +void CuFail_Line(CuTest* tc, const char* file, int line, const char* message2, const char* message) +{ + CuString string; + + CuStringInit(&string); + if (message2 != NULL) + { + CuStringAppend(&string, message2); + CuStringAppend(&string, ": "); + } + CuStringAppend(&string, message); + CuFailInternal(tc, file, line, &string); +} + +void CuAssert_Line(CuTest* tc, const char* file, int line, const char* message, int condition) +{ + if (condition) return; + CuFail_Line(tc, file, line, NULL, message); +} + +void CuAssertStrEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message, + const char* expected, const char* actual) +{ + CuString string; + if ((expected == NULL && actual == NULL) || + (expected != NULL && actual != NULL && + strcmp(expected, actual) == 0)) + { + return; + } + + CuStringInit(&string); + if (message != NULL) + { + CuStringAppend(&string, message); + CuStringAppend(&string, ": "); + } + CuStringAppend(&string, "expected <"); + CuStringAppend(&string, expected); + CuStringAppend(&string, "> but was <"); + CuStringAppend(&string, actual); + CuStringAppend(&string, ">"); + CuFailInternal(tc, file, line, &string); +} + +void CuAssertIntEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message, + int expected, int actual) +{ + char buf[STRING_MAX]; + if (expected == actual) return; + sprintf(buf, "expected <%d> but was <%d>", expected, actual); + CuFail_Line(tc, file, line, message, buf); +} + +void CuAssertDblEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message, + double expected, double actual, double delta) +{ + char buf[STRING_MAX]; + if (fabs(expected - actual) <= delta) return; + sprintf(buf, "expected <%f> but was <%f>", expected, actual); + + CuFail_Line(tc, file, line, message, buf); +} + +void CuAssertPtrEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message, + void* expected, void* actual) +{ + char buf[STRING_MAX]; + if (expected == actual) return; + sprintf(buf, "expected pointer <0x%p> but was <0x%p>", expected, actual); + CuFail_Line(tc, file, line, message, buf); +} + + +/*-------------------------------------------------------------------------* + * CuSuite + *-------------------------------------------------------------------------*/ + +void CuSuiteInit(CuSuite* testSuite) +{ + testSuite->count = 0; + testSuite->failCount = 0; + memset(testSuite->list, 0, sizeof(testSuite->list)); +} + +CuSuite* CuSuiteNew(void) +{ + CuSuite* testSuite = CU_ALLOC(CuSuite); + CuSuiteInit(testSuite); + return testSuite; +} + +void CuSuiteDelete(CuSuite *testSuite) +{ + unsigned int n; + for (n=0; n < MAX_TEST_CASES; n++) + { + if (testSuite->list[n]) + { + CuTestDelete(testSuite->list[n]); + } + } + free(testSuite); + +} + +void CuSuiteAdd(CuSuite* testSuite, CuTest *testCase) +{ + assert(testSuite->count < MAX_TEST_CASES); + testSuite->list[testSuite->count] = testCase; + testSuite->count++; +} + +void CuSuiteAddSuite(CuSuite* testSuite, CuSuite* testSuite2) +{ + int i; + for (i = 0 ; i < testSuite2->count ; ++i) + { + CuTest* testCase = testSuite2->list[i]; + CuSuiteAdd(testSuite, testCase); + } +} + +void CuSuiteRun(CuSuite* testSuite) +{ + int i; + for (i = 0 ; i < testSuite->count ; ++i) + { + CuTest* testCase = testSuite->list[i]; + CuTestRun(testCase); + if (testCase->failed) { testSuite->failCount += 1; } + } +} + +void CuSuiteSummary(CuSuite* testSuite, CuString* summary) +{ + int i; + for (i = 0 ; i < testSuite->count ; ++i) + { + CuTest* testCase = testSuite->list[i]; + CuStringAppend(summary, testCase->failed ? "F" : "."); + } + CuStringAppend(summary, "\n\n"); +} + +void CuSuiteDetails(CuSuite* testSuite, CuString* details) +{ + int i; + int failCount = 0; + + if (testSuite->failCount == 0) + { + int passCount = testSuite->count - testSuite->failCount; + const char* testWord = passCount == 1 ? "test" : "tests"; + CuStringAppendFormat(details, "OK (%d %s)\n", passCount, testWord); + } + else + { + if (testSuite->failCount == 1) + CuStringAppend(details, "There was 1 failure:\n"); + else + CuStringAppendFormat(details, "There were %d failures:\n", testSuite->failCount); + + for (i = 0 ; i < testSuite->count ; ++i) + { + CuTest* testCase = testSuite->list[i]; + if (testCase->failed) + { + failCount++; + CuStringAppendFormat(details, "%d) %s: %s\n", + failCount, testCase->name, testCase->message); + } + } + CuStringAppend(details, "\n!!!FAILURES!!!\n"); + + CuStringAppendFormat(details, "Runs: %d ", testSuite->count); + CuStringAppendFormat(details, "Passes: %d ", testSuite->count - testSuite->failCount); + CuStringAppendFormat(details, "Fails: %d\n", testSuite->failCount); + } +} diff --git a/src/CuTest.h b/src/CuTest.h new file mode 100755 index 0000000..8b32773 --- /dev/null +++ b/src/CuTest.h @@ -0,0 +1,116 @@ +#ifndef CU_TEST_H +#define CU_TEST_H + +#include +#include + +#define CUTEST_VERSION "CuTest 1.5" + +/* CuString */ + +char* CuStrAlloc(int size); +char* CuStrCopy(const char* old); + +#define CU_ALLOC(TYPE) ((TYPE*) malloc(sizeof(TYPE))) + +#define HUGE_STRING_LEN 8192 +#define STRING_MAX 256 +#define STRING_INC 256 + +typedef struct +{ + int length; + int size; + char* buffer; +} CuString; + +void CuStringInit(CuString* str); +CuString* CuStringNew(void); +void CuStringRead(CuString* str, const char* path); +void CuStringAppend(CuString* str, const char* text); +void CuStringAppendChar(CuString* str, char ch); +void CuStringAppendFormat(CuString* str, const char* format, ...); +void CuStringInsert(CuString* str, const char* text, int pos); +void CuStringResize(CuString* str, int newSize); +void CuStringDelete(CuString* str); + +/* CuTest */ + +typedef struct CuTest CuTest; + +typedef void (*TestFunction)(CuTest *); + +struct CuTest +{ + char* name; + TestFunction function; + int failed; + int ran; + const char* message; + jmp_buf *jumpBuf; +}; + +void CuTestInit(CuTest* t, const char* name, TestFunction function); +CuTest* CuTestNew(const char* name, TestFunction function); +void CuTestRun(CuTest* tc); +void CuTestDelete(CuTest *t); + +/* Internal versions of assert functions -- use the public versions */ +void CuFail_Line(CuTest* tc, const char* file, int line, const char* message2, const char* message); +void CuAssert_Line(CuTest* tc, const char* file, int line, const char* message, int condition); +void CuAssertStrEquals_LineMsg(CuTest* tc, + const char* file, int line, const char* message, + const char* expected, const char* actual); +void CuAssertIntEquals_LineMsg(CuTest* tc, + const char* file, int line, const char* message, + int expected, int actual); +void CuAssertDblEquals_LineMsg(CuTest* tc, + const char* file, int line, const char* message, + double expected, double actual, double delta); +void CuAssertPtrEquals_LineMsg(CuTest* tc, + const char* file, int line, const char* message, + void* expected, void* actual); + +/* public assert functions */ + +#define CuFail(tc, ms) CuFail_Line( (tc), __FILE__, __LINE__, NULL, (ms)) +#define CuAssert(tc, ms, cond) CuAssert_Line((tc), __FILE__, __LINE__, (ms), (cond)) +#define CuAssertTrue(tc, cond) CuAssert_Line((tc), __FILE__, __LINE__, "assert failed", (cond)) + +#define CuAssertStrEquals(tc,ex,ac) CuAssertStrEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(ex),(ac)) +#define CuAssertStrEquals_Msg(tc,ms,ex,ac) CuAssertStrEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac)) +#define CuAssertIntEquals(tc,ex,ac) CuAssertIntEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(ex),(ac)) +#define CuAssertIntEquals_Msg(tc,ms,ex,ac) CuAssertIntEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac)) +#define CuAssertDblEquals(tc,ex,ac,dl) CuAssertDblEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(ex),(ac),(dl)) +#define CuAssertDblEquals_Msg(tc,ms,ex,ac,dl) CuAssertDblEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac),(dl)) +#define CuAssertPtrEquals(tc,ex,ac) CuAssertPtrEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(ex),(ac)) +#define CuAssertPtrEquals_Msg(tc,ms,ex,ac) CuAssertPtrEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac)) + +#define CuAssertPtrNotNull(tc,p) CuAssert_Line((tc),__FILE__,__LINE__,"null pointer unexpected",(p != NULL)) +#define CuAssertPtrNotNullMsg(tc,msg,p) CuAssert_Line((tc),__FILE__,__LINE__,(msg),(p != NULL)) + +/* CuSuite */ + +#define MAX_TEST_CASES 1024 + +#define SUITE_ADD_TEST(SUITE,TEST) CuSuiteAdd(SUITE, CuTestNew(#TEST, TEST)) + +typedef struct +{ + int count; + CuTest* list[MAX_TEST_CASES]; + int failCount; + +} CuSuite; + + +void CuSuiteInit(CuSuite* testSuite); +CuSuite* CuSuiteNew(void); +void CuSuiteDelete(CuSuite *testSuite); +void CuSuiteAdd(CuSuite* testSuite, CuTest *testCase); +void CuSuiteAddSuite(CuSuite* testSuite, CuSuite* testSuite2); +void CuSuiteRun(CuSuite* testSuite); +void CuSuiteSummary(CuSuite* testSuite, CuString* summary); +void CuSuiteDetails(CuSuite* testSuite, CuString* details); + +#endif /* CU_TEST_H */ diff --git a/src/UnitTests.c b/src/UnitTests.c new file mode 100644 index 0000000..9550c9c --- /dev/null +++ b/src/UnitTests.c @@ -0,0 +1,4062 @@ +#include +#include +#include +#include +#include +#include "CuTest.h" + +/* +--------------------------------- +Tests - Grant +--------------------------------- +*/ + +/* + Test pawn movement abilities +*/ +void TestPlayer1PawnMovement(CuTest* tc) +{ + // Test Case 1 + // Test moving forward - valid + + printf("Testing Player 1 Pawn - Move 1 space forward\n"); + + char initial1[2][8][8] = { + { + {'1',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {'1',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expected1[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + // Perform action + compute('1', 0, 0, 1, 0, 0, initial1); + + int i, j, k; + //Compare result board with expected board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initial1[i][j][k] == expected1[i][j][k])); + } + } + } + + // Test Case 2 + // Test moving sideways + + printf("Testing Player 1 Pawn - Should not be able to move sideways\n"); + + char initial2[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expected2[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + // Perform action + compute('1', 7, 0, 7, 1, 0, initial2); + + //Compare result board with expected board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initial2[i][j][k] == expected2[i][j][k])); + } + } + } + + // Test Case 3 + // Test moving forward 2 spaces from start position + + printf("Testing Player 1 Pawn - Move 2 spaces from start position\n"); + + char initial3[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ','1',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ','1',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expected3[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ','1',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ','1',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + // Perform action + compute('1', 1, 1, 3, 1, 0, initial3); + + //Compare result board with expected board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initial3[i][j][k] == expected3[i][j][k])); + } + } + } + + // Test Case 4 + // Test moving forward 2 spaces away from start position + + printf("Testing Player 1 Pawn - Move 2 spaces outside start position\n"); + + char initial4[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ','1',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ','1',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expected4[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ','1',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ','1',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + // Perform action + compute('1', 3, 1, 5, 1, 0, initial4); + + //Compare result board with expected board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initial4[i][j][k] == expected4[i][j][k])); + } + } + } + + // Test Case 5 + // Test moving into friendly piece + + printf("Testing Player 1 Pawn - Cannot move into friendly piece\n"); + + char initial5[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ','1',' ',' ',' ',' ',' ',' '}, + {' ','5',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ','1',' ',' ',' ',' ',' ',' '}, + {' ','1',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expected5[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ','1',' ',' ',' ',' ',' ',' '}, + {' ','5',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ','1',' ',' ',' ',' ',' ',' '}, + {' ','1',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + // Perform action + compute('1', 3, 1, 4, 1, 0, initial5); + + //Compare result board with expected board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initial5[i][j][k] == expected5[i][j][k])); + } + } + } + + // Test Case 6 + // Test moving diagonally - not taking piece + + printf("Testing Player 1 Pawn - Cannot diagonal move without taking piece\n"); + + char initial6[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ','1',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ','1',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expected6[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ','1',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ','1',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + // Perform action + compute('1', 3, 1, 4, 2, 0, initial6); + + //Compare result board with expected board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initial6[i][j][k] == expected6[i][j][k])); + } + } + } + + // Test Case 7 + // Test moving backwards + + printf("Testing Player 1 Pawn - Cannot move backwards\n"); + + char initial7[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ','1',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ','1',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expected7[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ','1',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ','1',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + // Perform action + compute('1', 3, 1, 2, 1, 0, initial7); + + //Compare result board with expected board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initial7[i][j][k] == expected7[i][j][k])); + } + } + } + + printf("Completed Player 1 Pawn movement tests\n\n"); +} + +/* + Test taking pieces +*/ +void TestTakingPieces(CuTest* tc) +{ + // Test Case 1 + // Test player 1 pawn taking player 2 rook + + printf("Testing Taking Pieces - Player 1 Pawn takes Player 2 Rook\n"); + + char initial1[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','1',' ',' ',' ',' '}, + {' ',' ',' ',' ','5',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','1',' ',' ',' ',' '}, + {' ',' ',' ',' ','2',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expected1[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','1',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','1',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + // Perform action + compute('1', 3, 3, 4, 4, 0, initial1); + + int i, j, k; + //Compare result board with expected board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initial1[i][j][k] == expected1[i][j][k])); + } + } + } + + // Test Case 2 + // Test player 2 rook taking player 1 pawn + + printf("Testing Taking Pieces - Player 2 Rook takes Player 1 Pawn\n"); + + char initial2[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','1',' ','5',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','1',' ','2',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expected2[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','5',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','2',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + // Perform action + compute('5', 3, 5, 3, 3, 0, initial2); + + //Compare result board with expected board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initial2[i][j][k] == expected2[i][j][k])); + } + } + } + + // Test Case 3 + // Test player 1 queen cannot take player 1 pawn + + printf("Testing Taking Pieces - Player 1 Queen cannot take Player 1 Pawn\n"); + + char initial3[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','1',' ','7',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','1',' ','1',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expected3[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','1',' ','7',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','1',' ','1',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + // Perform action + compute('7', 3, 5, 3, 3, 0, initial3); + + //Compare result board with expected board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initial3[i][j][k] == expected3[i][j][k])); + } + } + } + + // Test Case 4 + // Test player 2 knight taking player 1 pawn jumping over player 1 pawn + + printf("Testing Taking Pieces - Player 2 Knight jumps over Player 1 pawn and takes Player 1 pawn\n"); + + char initial4[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ','1',' ',' ',' ',' ',' '}, + {' ',' ',' ','1',' ',' ',' ',' '}, + {' ',' ',' ','2',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ','1',' ',' ',' ',' ',' '}, + {' ',' ',' ','1',' ',' ',' ',' '}, + {' ',' ',' ','2',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expected4[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ','2',' ',' ',' ',' ',' '}, + {' ',' ',' ','1',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ','2',' ',' ',' ',' ',' '}, + {' ',' ',' ','1',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + // Perform action + compute('2', 4, 3, 2, 2, 0, initial4); + + //Compare result board with expected board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initial4[i][j][k] == expected4[i][j][k])); + } + } + } + + // Test Case 5 + // Test player 1 bishop takes player 2 queen + + printf("Testing Taking Pieces - Player 1 bishop takes Player 2 Queen\n"); + + char initial5[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ','4',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','7',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ','1',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','2',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expected5[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','4',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','1',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + // Perform action + compute('4', 2, 2, 4, 4, 0, initial5); + + //Compare result board with expected board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initial5[i][j][k] == expected5[i][j][k])); + } + } + } + + printf("Completed Taking Pieces tests\n\n"); +} + +/* +--------------------------------- +Tests - Matthew +--------------------------------- +*/ + + + +/* +--------------------------------- +Tests - Zachary +--------------------------------- +*/ +void TestRookVertMovement(CuTest* tc){ + + char initial[2][8][8] = { + { + {'5',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {'5',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expected[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'5',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'5',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('5', 0, 0, 7, 0, 0, initial); + + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initial[i][j][k] == expected[i][j][k])); + } + } + } +} +void TestRookHozMovement(CuTest* tc){ + + char initial[2][8][8] = { + { + {'5',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {'5',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expected[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ','5'}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ','5'}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('5', 0, 0, 0, 7, 0, initial); + + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initial[i][j][k] == expected[i][j][k])); + } + } + } +} +void TestRookPieceTaken(CuTest* tc){ + + char initial[2][8][8] = { + { + {'5',' ',' ',' ',' ',' ',' ','1'}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {'1',' ',' ',' ',' ',' ',' ','2'}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expected[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ','5'}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ','1'}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('5', 0, 0, 0, 7, 0, initial); + + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initial[i][j][k] == expected[i][j][k])); + } + } + } +} +void TestRookSelfTaken(CuTest* tc){ + + char initial[2][8][8] = { + { + {'5',' ',' ',' ',' ',' ',' ','5'}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {'1',' ',' ',' ',' ',' ',' ','2'}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expected[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ','5'}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ','1'}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('5', 0, 0, 0, 7, 0, initial); + + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initial[i][j][k] == expected[i][j][k])); + } + } + } +} +void TestRookCantJump(CuTest* tc){ + + char initial[2][8][8] = { + { + {'5',' ',' ','1',' ',' ',' ','5'}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'5',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {'1',' ',' ','1',' ',' ',' ','2'}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'2',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + CuAssertTrue(tc,compute('5', 0, 0, 0, 7, 0, initial)==1);//assert horizontally + CuAssertTrue(tc,compute('5', 0, 0, 7, 0, 0, initial)==1);//assert vertically + +} +void TestRookCantOverrun(CuTest* tc){ + + char initial[2][8][8] = { + { + {'5',' ',' ','1',' ',' ',' ','5'}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'5',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {'1',' ',' ','1',' ',' ',' ','2'}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'2',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + CuAssertTrue(tc,compute('5', 0, 0, 0, 3, 0, initial)==1);//assert horizontally + CuAssertTrue(tc,compute('5', 0, 0, 3, 0, 0, initial)==1);//assert vertically +} +void TestRookNotRook(CuTest* tc){ + + char initial[2][8][8] = { + { + {'1',' ',' ',' ',' ',' ',' ','5'}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'5',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {'1',' ',' ',' ',' ',' ',' ','2'}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'2',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + CuAssertTrue(tc,compute('5', 0, 0, 0, 3, 0, initial)==1);//assert horizontally + CuAssertTrue(tc,compute('5', 0, 0, 3, 0, 0, initial)==1);//assert vertically +} +void TestRookInvalidMove(CuTest* tc){ + + char initial[2][8][8] = { + { + {'5',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {'1',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + CuAssertTrue(tc,compute('5', 0, 0, 3, 3, 0, initial)==1);//assert horizontally +} +void TestKnightUpLeftMovement(CuTest* tc){ + + char initial[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','2',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','1',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expected[2][8][8] = { + { + {' ',' ','2',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ','1',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('2', 2, 3, 0, 2, 0, initial); + + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initial[i][j][k] == expected[i][j][k])); + } + } + } +} +void TestKnightUpRightMovement(CuTest* tc){ + + char initial[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','2',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','1',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expected[2][8][8] = { + { + {' ',' ',' ',' ','2',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ','1',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('2', 2, 3, 0, 4, 0, initial); + + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initial[i][j][k] == expected[i][j][k])); + } + } + } +} +void TestKnightRightUpMovement(CuTest* tc){ + + char initial[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','2',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','1',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expected[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ','2',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ','1',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('2', 2, 3, 1, 5, 0, initial); + + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initial[i][j][k] == expected[i][j][k])); + } + } + } +} +void TestKnightRightDownMovement(CuTest* tc){ + + char initial[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','2',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','1',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expected[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ','2',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ','1',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('2', 2, 3, 3, 5, 0, initial); + + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initial[i][j][k] == expected[i][j][k])); + } + } + } +} +void TestKnightDownLeftMovement(CuTest* tc){ + + char initial[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','2',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','1',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expected[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ','2',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ','1',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('2', 2, 3, 4, 2, 0, initial); + + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initial[i][j][k] == expected[i][j][k])); + } + } + } +} +void TestKnightDownRightMovement(CuTest* tc){ + + char initial[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','2',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','1',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expected[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','2',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','1',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('2', 2, 3, 4, 4, 0, initial); + + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initial[i][j][k] == expected[i][j][k])); + } + } + } +} +void TestKnightLeftDownMovement(CuTest* tc){ + + char initial[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','2',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','1',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expected[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ','2',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ','1',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('2', 2, 3, 3, 1, 0, initial); + + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initial[i][j][k] == expected[i][j][k])); + } + } + } +} +void TestKnightLeftUpMovement(CuTest* tc){ + + char initial[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','2',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','1',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expected[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ','2',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ','1',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('2', 2, 3, 1, 1, 0, initial); + + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initial[i][j][k] == expected[i][j][k])); + } + } + } +} +void TestKnightPieceTaken(CuTest* tc){ + + char initial[2][8][8] = { + { + {'2',' ',' ',' ',' ',' ',' ','1'}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ','1',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {'1',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ','2',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expected[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ','2',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ','1',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('2', 0, 0, 2, 1, 0, initial); + + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initial[i][j][k] == expected[i][j][k])); + } + } + } +} +void TestKnightSelfTaken(CuTest* tc){ + + char initial[2][8][8] = { + { + {'2',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ','2',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {'1',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ','2',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expected[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ','2',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ','1',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('2', 0, 0, 2, 1, 0, initial); +} + +void TestKingMovementForward(CuTest *tc) +{ + + char initialm1[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','9',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','1',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expectedm1[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','9',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','1',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('9', 4, 4, 3, 4, 0, initialm1); + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initialm1[i][j][k] == expectedm1[i][j][k])); + } + } + } + +} + + +void TestKingMovementBackward(CuTest *tc) +{ + + char initialm2[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','9',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','1',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expectedm2[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','9',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','1',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('9', 4, 4, 5, 4, 0, initialm2); + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initialm2[i][j][k] == expectedm2[i][j][k])); + } + } + } + +} + + +void TestKingMovementLeft(CuTest *tc) +{ + + char initialm3[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','9',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','1',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expectedm3[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','9',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','1',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('9', 4, 4, 4, 3, 0, initialm3); + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initialm3[i][j][k] == expectedm3[i][j][k])); + } + } + } + +} + +void TestKingMovementRight(CuTest *tc) +{ + + char initialm4[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','9',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','1',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expectedm4[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ','9',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ','1',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('9', 4, 4, 4, 5, 0, initialm4); + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initialm4[i][j][k] == expectedm4[i][j][k])); + } + } + } + +} + +void TestKingMovementDiagonalRF(CuTest *tc) +{ + + char initialm5[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','9',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','1',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expectedm5[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ','9',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ','1',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('9', 4, 4, 3, 5, 0, initialm5); + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initialm5[i][j][k] == expectedm5[i][j][k])); + } + } + } + +} + +void TestKingMovementDiagonalLF(CuTest *tc) +{ + + char initialm6[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','9',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','1',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expectedm6[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','9',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','1',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('9', 4, 4, 3, 3, 0, initialm6); + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initialm6[i][j][k] == expectedm6[i][j][k])); + } + } + } + +} + +void TestKingMovementDiagonalRB(CuTest *tc) +{ + + char initialm7[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','9',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','1',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expectedm7[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ','9',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ','1',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('9', 4, 4, 5, 5, 0, initialm7); + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initialm7[i][j][k] == expectedm7[i][j][k])); + } + } + } + +} + +void TestKingMovementDiagonalLB(CuTest *tc) +{ + + char initialm8[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','9',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','1',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expectedm8[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','9',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','1',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('9', 4, 4, 5, 3, 0, initialm8); + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initialm8[i][j][k] == expectedm8[i][j][k])); + } + } + } + +} + +void TestKingMovementMoreThanOneTile(CuTest *tc) +{ + + char initialm9[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','9',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','1',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expectedm9[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','9',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','1',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('9', 4, 4, 0, 4, 0, initialm9); + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initialm9[i][j][k] == expectedm9[i][j][k])); + } + } + } + +} + +void TestBishopMovementDiagonalRF(CuTest *tc) +{ + + char initialm10[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','4',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','1',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expectedm10[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ','4',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ','1',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('4', 4, 4, 2, 6, 0, initialm10); + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initialm10[i][j][k] == expectedm10[i][j][k])); + } + } + } + +} + +void TestBishopMovementDiagonalLF(CuTest *tc) +{ + + char initialm11[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','4',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','1',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expectedm11[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ','4',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ','1',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('4', 4, 4, 2, 2, 0, initialm11); + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initialm11[i][j][k] == expectedm11[i][j][k])); + } + } + } + +} + +void TestBishopMovementDiagonalRB(CuTest *tc) +{ + + char initialm12[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','4',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','1',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expectedm12[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ','4',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ','1',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('4', 4, 4, 6, 6, 0, initialm12); + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initialm12[i][j][k] == expectedm12[i][j][k])); + } + } + } + +} + +void TestBishopMovementDiagonalLB(CuTest *tc) +{ + + char initialm13[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','4',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','1',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expectedm13[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ','4',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ','1',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('4', 4, 4, 6, 2, 0, initialm13); + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initialm13[i][j][k] == expectedm13[i][j][k])); + } + } + } + +} + +void TestBishopMovementForward(CuTest *tc) +{ + + char initialm14[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','4',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','1',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expectedm14[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','4',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','1',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + + compute('4', 4, 4, 3, 4, 0, initialm14); + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initialm14[i][j][k] == expectedm14[i][j][k])); + } + } + } + +} + +void TestBishopMovementBackward(CuTest *tc) +{ + + char initialm15[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','4',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','1',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expectedm15[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','4',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','1',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('4', 4, 4, 5, 4, 0, initialm15); + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initialm15[i][j][k] == expectedm15[i][j][k])); + } + } + } + +} + +void TestBishopMovementLeft(CuTest *tc) +{ + + char initialm16[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','4',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','1',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expectedm16[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','4',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','1',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('4', 4, 4, 4, 3, 0, initialm16); + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initialm16[i][j][k] == expectedm16[i][j][k])); + } + } + } + +} + +void TestBishopMovementRight(CuTest *tc) +{ + + char initialm17[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ','4',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ','1',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + + char expectedm17[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ','4',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ','1',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('4', 4, 4, 4, 5, 0, initialm17); + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initialm17[i][j][k] == expectedm17[i][j][k])); + } + } + } + +} +/* +--------------------------------- +Tests - Zachary +--------------------------------- +*/ + +void TestKnightCanJump(CuTest* tc){ + + char initial[2][8][8] = { + { + {'2',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {'1',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + + CuAssertTrue(tc,compute('2', 0, 0, 2, 1, 0, initial)==0);//assert + +} +void TestKnightCantOverrun(CuTest* tc){ + + char initial[2][8][8] = { + { + {'2',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ','1',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {'1',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ','1',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + CuAssertTrue(tc,compute('2', 0, 0, 2, 1, 0, initial)==1);//assert +} +void TestKnightNotKnight(CuTest* tc){ + + char initial[2][8][8] = { + { + {'5',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {'1',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + CuAssertTrue(tc,compute('2', 0, 0, 2, 1, 0, initial)==1);//assert +} +void TestKnightInvalidMove(CuTest* tc){ + + char initial[2][8][8] = { + { + {'2',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {'1',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + CuAssertTrue(tc,compute('2', 0, 0, 3, 3, 0, initial)==1);//assert horizontally +} + +/* +--------------------------------- +Tests - Gavin +--------------------------------- +*/ + +/* WHEN MOVING PLAYER 2 PAWN FROM START, USE THE FUNCTION: "TESTPLAYER2PAWN...FROMSTART" */ + +void TestPlayer2PawnMovementForward(CuTest* tc) +{ + char initialg1[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'2',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expectedg1[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'2',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('1', 7, 0, 6, 0, 0, initialg1); + //compute('piecenumber', initialrow, initialcol, endrow, endcol, 0, initial); + /* To test all possible outcomes: + endrow = initialrow - 1 + endcol = initialcol + DONT FORGET TO CHANGE THE BOARDS APPROPIATELY!! + */ + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initialg1[i][j][k] == expectedg1[i][j][k])); + } + } + } +} + +void TestPlayer2PawnMovementForwardFromStart(CuTest* tc) +{ + char initialg11[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'2',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expectedg11[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'2',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('1', 6, 0, 4, 0, 0, initialg11); + //compute('piecenumber', initialrow, initialcol, endrow, endcol, 0, initial); + + int i, j, k; + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initialg11[i][j][k] == expectedg11[i][j][k])); + } + } + } +} + +void TestPlayer2PawnMovementForwardTwoNotFromStart(CuTest* tc) +{ + char initialg12[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expectedg12[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('1', 7, 0, 7, 0, 0, initialg12); + //compute('piecenumber', initialrow, initialcol, endrow, endcol, 0, initial); + /* To test all possible outcomes: + endrow = initialrow - 1 + endcol = initialcol + + DONT FORGET TO CHANGE THE BOARDS APPROPIATELY!! + */ + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initialg12[i][j][k] == expectedg12[i][j][k])); + } + } + } +} + +void TestPlayer2PawnMovementCannotMoveSideways(CuTest* tc) +{ + char initialg13[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expectedg13[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('1', 7, 0, 7, 0, 0, initialg13); + //compute('piecenumber', initialrow, initialcol, endrow, endcol, 0, initial); + /* To test all possible outcomes: + endrow = initialrow - 1 + endcol = initialcol + + DONT FORGET TO CHANGE THE BOARDS APPROPIATELY!! + */ + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initialg13[i][j][k] == expectedg13[i][j][k])); + } + } + } +} + +void TestPlayer2PawnMovementCannotMoveDiagonal(CuTest* tc) +{ + char initialg14[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expectedg14[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('1', 7, 0, 7, 0, 0, initialg14); + //compute('piecenumber', initialrow, initialcol, endrow, endcol, 0, initial); + /* To test all possible outcomes: + endrow = initialrow - 1 + endcol = initialcol + + DONT FORGET TO CHANGE THE BOARDS APPROPIATELY!! + */ + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initialg14[i][j][k] == expectedg14[i][j][k])); + } + } + } +} + +void TestPlayer2PawnMovementCannotMoveBackward(CuTest* tc) +{ + char initialg15[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expectedg15[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('1', 6, 0, 6, 0, 0, initialg15); + //compute('piecenumber', initialrow, initialcol, endrow, endcol, 0, initial); + /* To test all possible outcomes: + endrow = initialrow - 1 + endcol = initialcol + + DONT FORGET TO CHANGE THE BOARDS APPROPIATELY!! + */ + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initialg15[i][j][k] == expectedg15[i][j][k])); + } + } + } +} + +void TestPlayer2PawnMovementCannotMoveIntoAlly(CuTest* tc) +{ + char initialg16[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expectedg16[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {'1',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('1', 7, 0, 7, 0, 0, initialg16); + //compute('piecenumber', initialrow, initialcol, endrow, endcol, 0, initial); + /* To test all possible outcomes: + endrow = initialrow - 1 + endcol = initialcol + + DONT FORGET TO CHANGE THE BOARDS APPROPIATELY!! + */ + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initialg16[i][j][k] == expectedg16[i][j][k])); + } + } + } +} + +void TestQueenMovementForward(CuTest* tc) +{ + char initialg2[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','7',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','7',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expectedg2[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','7',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','7',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('7', 3, 3, 2, 3, 0, initialg2); + //compute('piecenumber', initialrow, initialcol, endrow, endcol, 0, initial); + /* To test all possible movements from initialg2, endrow = initialrow - x for [0 <= endrow <= 8], [x > 0] */ + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initialg2[i][j][k] == expectedg2[i][j][k])); + } + } + } +} + +void TestQueenMovementBackward(CuTest* tc) +{ + char initialg3[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','7',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','7',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expectedg3[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','7',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','7',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('7', 3, 3, 4, 3, 0, initialg3); + //compute('piecenumber', initialrow, initialcol, endrow, endcol, 0, initial); + /* To test all possible movements from initialg3, endrow = initialrow + x for [0 <= endrow <= 8], [x > 0] */ + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initialg3[i][j][k] == expectedg3[i][j][k])); + } + } + } +} + +void TestQueenMovementRight(CuTest* tc) +{ + char initialg4[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','7',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','7',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expectedg4[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','7',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','7',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('7', 3, 3, 3, 4, 0, initialg4); + //compute('piecenumber', initialrow, initialcol, endrow, endcol, 0, initial); + /* To test all possible movements from initialg4, endcol = initialcol + x for [0 <= endcol <= 8], [x > 0] */ + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initialg4[i][j][k] == expectedg4[i][j][k])); + } + } + } +} + +void TestQueenMovementLeft(CuTest* tc) +{ + char initialg5[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','7',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','7',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expectedg5[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ','7',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ','7',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('7', 3, 3, 3, 2, 0, initialg5); + //compute('piecenumber', initialrow, initialcol, endrow, endcol, 0, initial); + /* To test all possible movements from initialg5, endcol = initialcol - x for [0 <= endcol <= 8], [x > 0] */ + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initialg5[i][j][k] == expectedg5[i][j][k])); + } + } + } +} + +void TestQueenMovementDiagonalBR(CuTest* tc) +{ + char initialg6[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','7',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','7',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expectedg6[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','7',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','7',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('7', 3, 3, 4, 4, 0, initialg6); + //compute('piecenumber', initialrow, initialcol, endrow, endcol, 0, initial); + /* To test all possible movements from initialg6 + endrow = initialrow + x for [0 <= endrow <= 8], [x > 0] + endcol = initialcol + x for [0 <= endcol <= 8], [x > 0] + */ + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initialg6[i][j][k] == expectedg6[i][j][k])); + } + } + } +} + +void TestQueenMovementDiagonalBL(CuTest* tc) +{ + char initialg7[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','7',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','7',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expectedg7[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ','7',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ','7',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('7', 3, 3, 4, 2, 0, initialg7); + //compute('piecenumber', initialrow, initialcol, endrow, endcol, 0, initial); + /* To test all possible movements from initialg7 + endrow = initialrow + x for [0 <= endrow <= 8], [x > 0] + endcol = initialcol - x for [0 <= endcol <= 8], [x > 0] + */ + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initialg7[i][j][k] == expectedg7[i][j][k])); + } + } + } +} + +void TestQueenMovementDiagonalFL(CuTest* tc) +{ + char initialg8[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','7',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','7',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expectedg8[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ','7',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ','7',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('7', 3, 3, 2, 2, 0, initialg8); + //compute('piecenumber', initialrow, initialcol, endrow, endcol, 0, initial); + /* To test all possible movements from initialg8 + endrow = initialrow - x for [0 <= endrow <= 8], [x > 0] + endcol = initialcol - x for [0 <= endcol <= 8], [x > 0] + */ + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initialg8[i][j][k] == expectedg8[i][j][k])); + } + } + } +} + +void TestQueenMovementDiagonalFR(CuTest* tc) +{ + char initialg9[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','7',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ','7',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + char expectedg9[2][8][8] = { + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','7',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + }, + { + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ','7',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + {' ',' ',' ',' ',' ',' ',' ',' '}, + } + }; + + compute('7', 3, 3, 2, 4, 0, initialg9); + //compute('piecenumber', initialrow, initialcol, endrow, endcol, 0, initial); + /* To test all possible movements from initialg9 + endrow = initialrow - x for [0 <= endrow <= 8], [x > 0] + endcol = initialcol + x for [0 <= endcol <= 8], [x > 0] + */ + + int i, j, k; + + //Compare result with expected chess board + for (i = 0; i < 2; i++) { + for (j = 0; j < 8; j++) { + for (k = 0; k < 8; k++) { + CuAssertTrue(tc, (initialg9[i][j][k] == expectedg9[i][j][k])); + } + } + } +} + +/* +--------------------------------- +Compile Test Suite +--------------------------------- +*/ + +CuSuite* CuGetSuite(void) +{ + CuSuite* suite = CuSuiteNew(); + + //Unit Tests - Grant + SUITE_ADD_TEST(suite, TestPlayer1PawnMovement); + SUITE_ADD_TEST(suite, TestTakingPieces); + + + //Unit Tests - Matthew + + SUITE_ADD_TEST(suite, TestKingMovementForward); + SUITE_ADD_TEST(suite, TestKingMovementBackward); + SUITE_ADD_TEST(suite, TestKingMovementLeft); + SUITE_ADD_TEST(suite, TestKingMovementRight); + SUITE_ADD_TEST(suite, TestKingMovementDiagonalRF); + SUITE_ADD_TEST(suite, TestKingMovementDiagonalLF); + SUITE_ADD_TEST(suite, TestKingMovementDiagonalRB); + SUITE_ADD_TEST(suite, TestKingMovementDiagonalLB); + SUITE_ADD_TEST(suite, TestKingMovementMoreThanOneTile); + + SUITE_ADD_TEST(suite, TestBishopMovementDiagonalRF); + SUITE_ADD_TEST(suite, TestBishopMovementDiagonalLF); + SUITE_ADD_TEST(suite, TestBishopMovementDiagonalRB); + SUITE_ADD_TEST(suite, TestBishopMovementDiagonalLB); + SUITE_ADD_TEST(suite, TestBishopMovementForward); + SUITE_ADD_TEST(suite, TestBishopMovementBackward); + SUITE_ADD_TEST(suite, TestBishopMovementLeft); + SUITE_ADD_TEST(suite, TestBishopMovementRight); + + //Unit Tests - Zachary + SUITE_ADD_TEST(suite,TestRookVertMovement); + SUITE_ADD_TEST(suite,TestRookHozMovement); + SUITE_ADD_TEST(suite,TestRookPieceTaken); + SUITE_ADD_TEST(suite,TestRookSelfTaken); + SUITE_ADD_TEST(suite,TestRookCantOverrun); + SUITE_ADD_TEST(suite,TestRookCantJump); + SUITE_ADD_TEST(suite,TestRookNotRook); + SUITE_ADD_TEST(suite,TestRookInvalidMove); + + SUITE_ADD_TEST(suite,TestKnightUpLeftMovement); + SUITE_ADD_TEST(suite,TestKnightUpRightMovement); + SUITE_ADD_TEST(suite,TestKnightLeftUpMovement); + SUITE_ADD_TEST(suite,TestKnightLeftDownMovement); + SUITE_ADD_TEST(suite,TestKnightDownLeftMovement); + SUITE_ADD_TEST(suite,TestKnightDownRightMovement); + SUITE_ADD_TEST(suite,TestKnightLeftDownMovement); + SUITE_ADD_TEST(suite,TestKnightRightDownMovement); + SUITE_ADD_TEST(suite,TestKnightCantOverrun); + SUITE_ADD_TEST(suite,TestKnightCanJump); + SUITE_ADD_TEST(suite,TestKnightNotKnight); + SUITE_ADD_TEST(suite,TestKnightInvalidMove); + + //Unit Tests - Gavin + SUITE_ADD_TEST(suite, TestPlayer2PawnMovementForward); + SUITE_ADD_TEST(suite, TestPlayer2PawnMovementForwardFromStart); + SUITE_ADD_TEST(suite, TestPlayer2PawnMovementForwardTwoNotFromStart); + SUITE_ADD_TEST(suite, TestPlayer2PawnMovementCannotMoveBackward); + SUITE_ADD_TEST(suite, TestPlayer2PawnMovementCannotMoveDiagonal); + SUITE_ADD_TEST(suite, TestPlayer2PawnMovementCannotMoveIntoAlly); + SUITE_ADD_TEST(suite, TestPlayer2PawnMovementCannotMoveSideways); + SUITE_ADD_TEST(suite, TestQueenMovementForward); + SUITE_ADD_TEST(suite, TestQueenMovementBackward); + SUITE_ADD_TEST(suite, TestQueenMovementRight); + SUITE_ADD_TEST(suite, TestQueenMovementLeft); + SUITE_ADD_TEST(suite, TestQueenMovementDiagonalBR); + SUITE_ADD_TEST(suite, TestQueenMovementDiagonalBL); + SUITE_ADD_TEST(suite, TestQueenMovementDiagonalFL); + SUITE_ADD_TEST(suite, TestQueenMovementDiagonalFR); + + return suite; +} diff --git a/src/chess3.c b/src/chess3.c index 629f22e..ad3ffc7 100644 --- a/src/chess3.c +++ b/src/chess3.c @@ -7,29 +7,53 @@ #include #include "AI.h" -/* 1 = PAWN - * 2 = KNIGHT - * 4 = BISHOP - * 5 = ROOK - * 7 = QUEEN - * 9 = KING*/ - -int compute(char ent1,int i1,int j1,int k1,int l1, int cond, char chess[2][8][8]); +//Added by Grant for testing: +#include "CuTest.h" + +/* + 1 = PAWN + 2 = KNIGHT + 4 = BISHOP + 5 = ROOK + 7 = QUEEN + 9 = KING +*/ + +// Computes if a move is valid and performs it +int compute(char ent1, int fromRow, int fromCol, int toRow, int toCol, int printErrors, char board[2][8][8]); + +// Checks that the pawn can move +int checkPawnMove(int fromRow, int fromCol, int toRow, int toCol, int printErrors, char board[2][8][8]); + +int checkBishopMove(char ent1, int fromRow, int fromCol, int toRow, int toCol, int printErrors, char chess[2][8][8]); + +int checkKingMove(char ent1, int fromRow, int fromCol, int toRow, int toCol, int printErrors, char chess[2][8][8]); + +// Prints the game board & instructions void printing(char chp [2][8][8]); -int main() +int main(int argc, char *argv[]) { + // Added by Grant for testing + + if (argc == 2 && strcmp(argv[1], "--test") == 0) { + RunAllTests(); + } + + else { + + //Original program char chess[2][8][8]={ { - {'5','4','2','9','7','2','4','5'}, + {'5','2','4','7','9','4','2','1'}, {'1','1','1','1','1','1','1','1'}, {' ',' ',' ',' ',' ',' ',' ',' '}, {' ',' ',' ',' ',' ',' ',' ',' '}, {' ',' ',' ',' ',' ',' ',' ',' '}, {' ',' ',' ',' ',' ',' ',' ',' '}, {'1','1','1','1','1','1','1','1'}, - {'5','4','2','7','9','2','4','5'}, + {'5','2','4','7','9','4','2','5'}, }, { @@ -68,12 +92,8 @@ int main() /***************************************TAKING THE INPUT**********************************************/ if(checker%2 ==0) - { - int loop =0; /********Delay Loop********/ - for(loop;loop<=1000000000;loop++) /******To enhance the gameplay and make it look more real******/ - { - ; - }; + { + sleep(2); AIfunc(chess); checker++; } @@ -180,7 +200,8 @@ int main() char y; if( (y = getchar() ) == 'y' || (y = getchar() )== 'Y') - goto END; + + return 0; } @@ -277,557 +298,274 @@ int main() } } - END: + } + return 0; } +int RookRules(char ent1, int fromRow, int fromCol, int toRow, int toCol, int printErrors, char chess[2][8][8]) { + int q = 0; + switch(chess[0][fromRow][fromCol]){ + case '5':/***CHECKS WHETHER ROOK IS THERE OR NOT******/ + { + if(toCol==fromCol) + {/*******FOR VERTICAL MOVEMENT*************/ + int rip; + rip = toRow - fromRow; + int vap = rip-1; + if(rip <0) + { + vap = (-1)*rip-1; + } -int compute(char ent1,int i1,int j1,int k1,int l1, int cond, char chess[2][8][8]) -/*cond means condition for stopping printf statements - *when cond ==1 do not print */ -{ - int q=0; - switch(ent1) - { - case '1':/************************************* RULES FOR PAWN************************************************/ - switch(chess[0][i1][j1]) - { - case'1': /*CHECKS WHETHER PAWN IS AVAILABLE OR NOT*/ - { - if (chess[1][i1][j1]=='1')/*FOR UPPER PLAYER*/ - { - if( (chess[1][k1][l1]== '1' && l1==j1) || (i1 == 1 && chess[1][2][j1] == '1' && j1==l1 ) ) - { - q=1; - if(cond == 0) - printf("PLAYER 1 YOU CAN NOT OVERRUN YOUR ARMY\n");/************ERROR ERROR***************/ - } - - else if (chess[1][2][j1] == '2') - { - q=1; - if(cond == 0) - printf("PLAYER 1 PAWN CAN'T JUMP OVER THE ENEMY\n");/************ERROR ERROR***************/ - } - - - else - { - if ( i1==1 && (k1==i1+1 || k1==i1+2) && l1==j1 )/*WHEN THE PAWN IS AT ITS INITIAL POSITION*/ - { - if(chess[1][k1][l1] == ' ') - { - chess[0][k1][l1]=chess[0][i1][j1]; - chess[1][k1][l1]=chess[1][i1][j1]; - chess[0][i1][j1]=chess[1][i1][j1]=' '; - } - - else - { - q=1; - if(cond == 0) - printf("ILLEGAL MOVE\n");/************ERROR ERROR***************/ + for(vap; vap>0; vap--) + { + if(rip>0) + { + if(chess[1][fromRow + vap][fromCol] == ' ') + continue; + + else + { + q =1; + if(printErrors == 0) + printf("ROOK CAN'T JUMP\n");/*******ERROR ERROR*********/ + break; + } + } + + else if(rip<0) + { + if(chess[1][fromRow - vap][fromCol] == ' ') + continue; + + else + { + q =1; + if(printErrors == 0) + printf("ROOK CAN'T JUMP\n");/*******ERROR ERROR*********/ + break; + } + } - } + } - } - - - else if (k1==i1+1 && l1==j1)/*WHEN PAWN IS ANYWHERE ELSE*/ - { - if(chess[1][k1][l1] == ' ') - { - chess[0][k1][l1]=chess[0][i1][j1]; - chess[1][k1][l1]=chess[1][i1][j1]; - chess[0][i1][j1]=chess[1][i1][j1]=' '; - } - - else - { - q=1; - if(cond == 0) - printf("ILLEGAL MOVE\n");/************ERROR ERROR***************/ - } + if(chess[1][fromRow][fromCol] == chess[1][toRow][toCol] ) + { + q =1; + vap = 1; + if(printErrors == 0) + printf("YOU CANNOT OVERRUN YOUR ARMY\n");/************ERROR ERROR***************/ + } - } - else if (k1 == i1+1 && ( l1==j1-1 || l1==j1+1))/*WHEN PAWN IS ANYWHERE ELSE*/ - { - if(chess[1][k1][l1] == '2') - { - chess[0][k1][l1]=chess[0][i1][j1]; - chess[1][k1][l1]=chess[1][i1][j1]; - chess[0][i1][j1]=chess[1][i1][j1]=' '; - } - - else - { - q=1; - if(cond == 0) - printf("ILLEGAL MOVE\n");/************ERROR ERROR***************/ + if(vap ==0) + { + chess[0][toRow][toCol]=chess[0][fromRow][fromCol]; + chess[1][toRow][toCol]=chess[1][fromRow][fromCol]; + chess[0][fromRow][fromCol]=chess[1][fromRow][fromCol]=' '; - } - } + } + } - else - { q=1; - if(cond == 0) - printf("PLAYER 1 ILLEGAL MOVE\n");/************ERROR ERROR***************/ + else if(toRow==fromRow) + {/******FOR HORIZONTAL MOVEMENT*************/ + int rhip; + rhip = toCol - fromCol; + int vhap = rhip -1 ; + if(rhip <0) + { + vhap = (-1)*rhip-1; } - } - - } - - else if (chess[1][i1][j1]=='2')/*FOR LOWER PLAYER*/ - { - if( (chess[1][k1][l1]== '2' && l1 == j1) || (i1==6 && chess[1][5][j1] == '2' && j1==l1 ) ) - { - q=1; - if(cond == 0) - printf("PLAYER 2 YOU CAN NOT OVERRUN YOUR ARMY\n");/************ERROR ERROR***************/ - } - - else if (chess[1][5][j1] == '1') - { - q=1; - if(cond == 0) - printf("PLAYER 2 PAWN CAN'T JUMP OVER THE ENEMY\n");/************ERROR ERROR***************/ - } + for(vhap; vhap>0; vhap--) + { + if(rhip>0) + { + if(chess[1][fromRow][fromCol + vhap] == ' ') + continue; + + else + { + q =1; + if(printErrors == 0) + printf("ROOK CAN'T JUMP\n");/*******ERROR ERROR*********/ + break; + } + } + + else if(rhip<0) + { + if(chess[1][fromRow][fromCol - vhap] == ' ') + continue; + + else + { + q =1; + if(printErrors == 0) + printf("ROOK CAN'T JUMP\n");/*******ERROR ERROR*********/ + break; + } + } - else - { - if ( i1==6 && (k1==i1-1 || k1==i1-2) && l1==j1 )/*WHEN THE PAWN IS AT ITS INITIAL POSITION*/ - { - if(chess[1][k1][l1] == ' ') - { - chess[0][k1][l1]=chess[0][i1][j1]; - chess[1][k1][l1]=chess[1][i1][j1]; - chess[0][i1][j1]=chess[1][i1][j1]=' '; - } + } - else - { - q=1; - if(cond == 0) - printf("ILLEGAL MOVE\n");/************ERROR ERROR***************/ + if(chess[1][fromRow][fromCol] == chess[1][toRow][toCol] ) + { + q =1; + vhap = 1; + if(printErrors == 0) + printf("YOU CANNOT OVERRUN YOUR ARMY\n"); /************ERROR ERROR***************/ + } - } - } + if(vhap ==0) + { + chess[0][toRow][toCol]=chess[0][fromRow][fromCol]; + chess[1][toRow][toCol]=chess[1][fromRow][fromCol]; + chess[0][fromRow][fromCol]=chess[1][fromRow][fromCol]=' '; - else if (k1==i1-1 && l1==j1)/*WHEN PAWN IS ANYWHERE ELSE*/ - { - if(chess[1][k1][l1] == ' ') - { - chess[0][k1][l1]=chess[0][i1][j1]; - chess[1][k1][l1]=chess[1][i1][j1]; - chess[0][i1][j1]=chess[1][i1][j1]=' '; - } + } - else - { - q=1; - if(cond == 0) - printf("ILLEGAL MOVE\n");/************ERROR ERROR***************/ - } + } + + else + { + q =1; + if(printErrors == 0) + printf("INVALID MOVE FOR ROOK\n"); /*******ERROR ERROR*********/ + + } - } - else if (k1 == i1-1 && ( l1==j1-1 || l1==j1+1))/*WHEN PAWN IS ANYWHERE ELSE*/ - { - if(chess[1][k1][l1] == '1') - { - chess[0][k1][l1]=chess[0][i1][j1]; - chess[1][k1][l1]=chess[1][i1][j1]; - chess[0][i1][j1]=chess[1][i1][j1]=' '; - } + break;}/***END OF CASE 5 ***********/ - else - { - q=1; - if(cond == 0) - printf("ILLEGAL MOVE\n");/************ERROR ERROR***************/ - } - } - - - else - { q=1; - if(cond == 0) - printf("YOUR MOVE IS ILLEGAL\n");/************ERROR ERROR***************/ - } - - } - } - break;}/*BREAK OF CASE 1*/ + default: + { + q =1; + if(printErrors == 0) + printf("ROOK IS NOT AT THE SPECIFIED POSITION\n");/***********ERROR ERROR**************/ + } - + }/*******************************END OF ROOK**************************************/ + return q; +} - default: - { q=1; - if(cond == 0) - printf("PAWN IS NOT AT THE SPECIFIED POSITION\n");/************ERROR ERROR***************/ - } +int KnightRules(char ent1, int fromRow, int fromCol, int toRow, int toCol, int printErrors, char chess[2][8][8]){ + int q = 0; + switch(chess[0][fromRow][fromCol]) + { case '2':/***CHECKS WHETHER KNIGHT IS THERE OR NOT******/ + { + if( (toRow == fromRow+2 || toRow == fromRow-2) && (toRow>=0 && toRow<=7) && (toCol == fromCol+1 || toCol == fromCol-1) && (toCol>=0 && toCol<=7) ) + {/*******FOR VERTICAL MOVEMENT*************/ + if(chess[1][fromRow][fromCol] == chess[1][toRow][toCol] ) + { + q =1; + if(printErrors == 0) + printf("YOU CANNOT OVERRUN YOUR ARMY\n"); /************ERROR ERROR***************/ + } + + + else + { + chess[0][toRow][toCol]=chess[0][fromRow][fromCol]; + chess[1][toRow][toCol]=chess[1][fromRow][fromCol]; + chess[0][fromRow][fromCol]=chess[1][fromRow][fromCol]=' '; + + } + + } + + + else if( (toRow == fromRow+1 || toRow == fromRow-1) && (toRow>=0 && toRow<=7) && (toCol == fromCol+2 || toCol== fromCol-2) && (toCol>=0 && toCol<=7) ) + {/*********FOR HORIZONTAL MOVEMENT***********/ + if(chess[1][fromRow][fromCol] == chess[1][toRow][toCol] ) + { + q =1; + if(printErrors == 0) + printf("YOU CANNOT OVERRUN YOUR ARMY\n");/************ERROR ERROR***************/ + } - }break;/**********************************************END OF PAWN***********************************/ - + else + { + chess[0][toRow][toCol]=chess[0][fromRow][fromCol]; + chess[1][toRow][toCol]=chess[1][fromRow][fromCol]; + chess[0][fromRow][fromCol]=chess[1][fromRow][fromCol]=' '; - case '2' : /******************************************RULES FOR KNIGHT*********************************/ - switch(chess[0][i1][j1]) - { case '2':/***CHECKS WHETHER KNIGHT IS THERE OR NOT******/ - { - if( (k1 == i1+2 || k1 == i1-2) && (k1>=0 && k1<=7) && (l1 == j1+1 || l1 == j1-1) && (l1>=0 && l1<=7) ) - {/*******FOR VERTICAL MOVEMENT*************/ - if(chess[1][i1][j1] == chess[1][k1][l1] ) - { - q =1; - if(cond == 0) - printf("YOU CANNOT OVERRUN YOUR ARMY\n"); /************ERROR ERROR***************/ - } - + } - else - { - chess[0][k1][l1]=chess[0][i1][j1]; - chess[1][k1][l1]=chess[1][i1][j1]; - chess[0][i1][j1]=chess[1][i1][j1]=' '; + } - } - - } - - - else if( (k1 == i1+1 || k1 == i1-1) && (k1>=0 && k1<=7) && (l1 == j1+2 || l1== j1-2) && (l1>=0 && l1<=7) ) - {/*********FOR HORIZONTAL MOVEMENT***********/ - if(chess[1][i1][j1] == chess[1][k1][l1] ) - { - q =1; - if(cond == 0) - printf("YOU CANNOT OVERRUN YOUR ARMY\n");/************ERROR ERROR***************/ - } + else + { + q =1; + if(printErrors == 0) + printf("YOUR KNIGHT MOVE IS ILLEGAL\n");/************ERROR ERROR***************/ + } + + break;}/*BREAK OF CASE 2*/ + + + default: + { + q =1; + if(printErrors == 0) + printf("KNIGHT IS NOT AT THE SPECIFIED POSITION\n");/************ERROR ERROR***************/ + } + } + return q; +} - else - { - chess[0][k1][l1]=chess[0][i1][j1]; - chess[1][k1][l1]=chess[1][i1][j1]; - chess[0][i1][j1]=chess[1][i1][j1]=' '; - } - } - else - { - q =1; - if(cond == 0) - printf("YOUR KNIGHT MOVE IS ILLEGAL\n");/************ERROR ERROR***************/ - } - - break;}/*BREAK OF CASE 2*/ +/* + Computes results of attempting a move + printErrors means condition for stopping printf statements + when printErrors ==1 do not print +*/ +int compute(char ent1, int fromRow, int fromCol, int toRow, int toCol, int printErrors, char board[2][8][8]) { + int q=0; - default: - { - q =1; - if(cond == 0) - printf("KNIGHT IS NOT AT THE SPECIFIED POSITION\n");/************ERROR ERROR***************/ - } + switch(ent1) { + case '1': // Piece is a Pawn + q = checkPawnMove(fromRow, fromCol, toRow, toCol, printErrors, board); + break; - }break;/***********************************END OF KNIGHT********************************************/ - + case '2': // Piece is a Knight + q = KnightRules(ent1, fromRow, fromCol, toRow, toCol, printErrors, board); + break; - - case'3':/***************************************RULE OF NO-ENTITY 3 ****************************************/ + case'3':/***************************************RULE OF NO-ENTITY 3 ****************************************/ { q =1; - if(cond == 0) + if(printErrors == 0) printf("THERE IS NO ENTITY 3\n");/************ERROR ERROR***************/ }break;/***********************************END OF NO-ENTITY 3 ****************************************/ - case'4':/****************************************RULES OF BISHOP****************************************/ - switch(chess[0][i1][j1]) - { case '4': /***CHECKS WHETHER BISHOP IS THERE OR NOT******/ - { int bis; - bis = k1 - i1; - /* printf("%d\n",bis);*/ - - if(l1 == bis + j1 || l1 == (-1)*bis + j1) - { int var = bis - 1; - - - if(bis < 0){ - var = (-1)*bis -1; - } - - for(var; var >0; var--) - { - if(bis > 0 && l1 > j1) - { - if(chess[1][i1+var][j1+var] == ' ') - continue; - - else - { - q =1; - if(cond == 0) - printf("BISHOP CAN'T JUMP\n");/*******ERROR ERROR*********/ - break; - } - } - - else if(bis > 0 && l1 < j1) - { - if(chess[1][i1+var][j1-var] == ' ') - continue; - - else - { - q =1; - if(cond == 0) - printf("BISHOP CAN'T JUMP\n");/*******ERROR ERROR*********/ - break; - } - } - - else if(bis < 0 && l1 > j1) - { - if(chess[1][i1-var][j1+var] == ' ') - continue; - - else - { - q =1; - if(cond == 0) - printf("BISHOP CAN'T JUMP\n");/*******ERROR ERROR*********/ - break; - - } - } - - if(bis < 0 && l1 < j1) - { - if(chess[1][i1-var][j1-var] == ' ') - continue; - - else - { - q =1; - if(cond == 0) - printf("BISHOP CAN'T JUMP\n");/*******ERROR ERROR*********/ - break; - - } - } - - } - - - if(chess[1][i1][j1] == chess[1][k1][l1]) - { - q =1; - var = 1; - if(cond == 0) - printf("YOU CANNOT OVERRUN YOUR ARMY\n"); /************ERROR ERROR***************/ - } - - - if(var == 0) - { - chess[0][k1][l1]=chess[0][i1][j1]; - chess[1][k1][l1]=chess[1][i1][j1]; - chess[0][i1][j1]=chess[1][i1][j1]=' '; - - } - - } - - else - { - q =1; - if(cond == 0) - printf("INVALID MOVE OF BISHOP\n"); /************ERROR ERROR***************/ - } - - - - - - break;}/***END OF CASE 4 ***********/ - - default: - { q =1; - if(cond == 0) - printf("BISHOP IS NOT AT THE SPECIFIED POSITION\n"); /************ERROR ERROR***************/ - } - - - }break; /*********************************END OF BISHOP**************************************/ - + case '4':/****************************************RULES OF BISHOP****************************************/ + q = checkBishopMove(ent1, fromRow, fromCol, toRow, toCol, printErrors, board); + break; case '5' : /******************************************RULES FOR ROOK*********************************/ - switch(chess[0][i1][j1]) - { case '5':/***CHECKS WHETHER ROOK IS THERE OR NOT******/ - { - if(l1==j1) - {/*******FOR VERTICAL MOVEMENT*************/ - int rip; - rip = k1 - i1; - int vap = rip-1; - - if(rip <0) - { - vap = (-1)*rip-1; - } - - for(vap; vap>0; vap--) - { - if(rip>0) - { - if(chess[1][i1 + vap][j1] == ' ') - continue; - - else - { - q =1; - if(cond == 0) - printf("ROOK CAN'T JUMP\n");/*******ERROR ERROR*********/ - break; - } - } - - else if(rip<0) - { - if(chess[1][i1 - vap][j1] == ' ') - continue; - - else - { - q =1; - if(cond == 0) - printf("ROOK CAN'T JUMP\n");/*******ERROR ERROR*********/ - break; - } - } - - } - - if(chess[1][i1][j1] == chess[1][k1][l1] ) - { - q =1; - vap = 1; - if(cond == 0) - printf("YOU CANNOT OVERRUN YOUR ARMY\n");/************ERROR ERROR***************/ - } - - - if(vap ==0) - { - chess[0][k1][l1]=chess[0][i1][j1]; - chess[1][k1][l1]=chess[1][i1][j1]; - chess[0][i1][j1]=chess[1][i1][j1]=' '; - - } - - } - - else if(k1==i1) - {/******FOR HORIZONTAL MOVEMENT*************/ - int rhip; - rhip = l1 - j1; - int vhap = rhip -1 ; - - if(rhip <0) - { - vhap = (-1)*rhip-1; - } - - for(vhap; vhap>0; vhap--) - { - if(rhip>0) - { - if(chess[1][i1][j1 + vhap] == ' ') - continue; - - else - { - q =1; - if(cond == 0) - printf("ROOK CAN'T JUMP\n");/*******ERROR ERROR*********/ - break; - } - } - - else if(rhip<0) - { - if(chess[1][i1][j1 - vhap] == ' ') - continue; - - else - { - q =1; - if(cond == 0) - printf("ROOK CAN'T JUMP\n");/*******ERROR ERROR*********/ - break; - } - } - - - } - - if(chess[1][i1][j1] == chess[1][k1][l1] ) - { - q =1; - vhap = 1; - if(cond == 0) - printf("YOU CANNOT OVERRUN YOUR ARMY\n"); /************ERROR ERROR***************/ - } - - - if(vhap ==0) - { - chess[0][k1][l1]=chess[0][i1][j1]; - chess[1][k1][l1]=chess[1][i1][j1]; - chess[0][i1][j1]=chess[1][i1][j1]=' '; - - } - - } - - else - { - q =1; - if(cond == 0) - printf("INVALID MOVE FOR ROOK\n"); /*******ERROR ERROR*********/ - - } - - - break;}/***END OF CASE 5 ***********/ - - - default: - { - q =1; - if(cond == 0) - printf("ROOK IS NOT AT THE SPECIFIED POSITION\n");/***********ERROR ERROR**************/ - } - - }break; /*******************************END OF ROOK**************************************/ + { + q = RookRules(ent1, fromRow,fromCol,toRow,toCol, printErrors, board); + }break; @@ -835,7 +573,7 @@ int compute(char ent1,int i1,int j1,int k1,int l1, int cond, char chess[2][8][8] case'6':/***************************************RULE OF NO-ENTITY 6 ****************************************/ { q =1; - if(cond == 0) + if(printErrors == 0) printf("THERE IS NO ENTITY 6\n");/************ERROR ERROR***************/ }break;/***********************************END OF NO-ENTITY 6 ****************************************/ @@ -845,14 +583,14 @@ int compute(char ent1,int i1,int j1,int k1,int l1, int cond, char chess[2][8][8] case'7':/***************************************RULE OF QUEEN ****************************************/ - switch(chess[0][i1][j1])/***CHECKS WHETHER QUEEN IS THERE OR NOT******/ + switch(board[0][fromRow][fromCol])/***CHECKS WHETHER QUEEN IS THERE OR NOT******/ { case'7': { - if(l1==j1) + if(toCol==fromCol) {/*******FOR VERTICAL MOVEMENT*************/ int rip; - rip = k1 - i1; + rip = toRow - fromRow; int vap = rip-1; if(rip <0) @@ -864,13 +602,13 @@ int compute(char ent1,int i1,int j1,int k1,int l1, int cond, char chess[2][8][8] { if(rip>0) { - if(chess[1][i1 + vap][j1] == ' ') + if(board[1][fromRow + vap][fromCol] == ' ') continue; else { q =1; - if(cond == 0) + if(printErrors == 0) printf("QUEEN CAN'T JUMP\n");/*******ERROR ERROR*********/ break; } @@ -878,13 +616,13 @@ int compute(char ent1,int i1,int j1,int k1,int l1, int cond, char chess[2][8][8] else if(rip<0) { - if(chess[1][i1 - vap][j1] == ' ') + if(board[1][fromRow - vap][fromCol] == ' ') continue; else { q =1; - if(cond == 0) + if(printErrors == 0) printf("QUEEN CAN'T JUMP\n");/*******ERROR ERROR*********/ break; } @@ -892,29 +630,29 @@ int compute(char ent1,int i1,int j1,int k1,int l1, int cond, char chess[2][8][8] } - if(chess[1][i1][j1] == chess[1][k1][l1] ) + if(board[1][fromRow][fromCol] == board[1][toRow][toCol] ) { q =1; vap = 1; - if(cond == 0) + if(printErrors == 0) printf("YOU CANNOT OVERRUN YOUR ARMY\n");/************ERROR ERROR***************/ } if(vap ==0) { - chess[0][k1][l1]=chess[0][i1][j1]; - chess[1][k1][l1]=chess[1][i1][j1]; - chess[0][i1][j1]=chess[1][i1][j1]=' '; + board[0][toRow][toCol]=board[0][fromRow][fromCol]; + board[1][toRow][toCol]=board[1][fromRow][fromCol]; + board[0][fromRow][fromCol]=board[1][fromRow][fromCol]=' '; } } - else if(k1==i1) + else if(toRow==fromRow) {/******FOR HORIZONTAL MOVEMENT*************/ int rhip; - rhip = l1 - j1; + rhip = toCol - fromCol; int vhap = rhip -1 ; if(rhip <0) @@ -926,13 +664,13 @@ int compute(char ent1,int i1,int j1,int k1,int l1, int cond, char chess[2][8][8] { if(rhip>0) { - if(chess[1][i1][j1 + vhap] == ' ') + if(board[1][fromRow][fromCol + vhap] == ' ') continue; else { q =1; - if(cond == 0) + if(printErrors == 0) printf("QUEEN CAN'T JUMP\n");/*******ERROR ERROR*********/ break; } @@ -940,13 +678,13 @@ int compute(char ent1,int i1,int j1,int k1,int l1, int cond, char chess[2][8][8] else if(rhip<0) { - if(chess[1][i1][j1 - vhap] == ' ') + if(board[1][fromRow][fromCol - vhap] == ' ') continue; else { q =1; - if(cond == 0) + if(printErrors == 0) printf("QUEEN CAN'T JUMP\n");/*******ERROR ERROR*********/ break; } @@ -955,20 +693,20 @@ int compute(char ent1,int i1,int j1,int k1,int l1, int cond, char chess[2][8][8] } - if(chess[1][i1][j1] == chess[1][k1][l1] ) + if(board[1][fromRow][fromCol] == board[1][toRow][toCol] ) { q =1; vhap = 1; - if(cond == 0) + if(printErrors == 0) printf("YOU CANNOT OVERRUN YOUR ARMY\n"); /************ERROR ERROR***************/ } if(vhap ==0) { - chess[0][k1][l1]=chess[0][i1][j1]; - chess[1][k1][l1]=chess[1][i1][j1]; - chess[0][i1][j1]=chess[1][i1][j1]=' '; + board[0][toRow][toCol]=board[0][fromRow][fromCol]; + board[1][toRow][toCol]=board[1][fromRow][fromCol]; + board[0][fromRow][fromCol]=board[1][fromRow][fromCol]=' '; } @@ -977,10 +715,10 @@ int compute(char ent1,int i1,int j1,int k1,int l1, int cond, char chess[2][8][8] else { int bis; - bis = k1 - i1; + bis = toRow - fromRow; /*printf("%d\n",bis);*/ - if(l1 == bis + j1 || l1 == (-1)*bis + j1) + if(toCol == bis + fromCol || toCol == (-1)*bis + fromCol) { int var = bis - 1; @@ -990,58 +728,58 @@ int compute(char ent1,int i1,int j1,int k1,int l1, int cond, char chess[2][8][8] for(var; var >0; var--) { - if(bis > 0 && l1 > j1) + if(bis > 0 && toCol > fromCol) { - if(chess[1][i1+var][j1+var] == ' ') + if(board[1][fromRow+var][fromCol+var] == ' ') continue; else { q =1; - if(cond == 0) + if(printErrors == 0) printf("QUEEN CAN'T JUMP\n");/*******ERROR ERROR*********/ break; } } - else if(bis > 0 && l1 < j1) + else if(bis > 0 && toCol < fromCol) { - if(chess[1][i1+var][j1-var] == ' ') + if(board[1][fromRow+var][fromCol-var] == ' ') continue; else { q =1; - if(cond == 0) + if(printErrors == 0) printf("QUEEN CAN'T JUMP\n");/*******ERROR ERROR*********/ break; } } - else if(bis < 0 && l1 > j1) + else if(bis < 0 && toCol > fromCol) { - if(chess[1][i1-var][j1+var] == ' ') + if(board[1][fromRow-var][fromCol+var] == ' ') continue; else { q =1; - if(cond == 0) + if(printErrors == 0) printf("QUEEN CAN'T JUMP\n");/*******ERROR ERROR*********/ break; } } - if(bis < 0 && l1 < j1) + if(bis < 0 && toCol < fromCol) { - if(chess[1][i1-var][j1-var] == ' ') + if(board[1][fromRow-var][fromCol-var] == ' ') continue; else { q =1; - if(cond == 0) + if(printErrors == 0) printf("QUEEN CAN'T JUMP\n");/*******ERROR ERROR*********/ break; @@ -1051,20 +789,20 @@ int compute(char ent1,int i1,int j1,int k1,int l1, int cond, char chess[2][8][8] } - if(chess[1][i1][j1] == chess[1][k1][l1]) + if(board[1][fromRow][fromCol] == board[1][toRow][toCol]) { q =1; var = 1; - if(cond == 0) + if(printErrors == 0) printf("YOU CANNOT OVERRUN YOUR ARMY\n"); /************ERROR ERROR***************/ } if(var == 0) { - chess[0][k1][l1]=chess[0][i1][j1]; - chess[1][k1][l1]=chess[1][i1][j1]; - chess[0][i1][j1]=chess[1][i1][j1]=' '; + board[0][toRow][toCol]=board[0][fromRow][fromCol]; + board[1][toRow][toCol]=board[1][fromRow][fromCol]; + board[0][fromRow][fromCol]=board[1][fromRow][fromCol]=' '; } @@ -1073,7 +811,7 @@ int compute(char ent1,int i1,int j1,int k1,int l1, int cond, char chess[2][8][8] else { q =1; - if(cond == 0) + if(printErrors == 0) printf("INVALID MOVE FOR QUEEN\n");/*******ERROR ERROR*********/ } @@ -1087,7 +825,7 @@ int compute(char ent1,int i1,int j1,int k1,int l1, int cond, char chess[2][8][8] default: { q =1; - if(cond == 0) + if(printErrors == 0) printf("QUEEN IS NOT AT THE SPECIFIED POSITION\n");/***********ERROR ERROR**************/ } @@ -1097,91 +835,361 @@ int compute(char ent1,int i1,int j1,int k1,int l1, int cond, char chess[2][8][8] case'9':/***************************************RULE OF KING ****************************************/ - switch(chess[0][i1][j1])/***CHECKS WHETHER QUEEN IS THERE OR NOT******/ - {case'9': - { - - if( (k1 == i1 + 1 || k1 == i1-1) && (l1 == j1 || l1==j1-1 || l1 == j1+1) ) - { + q = checkKingMove(ent1, fromRow, fromCol, toRow, toCol, printErrors, board); - if(chess[1][i1][j1] == chess[1][k1][l1]) - { - q =1; - if(cond == 0) - printf("YOU CANNOT OVERRUN YOUR ARMY\n"); /************ERROR ERROR***************/ - } + break;/***********************************END OF KING **************************************/ - else - { - chess[0][k1][l1]=chess[0][i1][j1]; - chess[1][k1][l1]=chess[1][i1][j1]; - chess[0][i1][j1]=chess[1][i1][j1]=' '; + default: + if(printErrors == 0) + printf("THERE IS NO ENTITY %c\n", ent1); + break; + }/*****************END OF SWITCH(ENTITY)************************/ + + return q; - } +}/*END OF COMPUTE*/ - } +// Checks that the pawn can move and performs it +int checkPawnMove(int fromRow, int fromCol, int toRow, int toCol, int printErrors, char board[2][8][8]) { + // Return 1 if an error occurred, 0 if successful + int error = 0; + + // If the piece belongs to player 1 (top) + if (board[1][fromRow][fromCol]=='1') { + // Check if the move would overrun a friendly piece + if ((board[1][toRow][toCol]== '1' && toCol==fromCol) || (fromRow == 1 && board[1][2][fromCol] == '1' && fromCol==toCol)) { + error = 1; + if(printErrors == 0) + printf("PLAYER 1 YOU CAN NOT OVERRUN YOUR ARMY\n"); /* ===== Error ===== */ + } + + // Check if the move would jump over an opponent piece + else if (board[1][2][fromCol] == '2') { + error = 1; + if(printErrors == 0) + printf("PLAYER 1 PAWN CAN'T JUMP OVER THE ENEMY\n"); /* ===== Error ===== */ + } + + else { + // Check if the pawn is at its initial position (allow move forward 2) + if (fromRow == 1 && (toRow == fromRow + 1 || toRow == fromRow + 2) && toCol == fromCol) { + // Make the move if the space is empty + if (board[1][toRow][toCol] == ' ') { + board[0][toRow][toCol]=board[0][fromRow][fromCol]; + board[1][toRow][toCol]=board[1][fromRow][fromCol]; + board[0][fromRow][fromCol]=board[1][fromRow][fromCol]=' '; + } + // Otherwise, give an error + else { + error = 1; + if (printErrors == 0) + printf("ILLEGAL MOVE\n"); /* ===== Error ===== */ + } + } - else if( (k1 == i1) && (l1==j1-1 || l1 == j1+1) ) - { + // Otherwise use rules for non-starting space moves forward + else if (toRow==fromRow+1 && toCol==fromCol) { + // Make the move if the space is empty + if (board[1][toRow][toCol] == ' ') { + board[0][toRow][toCol]=board[0][fromRow][fromCol]; + board[1][toRow][toCol]=board[1][fromRow][fromCol]; + board[0][fromRow][fromCol]=board[1][fromRow][fromCol]=' '; + } + // Otherwise give an error + else { + error = 1; + if (printErrors == 0) + printf("ILLEGAL MOVE\n"); /* ===== Error ===== */ + } + } - if(chess[1][i1][j1] == chess[1][k1][l1]) - { - q =1; - if(cond == 0) - printf("YOU CANNOT OVERRUN YOUR ARMY\n"); /************ERROR ERROR***************/ - } + // If the pawn is moving diagonally, only allow it to take pieces + else if (toRow == fromRow+1 && (toCol==fromCol-1 || toCol==fromCol+1)) { + // Make the move if the space has an opponent piece + if (board[1][toRow][toCol] == '2') { + board[0][toRow][toCol]=board[0][fromRow][fromCol]; + board[1][toRow][toCol]=board[1][fromRow][fromCol]; + board[0][fromRow][fromCol]=board[1][fromRow][fromCol]=' '; + } + // Otherwise give an error + else { + error = 1; + if(printErrors == 0) + printf("ILLEGAL MOVE\n"); /* ===== Error ===== */ + } + } + + // Any other moves are illegal + else + { error = 1; + if(printErrors == 0) + printf("PLAYER 1 ILLEGAL MOVE\n"); /* ===== Error ===== */ + + } + } + } + // Else if piece belongs to player 2 (bottom) + else if (board[1][fromRow][fromCol]=='2') { + // Check if the move overruns a friendly piece + if ((board[1][toRow][toCol]== '2' && toCol == fromCol) || (fromRow==6 && board[1][5][fromCol] == '2' && fromCol == toCol)) { + error = 1; + if (printErrors == 0) + printf("PLAYER 2 YOU CAN NOT OVERRUN YOUR ARMY\n"); /* ===== Error ===== */ + } + // Check if the move jumps over an opponent's piece + else if (board[1][5][fromCol] == '1') { + error = 1; + if(printErrors == 0) + printf("PLAYER 2 PAWN CAN'T JUMP OVER THE ENEMY\n"); /* ===== Error ===== */ + } + else { + // Check if the pawn is at its initial position (allow move 2 forward) + if (fromRow == 6 && (toRow == fromRow - 1 || toRow == fromRow - 2) && toCol == fromCol) { + // If the space is empty, perform the move + if(board[1][toRow][toCol] == ' ') { + board[0][toRow][toCol]=board[0][fromRow][fromCol]; + board[1][toRow][toCol]=board[1][fromRow][fromCol]; + board[0][fromRow][fromCol]=board[1][fromRow][fromCol]=' '; + } + // Otherwise, give an error + else { + error = 1; + if(printErrors == 0) + printf("ILLEGAL MOVE\n"); /* ===== Error ===== */ + } + } - else - { - chess[0][k1][l1]=chess[0][i1][j1]; - chess[1][k1][l1]=chess[1][i1][j1]; - chess[0][i1][j1]=chess[1][i1][j1]=' '; + // If it is anywhere else, do not allow moving 2 spaces forward + else if (toRow == fromRow - 1 && toCol == fromCol) { + // If the space is empty, perform the move + if (board[1][toRow][toCol] == ' ') { + board[0][toRow][toCol]=board[0][fromRow][fromCol]; + board[1][toRow][toCol]=board[1][fromRow][fromCol]; + board[0][fromRow][fromCol]=board[1][fromRow][fromCol]=' '; + } + // Otherwise, give an error + else { + error = 1; + if(printErrors == 0) + printf("ILLEGAL MOVE\n"); /* ===== Error ===== */ + } + } - } + // If moving diagonally, only allow pawn to take pieces + else if (toRow == fromRow - 1 && (toCol == fromCol - 1 || toCol == fromCol + 1)) { + // If the space has an opponent's piece, move into it and take it + if (board[1][toRow][toCol] == '1') { + board[0][toRow][toCol]=board[0][fromRow][fromCol]; + board[1][toRow][toCol]=board[1][fromRow][fromCol]; + board[0][fromRow][fromCol]=board[1][fromRow][fromCol]=' '; + } + // Otherwise, give an error + else { + error = 1; + if(printErrors == 0) + printf("ILLEGAL MOVE\n"); /* ===== Error ===== */ + } + } + // Any other moves are illegal + else { + error = 1; + if(printErrors == 0) + printf("YOUR MOVE IS ILLEGAL\n");/************ERROR ERROR***************/ + } + } + } +} - } +int checkBishopMove(char ent1, int fromRow, int fromCol, int toRow, int toCol, int printErrors, char board[2][8][8]){ + + int q = 0; + + switch(board[0][fromRow][fromCol]) + { case '4': /***CHECKS WHETHER BISHOP IS THERE OR NOT******/ + { int bis; + bis = toRow - fromRow; + /* printf("%d\n",bis);*/ + if(toCol == bis + fromCol || toCol == (-1)*bis + fromCol) + { + int var = bis - 1; + if(bis < 0){ + var = (-1)*bis -1; + } + for(var; var >0; var--) + { + if(bis > 0 && toCol > fromCol) + { + if(board[1][fromRow+var][fromCol+var] == ' ') + continue; + + else + { + q =1; + if(printErrors == 0) + printf("BISHOP CAN'T JUMP\n");/*******ERROR ERROR*********/ + break; + } + } - - else - { - q =1; - if(cond == 0) - printf("ILLEGAL MOVE FOR KING\n"); /************ERROR ERROR***************/ - } - + + else if(bis > 0 && toCol < fromCol) + { + if(board[1][fromRow+var][fromCol-var] == ' ') + continue; + else + { + q =1; + if(printErrors == 0) + printf("BISHOP CAN'T JUMP\n");/*******ERROR ERROR*********/ + break; + } + } + + else if(bis < 0 && toCol > fromCol) + { + if(board[1][fromRow-var][fromCol+var] == ' ') + continue; + else + { + q =1; + if(printErrors == 0) + printf("BISHOP CAN'T JUMP\n");/*******ERROR ERROR*********/ + break; + + } + } + + if(bis < 0 && toCol < fromCol) + { + if(board[1][fromRow-var][fromCol-var] == ' ') + continue; + else + { + q =1; + if(printErrors == 0) + printf("BISHOP CAN'T JUMP\n");/*******ERROR ERROR*********/ + break; + } + } + + } + + if(board[1][fromRow][fromCol] == board[1][toRow][toCol]) + { + q =1; + var = 1; + if(printErrors == 0) + printf("YOU CANNOT OVERRUN YOUR ARMY\n"); /************ERROR ERROR***************/ + } + + + if(var == 0) + { + board[0][toRow][toCol]=board[0][fromRow][fromCol]; + board[1][toRow][toCol]=board[1][fromRow][fromCol]; + board[0][fromRow][fromCol]=board[1][fromRow][fromCol]=' '; + + } + + } - break;}/********END OF CASE 9 ************/ + + else + { + q =1; + if(printErrors == 0) + printf("INVALID MOVE OF BISHOP\n"); /************ERROR ERROR***************/ + } + + break;}/***END OF CASE 4 ***********/ - default: - { - q =1; - if(cond == 0) - printf("KING IS NOT AT THE SPECIFIED POSITION\n");/***********ERROR ERROR**************/ - } + default: + { q =1; + if(printErrors == 0) + printf("BISHOP IS NOT AT THE SPECIFIED POSITION\n"); /************ERROR ERROR***************/ + } + } + + return q; + +} - }break;/***********************************END OF KING **************************************/ +int checkKingMove(char ent1, int fromRow, int fromCol, int toRow, int toCol, int printErrors, char board[2][8][8]){ + int q = 0; + + switch(board[0][fromRow][fromCol])/***CHECKS WHETHER QUEEN IS THERE OR NOT******/ + {case'9': + { - default:{ - if(cond == 0) - printf("OTHER THAN THE ALLOWED NUMBERS , CHARACTERS NOT ALLOWED AS ENTITY\nLOOK INTO HELP\n");/************ERROR ERROR***************/ - } + if( (toRow == fromRow + 1 || toRow == fromRow-1) && (toCol == fromCol || toCol==fromCol-1 || toCol == fromCol+1) ) + { + + if(board[1][fromRow][fromCol] == board[1][toRow][toCol]) + { + q =1; + if(printErrors == 0) + printf("YOU CANNOT OVERRUN YOUR ARMY\n"); /************ERROR ERROR***************/ + } + + else + { + board[0][toRow][toCol]=board[0][fromRow][fromCol]; + board[1][toRow][toCol]=board[1][fromRow][fromCol]; + board[0][fromRow][fromCol]=board[1][fromRow][fromCol]=' '; + + } + + } + + else if( (toRow == fromRow) && (toCol==fromCol-1 || toCol == fromCol+1) ) + { + if(board[1][fromRow][fromCol] == board[1][toRow][toCol]) + { + q =1; + if(printErrors == 0) + printf("YOU CANNOT OVERRUN YOUR ARMY\n"); /************ERROR ERROR***************/ + } + + else + { + board[0][toRow][toCol]=board[0][fromRow][fromCol]; + board[1][toRow][toCol]=board[1][fromRow][fromCol]; + board[0][fromRow][fromCol]=board[1][fromRow][fromCol]=' '; + + } - }/*****************END OF SWITCH(ENTITY)************************/ - - return q; + } -}/*END OF COMPUTE*/ + else + { + q =1; + if(printErrors == 0) + printf("ILLEGAL MOVE FOR KING\n"); /************ERROR ERROR***************/ + } + + break;}/********END OF CASE 9 ************/ + default: + { + q =1; + if(printErrors == 0) + printf("KING IS NOT AT THE SPECIFIED POSITION\n");/***********ERROR ERROR**************/ + } + } + return q; + +} +// Prints current board state to console void printing(char chp [2][8][8]) { int a,b; diff --git a/src/testing b/src/testing new file mode 100755 index 0000000..e4ba2ed Binary files /dev/null and b/src/testing differ