/* ------------------------------------ input a complex column in the matrix created -- 98jan28, cca ------------------------------------ */ void InpMtx_inputComplexColumn ( InpMtx *inpmtx, int col, int colsize, int colind[], double colent[] ) { /* -------------- check the data -------------- */ if ( inpmtx == NULL || col < 0 || colsize < 0 || colind == NULL || colent == NULL ) { fprintf(stderr, "\n fatal error in InpMtx_inputComplexColumn(%p,%d,%d,%p,%p)" "\n bad input\n", inpmtx, col, colsize, colind, colent) ; spoolesFatal(); } if ( ! INPMTX_IS_COMPLEX_ENTRIES(inpmtx) ) { fprintf(stderr, "\n fatal error in InpMtx_inputComplexColumn(%p,%d,%d,%p,%p)" "\n inputMode must be SPOOLES_COMPLEX\n", inpmtx, col, colsize, colind, colent) ; spoolesFatal(); } inputColumn(inpmtx, col, colsize, colind, colent) ; return ; }
/* ---------------------------- input a column in the matrix created -- 98jan28, cca ---------------------------- */ void InpMtx_inputColumn ( InpMtx *inpmtx, int col, int colsize, int colind[] ) { /* -------------- check the data -------------- */ if ( inpmtx == NULL || col < 0 || colsize < 0 || colind == NULL ) { fprintf(stderr, "\n fatal error in InpMtx_inputRealColumn(%p,%d,%d,%p)" "\n bad input\n", inpmtx, col, colsize, colind) ; spoolesFatal(); } if ( ! INPMTX_IS_INDICES_ONLY(inpmtx) ) { fprintf(stderr, "\n fatal error in InpMtx_inputColumn(%p,%d,%d,%p)" "\n inputMode must be INPMTX_INDICES_ONLY\n", inpmtx, col, colsize, colind) ; spoolesFatal(); } inputColumn(inpmtx, col, colsize, colind, NULL) ; return ; }
/* *playerTurn *Description: Takes in user inputs for column and changes the resulting empty place in that column to the player number */ void playerTurn(int player, int grid[column_size][row_size]) { //varaible initialisation int inputColumn(); int col,test, row, placement; char placementerror[45] = "Can not place in that column! Try Again"; //error msg //print out the grid and ask for input clearScreen(); printGrid(grid); printf("\n\n"); spacer(); printf("Player %d ", player); if(player == 1) { printf("'O'\n"); } else { printf("'X'\n"); } spacer(); printf("Enter column: "); do { placement = 0; //will repeat until player makes a successful move (checks if column selected is full) do //will repeat until player selects a valid input (checks if column is inside grid) { test = 1; //initialised here for repeating loop col = inputColumn(); //validates input is within grid. if(col < 0 || col > (column_size - 1)) { test = 0; spacer(); printf("%s\n", placementerror ); spacer(); } }while(test == 0); row = 0; //row is intialised here for repeating loops. while(placement == 0 && row < row_size) //checks column selected from the bottom row and working upwards until it finds an empty position '0' and changes the value to the player. { if(grid[col][row] == 0) { grid[col][row] = player; placement = 1; //sets to 0 when a successfull move is made } else row++; } if(placement == 0) //if the above loop does not make a successful move within the column selected then placement will be 0 here. { spacer(); printf("%s\n", placementerror); //print error spacer(); } }while(placement == 0); }