Connect Four Game

I am trying to create a connect four game for my computer science class. I have a lot of it figured out but I cannot get the x's and o's to appear at the bottom of the collumn rather than at the top. Help would be greatly appreciated.

[code]
#include <iostream>
#include <time.h>
#include <string>
#include <iomanip>

using namespace std;

void DrawBoard(char []);
//char CheckWinner(char []);

int main ()
{
//CONNECT ME GAME

/*
1. Create/Initialize Board
2. Get Moves
3. See if Winner
*/

char board[144];
int col;
int row;


//Initialize board with spaces
for(int i = 0; i < 144; i++)
{
board[i] = ' ';
}

int boardSpot;
char winner;

winner = ' ';

for(int index = 0; index < 144; index++)
{
if(winner == ' ')
{
bool bMoveValid = false;
int turn = index % 2;

while(!bMoveValid) // While bMoveValid = true
{
if(turn == 0) // Enter move for First Player
{
cout << "Player 1, choose a column to drop a letter in: ";
cin >> col;
}
else // Code for Second Player
{
cout << "Player 2, choose a column to drop a letter in: ";
cin >> col;
}

//Process (validate) move
// a - Col between 1 and 12 inclusive
// b - Spot not taken
// c - Rows start at bottom and work way up
for(row = 12; row >=1; row--)
if(turn == 0)
{
bMoveValid = true;
if((col < 1) || (col > 12))
{
bMoveValid = false;
}
if(bMoveValid == true)
{
boardSpot = ((col - 1) * 12);
if(board[boardSpot] != ' ')
{
bMoveValid = false;
}
}
}
else
{
bMoveValid = true;
if((col < 1) || (col > 12))
{
bMoveValid = false;
}
if(bMoveValid == true)
{
boardSpot = ((col - 1) * 12);
if(board[boardSpot] != ' ')
{
bMoveValid = false;
}
}
}

}

//Mark spot on board
if(turn == 0) //Enter move
{
board[boardSpot] = 'X';
}
else
{
board[boardSpot] = 'O';
}

DrawBoard(board);
}
}

return 0;
}

void DrawBoard(char board[])
{
int row;
int col;

// Print Column Header
cout << "1 2 3 4 5 6 7 8 9 0 1 2" << endl;

for(col = 0; col < 12; col++)
{
for(row = 0; row < 12; row++)
{
cout << board[(col + (row * 12))]; //Space
if((col >= 0) && (col <= 12))
{
cout << "|";
}

}
cout << endl;

}

}
Please put in a closing code tag so we can see your code in code tags!

What you want to do is look in that column for the first empty cell. Something like:
1
2
3
4
5
6
7
8
9
10
11
 
//pseudocode 
while(n < 7) //Where n starts as whatever the bottom cell is 
{
    if(cell n is empty) 
    {
        put counter in that cell 
        break; 
    }
    ++n; //Put a suitable increment here so it moves on to checking the next cell up
}
How do I put a closing code tag on my code and where do you suggest putting this pseudocode?
Edit the end of your first post to have a "[/code]"

You want that code to be executed every time someone tries to make a move (computer or human).
Topic archived. No new replies allowed.