Super Tic Tac Toe

This is a discussion on Super Tic Tac Toe within the C++ Programming forums, part of the General Programming Boards category; I'm Working on A Game Called Super Tic Tac Toe Haven't Programmed In A While Really Need Some Help/Ideas Here ...

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    3

    Super Tic Tac Toe

    I'm Working on A Game Called Super Tic Tac Toe Haven't Programmed In A While Really Need Some Help/Ideas Here Are The Requirements For The Game Below:

    1. The Program Will Allow Up to 5 Players Capture First And Last Names 1 Player At a Time Then Using First Name Afterwards.
    2. The First Players Piece is "a" second is "b" and so on throughout the entire game.
    3. The Players can choose the board (up to 10 by 15) for each game. Each game can have a different size.
    4. Starts with player "a". Subsequent game starts with the winner of the previous and follows with players in the round robin sequence "a"..."e". If it ends in a draw the next game starts with the most recent winner.
    5. Move is specified as row character (A...J) followed by column number (1...15) i.e. D5, J11
    6. Must Redraw board after each move.

    Below Is the Code I Have So Far It's Due In A Little Over A Week. Once Again Any Suggestion/Help/Ideas Will Be Helpful. Thanks.





    Code:
    #include <iostream>
    #include <string>
    
    
    using namespace std;
    
    void displayBoard();
    void clear();
    void stat();
    void GetName(string&, string&);
    bool checkWin();
    void move(bool):
    bool isLegal(int);
    char board[9] = {'1','2','3','4','5','6','7','8','9'};
    string FirstPlName, SecondPlName;
    
    int main()
    {
    	bool player = false; 
    	char H;
    	string FirstName;
    	string SecondName;
    	GetNames(FirstName, SecondName);
    
    
    	displayBoard(;
    	while(!checkWin())
    
    	{
    		if(player == true)
    			player = false;
    		else
    			player = true;
    		move(player);
    	}
    	if(player == true)
    	cout << FirstPlName << "Wins" << endl;
    	else
    		cout << SecondPlName << "Wins" << endl;
    		cout << " Would you like to play again? Y or N" << endl;
    		cin >> H;
    		if (H='y')
    		{
    			clear();
    			bool player = false;
    			displayBoard();
    			while(!checkWin());
    		}
    		else
    			if(H='n')
    			{
    				cout << endl << " Thank You for playing";
    			}
    
    	void displayBoard()
    
    	{
    		system("cls");
    		cout << "\n -------------" << endl
    			<<	"|" << board[0]  <<		"|" << board[1]<<	"|" << board[2] << "|" << endl
    			<< " ---------------" << endl
    			<<	"|" << board[3]  <<		"|" << board[4]<<	"|" << board[5] << "|" << endl
    			<< " ---------------" << endl
    			<<	"|" << board[6]  <<		"|" << board[7]<<	"|" << board[8] << "|" << endl
    			<< " ---------------" << endl;
    
    	}
    	bool checkWin()
    
    	{
    		if(board[0] == board[1] && board[2] == board[0] )
    			return true;
    		else if (board[3] == board[4] && board[5] == board[3])
    			return true;
    		else if (board[6] == board[7] && board[8] == board[6])
    			return true;
    		else if (board[0] == board[3] && board[6] == board[0])
    			return true;
    		else if (board[1] == board[4] && board[7] == board[1])
    			return true;
    		else if (board[2] == board[5] && board[8] == board[2])
    			return true;
    		else if (board[0] == board[4] && board[8] == board[0])
    			return true;
    		else if (board[2] == board[4] && board[6] == board[2])
    			return true;
    		else
    			return false;
    	}
    	void move(bool who)
    	{
    	int spot;
    	if (who == true)
    				cout << "\nEnter your mmove " <<FirstPlName <<"; ";
    	else
    				cout << "\nEnter your mmove " <<SecondPlName <<"; ";
    	cin >> spot;
    	if(isLegal(spot))
    	
    	{
    		if (who == true)
    			board[spot-1] = 'x';
    		else
    			board[spot-1] = 'o';
    	}
    	else
    		move(who);
    	displayBoard();
    	}
    
    	bool isLegal(int spot)
    	{
    		if(board[spot-1] == 'X' || board[spot-1] == 'O')
    			return false;
    		else
    		return true;
    	}

  2. #2
    ...and never returned. StainedBlue's Avatar
    Join Date
    Aug 2009
    Posts
    168
    Suggestions:

    1)Get rid of all the global variables.

    2)Stop using system("cls") or anything like it. // Though I'm not sure what your alternative would be,
    I don't suspect you'll be including any other non-standard libraries, so it's OK i guess for your purposes

    3)Close main's bracket
    Last edited by StainedBlue; 09-13-2009 at 10:09 PM.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    > I'm Working on A Game Called Super Tic Tac Toe
    Drop the camel-case writing style if you want to be taken seriously.

    > if (H='y')
    Try ==

    > board[spot-1] = 'x';
    > if(board[spot-1] == 'X' || board[spot-1] == 'O')
    More case consistency issues.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,657
    Drop the camel-case writing style if you want to be taken seriously.
    Heh - perhaps he's German?

  5. #5
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    Nice idea, now we can finally play massively multiplayer tic tac toe
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  6. #6
    ...and never returned. StainedBlue's Avatar
    Join Date
    Aug 2009
    Posts
    168
    Quote Originally Posted by abachler View Post
    Nice idea, now we can finally play massively multiplayer tic tac toe
    I heard 7-deck Go Fish is quite a hoot too.

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    > Heh - perhaps he's German?
    CamelCase gives me the hump
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  8. #8
    ...and never returned. StainedBlue's Avatar
    Join Date
    Aug 2009
    Posts
    168
    A few Other things

    1) why would you fill a "char" board with numbers? Also, you'll need a 2-d array.

    2) don't you think displaying the board in a "for" loop would be a lot more elegant?

    3) what is the condition to win for gigantic tic-tac-toe boards?

  9. #9
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,295
    My suggestion is that your checkWin function must be done with loops.
    Have a look at my post here:
    Connect 5 Algorithm in C

    Note that with a board larger than 3x3, it is always possible for the starting player to get 3 in a row without the other player being able to stop them. Are you sure that is the actual winning criteria? Perhaps something like Gomoku is what you're really writing?
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  10. #10
    Registered User
    Join Date
    Sep 2009
    Posts
    3
    Stained Blue This Is Just A Previous Code For The Original Tic Tac Toe Game And I thought About The For Loop It's Probably What I'm Going To Have To Do For This Game Just Trying To Get The Mechanics Down. The Stipulation For Winning Is 3 Across, Vertical, Or Diagonal.

    IMalc Yes I'm Aware Of That But These Are The Conditions The Teacher Assigned.

  11. #11
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,295
    Okay, well the post I linked to above is still very much relevant.
    I suggest you start modifying the code such that it can handle arbitrary sized boards (or up to 10x15). Let us know if you get stuck when doing that.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help me with my simple Tic tac toe prog
    By maybnxtseasn in forum C Programming
    Replies: 2
    Last Post: 04-04-2009, 06:25 PM
  2. Tic Tac Toe Neural Network
    By glo in forum General AI Programming
    Replies: 4
    Last Post: 06-15-2008, 03:39 PM
  3. Help with Tic Tac Toe game
    By snef73 in forum C++ Programming
    Replies: 1
    Last Post: 04-25-2003, 08:33 AM
  4. Need some help with a basic tic tac toe game
    By darkshadow in forum C Programming
    Replies: 1
    Last Post: 05-12-2002, 04:21 PM
  5. my tic tac toe game, please try it
    By Leeman_s in forum C++ Programming
    Replies: 2
    Last Post: 04-14-2002, 05:16 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21