visual c++ - Placing a piece in a connect four game using c++ -
ok have homework assignment , dont know start function.
bool placepiece(char** pboard, int colsize, int rowsize, int columnselection, char player)
the function place piece represented char player, on game board char** pboard (a 2darray made colsize , rowsize) function put players piece @ bottom of column selected during players turn. if piece @ bottom of column puts piece on top of 1 , if column full return false.
really biggest issue im having dont understand how im supposed using pboard.
im not looking me me start out on right path.
to solve this, need understand arrays , loops. first argument in signature array containing board data (and next 2 arguments dimensions of it) - there need access first element @ columnselection
position , set value of player
argument. return value should indicate if operation successful.
bool placepiece(char** pboard, int colsize, int rowsize, int columnselection, char player) { if (columnselection >= colsize) { /* invalid column */ return false; } (size_t = 0; < rowsize; ++i) { /* loop go on rows - starting 0 */ if (pboard[columnselection][i] == 0) { /* find first empty row , set 'player' value */ pboard[columnselection][i] = player; return true; } } /* no free row found -> rows set*/ return false; }
this code assumes column-row order in array , goes row 0 upwards, should general idea.
Comments
Post a Comment