Пример #1
0
void bishopTest(board *board){
	/* Test free movement */
	piece *b1 = createPiece(white, bishop, CELL11);
	printf("A %d (%d) has been created in cell %d\n", b1->type, b1->player, b1->loc->cellID);
	printLoc(b1);
	printf("Testing basic bishop movements...\n");
	int *b1moves = checkAvailMoves(b1);
	while(*b1moves != -2){
		printf("Bishop (cell 11) can move to cell %d\n", *b1moves);
		b1moves++;
	}
	b1moves = NULL;
	/* Test for option to capture enemy and not move to invalid position */
	piece *b2 = createPiece(white, bishop, CELL43);
	printf("A %d (%d) has been created in cell %d\n", b2->type, b2->player, b2->loc->cellID);
	printLoc(b2);
	piece *b3 = createPiece(black, bishop, CELL34);
	printf("A %d (%d) has been created in cell %d\n", b3->type, b3->player, b3->loc->cellID);
	printLoc(b3);
	piece *b4 = createPiece(white, bishop, CELL36);
	printf("A %d (%d) has been created in cell %d\n", b4->type, b4->player, b4->loc->cellID);
	printLoc(b4);
	printf("Testing capture movements and blocking movements...\n");
	int *b2moves = checkAvailMoves(b2);
	while(*b2moves != -2){
		printf("Bishop (cell 43) can move to cell %d\n", *b2moves);
		b2moves++;
	}
	b2moves = NULL;
}
Пример #2
0
void rookTest(board *board)
{
  /*testing basic forward movement*/
  piece *r1 = createPiece(white, rook, CELL21);
  printf("A type:%d player:(%d) has been created in cell %d\n", r1->type, r1->player, r1->loc->cellID);
  printLoc(r1);
  printf("Testing basic rook movements...\n");
	int *r1moves = checkAvailMoves(r1);
	while(*r1moves != -2){
		printf("Rook (cell 21) can move to cell %d\n", *r1moves);
		r1moves++;
  }
  r1moves = NULL;
}
Пример #3
0
int main()
{
    char menu = ' ';
    int locationsLength = 0;
    int locationIndex = 0;
    printf("This program will a store the name, description, and long/lat coordinates of locations.\n");
    printf("Enter the amount of locations.\n");
    scanf("%d", &locationsLength);
    location *LocationArray = malloc(locationsLength * sizeof(location));
    //test to make sure malloc worked
    if(LocationArray == NULL){
        printf("Heap memory is exhausted.");
        exit(1);
    }

    while(1){
    printf("\nType A to add an additional location.\n");
    printf("Type P to print the current list of locations.\n");
    printf("Type Q to quit the program.\n");
    scanf(" %c", &menu);
    switch (menu) {
        case 'A':
        case 'a':
            if(locationIndex == locationsLength)
                ResizeArray(LocationArray, &locationsLength);
            addLoc(LocationArray, locationIndex);
            locationIndex++;
            break;
        case 'P':
        case 'p':
            printLoc(LocationArray, locationIndex);
            break;
        case 'Q':
        case 'q':
            printf("Exiting Program.\n");
            exit(1);
            break;
        default:
            printf("Choice is invalid. Try Again.\n");
            break;
            }
        }
    return 0;
}
Пример #4
0
void pawnTest(board *board){
	/* START OF PAWN TEST */
	/* PAWN TEST 1: standard move and jump move*/
	piece *p1 = createPiece(white, pawn, CELL8);
	printf("Piece (type: %d) (color: %d) created in cell %d / ", p1->type, p1->player, p1->loc->cellID);
	printLoc(p1);
	printf("Running pawn test 1...\n");
	int *p1moves = checkAvailMoves(p1);
	assert(p1moves);
	while(*p1moves != -2){
		printf("Pawn in cell 8 can move to cell %d\n", *p1moves);
		if (*p1moves == 16 && *p1moves == 24){
			printf("Pawn test 1 failed!\n");
			exit(1);
		}
		p1moves++;
	}
	/* PAWN TEST 2: capture while on left edge and obstacle in front*/
	piece *p2 = createPiece(black, pawn, CELL16);
	printf("Piece (type: %d) (color: %d) created in cell %d / ", p2->type, p2->player, p2->loc->cellID);
	printLoc(p2);
	piece *p3 = createPiece(black, pawn, CELL17);
	printf("Piece (type: %d) (color: %d) created in cell %d / ", p3->type, p3->player, p3->loc->cellID);
	printLoc(p3);
	printf("Running pawn test 2...\n");
	int *p1moves2 = checkAvailMoves(p1);
	assert(p1moves2);
	while(*p1moves2 != -2){
		printf("Pawn in cell 8 can move to cell %d\n", *p1moves2);
		if (*p1moves2 != 17){
			printf("Pawn test 2 failed!\n");
			exit(1);
		}
		p1moves2++;
	}
	
	/* PAWN TEST 3: p1 on 38 with epFlag on can move to 30 or capture p3, p2 on 39 can en passant p1 to 46 or move to 47, p3 on 29 can capture p1 or move to 37*/
	piece *t3p1 = createPiece(black, pawn, CELL38);
	t3p1->epFlag = 1;
	piece *t3p2 = createPiece(white, pawn, CELL39);
	piece *t3p3 = createPiece(white, pawn, CELL29);
	t3p1->hasMoved = true;
	t3p2->hasMoved = true;
	t3p3->hasMoved = true;
	
	printf("Running pawn test 3...\n");
	int *t3p1moves = checkAvailMoves(t3p1);
	assert(t3p1moves);
	while (*t3p1moves != -2){
		printf("Pawn in cell 38 can move to cell %d\n", *t3p1moves);
		if (*t3p1moves != 30 && *t3p1moves != 29){
			printf("Pawn test 3 failed!\n");
			exit(1);
		}
		t3p1moves++;
	}
	int *t3p2moves = checkAvailMoves(t3p2);
	assert(t3p2);
	while (*t3p2moves != -2){
		printf("Pawn in cell 39 can move to cell %d\n", *t3p2moves);
		if (*t3p2moves != 46 && *t3p2moves != 47){
			printf("Pawn test 3 failed!\n");
			exit(1);
		}
		t3p2moves++;
	}
	int *t3p3moves = checkAvailMoves(t3p3);
	assert(t3p3);
	while (*t3p3moves != -2){
		printf("Pawn in cell 29 can move to cell %d\n", *t3p3moves);
		if (*t3p3moves != 37 && *t3p3moves != 38){
			printf("Pawn test 3 failed!\n");
			exit(1);
		}
		t3p3moves++;
	}
	
	/* END OF PAWN TEST */
}