All pastes #839347 Raw Edit

Stuff

public cpp v1 · immutable
#839347 ·published 2007-12-30 23:52 UTC
rendered paste body
#include <iostream.h>#include <stdlib.h>void initialize(char board[6][7]){	int i, j;	for(i = 0; i < 6; i++)		for(j = 0; j < 7; j++)			board[i][j] = '.';}void draw_board(char board[6][7]){	int i, j;	system("cls");	cout << " | 1 | 2 | 3 | 4 | 5 | 6 | 7 | " << endl << endl;	for(i = 5; i >= 0; i--){		cout << " | ";		for(j = 0; j < 7; j++)			cout << board[i][j] << " | ";		cout << endl;	}	cout << endl;}// function passes in the board array, and the x/y coors (row/col))bool detect_win(char board[6][7], int row, int col){	// win counter, and the original row/col	// will use ocol and orow once i get the checking algorithm working	int win = 0, ocol = col, orow = row;	// less typing :D p is the current player's piece	char p = board[row][col];		// this loop *should* move the current coords all the way to the left of the line	while(p == board[row][col-1] && win == 0)		col--;	// this loop will move the coords to the right, as long as the one to the direct right	// is the same character.  it will increase the loop counter	while(p == board[row][col+1] && win < 3){		col++;		win++;	}	// if won, return true	if(win >=3 )		return true;	else 		return false;}bool check_col(char board[6][7], char turn, int col, int &row){	int i = 0;    if(col >= 0 && col < 7){    	while(board[i][col] != '.')    		i++;    	    	if(i < 7){    		board[i][col] = turn;			row = i;    		return true;    	}	    else{			cout << "pick another column!" << endl;			return false;		}	}	else{		cout << "pick another column!" << endl;		return false;	}}void play(){	int turn = 0, row;	char board[6][7], colors[2] = {'x','y'};	bool done = false;		initialize(board);		do{		int col;		draw_board(board);		do{			cout << "Player " << (turn % 2) + 1 << ", pick a column: ";			cin >> col;		}		// TESTING ONLY - WILL ONLY PUT X'S		//colors[turn % 2]		while(!check_col(board, colors[0], col - 1, row));						if(detect_win(board, row, col - 1))			done = true;		else		    turn++;    }    while(!done && turn < 42);		draw_board(board);		if(done)		cout << "congrats player " << turn % 2 + 1 << endl;	else		cout << "tie game, good job" << endl;			// for testing only	play();}int main(){	play();	system("pause");	return 0;}