C++ Tictactoe code

  • (2 Pages)
  • +
  • 1
  • 2

19 Replies - 1444 Views - Last Post: 07 October 2015 - 06:43 PM Rate Topic: -----

#1 helloworld135   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 03-October 15

C++ Tictactoe code

Posted 03 October 2015 - 12:23 AM

I'm trying to make a basic tictactoe AIThis is the function I'm trying to create below, I don't need anything more complex yet. I have a few problems right now, I changed everything to enums and I'm getting a lot of errors in my original code.

My biggest problem about the SECOND CODE is I don't know how to call my new checkBoard function. If I put cout<<checkBoard(board, orig) in the main for example, I get errors. I don't know how I can actually call this function ever since I changed it to Player instead of const int.

It's hard to test the first part of my code because my checkBoard and my copyBoard functions aren't working anymore.

/**
* Choose the next move for a player.
*
* Given a current state of a board, choose the best next move
* for a particular player.
*
* @param[in] board the current board state (Xs, Os and Nones)
* @param[in] player whose turn it is (X or O)
* @param[out] row the row that the player should choose
* @param[out] col the column that the player should choose
*
* @returns whether or not this move can result in a win
*/
bool chooseNextMove(const Player board[9], Player player, int &row, int &col){

while (checkBoard(board)=false){

copyBoard(board[9],copy[9]);//copies array
int answer=index(int &row, int &col);//See index value of array where I need to add an X or O
copy[answer]=player // put the value "player"(X or O) where the move took place

if (checkBoard(copy)==Player)//check if the new move resulted in a win
return 1;
else if

}[/code]


This is my entire code, excluding that function. I'm trying to learn to use classes and enums and it's giving me a lot of errors. It's finally compiling but I can't do much with it.

using namespace std;
#include <iostream>


	enum class Player : char {
		X,
		O,
		None,
	};
Player X;
const Player board[9] = { X,X,X,X,X,X,X,X,X };

int index(int i, int j)
{
	int ans = i * 3 + j;

	return  ans;
}

void copyBoard(const Player orig[9], Player copy[9])
{
	for (int i = 0; i<9; i++)
		copy[i] = orig[i];
}


Player checkBoard(const Player board[9]) {
	Player a = Player::X; 
	Player b = Player::o/>;
	Player c = Player::None;
	


	if (board[0] == a && board[1] == a && board[2] == a)
		return a;
	else if (board[3] == a && board[4] == a && board[5] == a)
		return a;
	else if (board[6] == a && board[7] == a && board[8] == a)
		return a;
	else if (board[0] == a && board[3] == a && board[6] == a)
		return a;
	else if (board[1] == a && board[4] == a && board[7] == a)
		return a;
	else if (board[2] == a && board[5] == a && board[8] == a)
		return a;
	else if (board[0] == a && board[4] == a && board[8] == a)
		return a;
	else if (board[2] == a && board[4] == a && board[6] == a)
		return a;
	if (board[0] == b && board[1] == b && board[2] == B)/>
		return b;
	else if (board[3] == b && board[4] == b && board[5] == B)/>
		return b;
	else if (board[6] == b && board[7] == b && board[8] == B)/>
		return b;
	else if (board[0] == b && board[3] == b && board[6] == B)/>
		return b;
	else if (board[1] == b && board[4] == b && board[7] == B)/>
		return b;
	else if (board[2] == b && board[5] == b && board[8] == B)/>
		return b;
	else if (board[0] == b && board[4] == b && board[8] == B)/>
		return b;
	else if (board[2] == b && board[4] == b && board[6] == B)/>
		return b;
		
	else
		return c;

}



int main(){
//int x;
//int y;
//cout<<index(0,1);
   //cout<< chooseNextMove(board, X, x,y);
  return 0;
}


Full code

View Posthelloworld135, on 03 October 2015 - 12:20 AM, said:

I'm trying to make a basic tictactoe AIThis is the function I'm trying to create below, I don't need anything more complex yet. I have a few problems right now, I changed everything to enums and I'm getting a lot of errors in my original code.

My biggest problem about the SECOND CODE is I don't know how to call my new checkBoard function. If I put cout<<checkBoard(board, orig) in the main for example, I get errors. I don't know how I can actually call this function ever since I changed it to Player instead of const int.

It's hard to test the first part of my code because my checkBoard and my copyBoard functions aren't working anymore.

/**
 * Choose the next move for a player.
 *
 * Given a current state of a board, choose the best next move
 * for a particular player.
 *
 * @param[in]  board    the current board state (Xs, Os and Nones)
 * @param[in]  player   whose turn it is (X or O)
 * @param[out] row      the row that the player should choose
 * @param[out] col      the column that the player should choose
 *
 * @returns    whether or not this move can result in a win
 */
bool chooseNextMove(const Player board[9], Player player, int &row, int &col){

  while (checkBoard(board)=false){

  copyBoard(board[9],copy[9]);//copies array
  int answer=index(int &row, int &col);//See index value of array where I need to add an X or O
   copy[answer]=player // put the value "player"(X or O) where the move took place
   
   if (checkBoard(copy)==Player)//check if the new move resulted in a win
    return 1;
else if
    
}



This is my entire code, excluding that function. I'm trying to learn to use classes and enums and it's giving me a lot of errors. It's finally compiling but I can't do much with it.

using namespace std;
#include <iostream>


	enum class Player : char {
		X,
		O,
		None,
	};
Player X;
const Player board[9] = { X,X,X,X,X,X,X,X,X };

int index(int i, int j)
{
	int ans = i * 3 + j;

	return  ans;
}

void copyBoard(const Player orig[9], Player copy[9])
{
	for (int i = 0; i<9; i++)
		copy[i] = orig[i];
}


Player checkBoard(const Player board[9]) {
	Player a = Player::X; 
	Player b = Player::o/>/>;
	Player c = Player::None;
	


	if (board[0] == a && board[1] == a && board[2] == a)
		return a;
	else if (board[3] == a && board[4] == a && board[5] == a)
		return a;
	else if (board[6] == a && board[7] == a && board[8] == a)
		return a;
	else if (board[0] == a && board[3] == a && board[6] == a)
		return a;
	else if (board[1] == a && board[4] == a && board[7] == a)
		return a;
	else if (board[2] == a && board[5] == a && board[8] == a)
		return a;
	else if (board[0] == a && board[4] == a && board[8] == a)
		return a;
	else if (board[2] == a && board[4] == a && board[6] == a)
		return a;
	if (board[0] == b && board[1] == b && board[2] == B)/>/>
		return b;
	else if (board[3] == b && board[4] == b && board[5] == B)/>/>
		return b;
	else if (board[6] == b && board[7] == b && board[8] == B)/>/>
		return b;
	else if (board[0] == b && board[3] == b && board[6] == B)/>/>
		return b;
	else if (board[1] == b && board[4] == b && board[7] == B)/>/>
		return b;
	else if (board[2] == b && board[5] == b && board[8] == B)/>/>
		return b;
	else if (board[0] == b && board[4] == b && board[8] == B)/>/>
		return b;
	else if (board[2] == b && board[4] == b && board[6] == B)/>/>
		return b;
		
	else
		return c;

}



int main(){
//int x;
//int y;
//cout<<index(0,1);
   //cout<< chooseNextMove(board, X, x,y);
  return 0;
}


I'm trying to make a basic tictactoe AIThis is the function I'm trying to create below, I don't need anything more complex yet. I have a few problems right now, I changed everything to enums and I'm getting a lot of errors in my original code.

My biggest problem about the SECOND CODE is I don't know how to call my new checkBoard function. If I put cout<<checkBoard(board, orig) in the main for example, I get errors. I don't know how I can actually call this function ever since I changed it to Player instead of const int.

It's hard to test the first part of my code because my checkBoard and my copyBoard functions aren't working anymore.
/**
 * Choose the next move for a player.
 *
 * Given a current state of a board, choose the best next move
 * for a particular player.
 *
 * @param[in]  board    the current board state (Xs, Os and Nones)
 * @param[in]  player   whose turn it is (X or O)
 * @param[out] row      the row that the player should choose
 * @param[out] col      the column that the player should choose
 *
 * @returns    whether or not this move can result in a win
 */
bool chooseNextMove(const Player board[9], Player player, int &row, int &col){

  while (checkBoard(board)=false){

  copyBoard(board[9],copy[9]);//copies array
  int answer=index(int &row, int &col);//See index value of array where I need to add an X or O
   copy[answer]=player // put the value "player"(X or O) where the move took place
   
   if (checkBoard(copy)==Player)//check if the new move resulted in a win
    return 1;
else if
    
}



This is my entire code, excluding that function. I'm trying to learn to use classes and enums and it's giving me a lot of errors. It's finally compiling but I can't do much with it.

using namespace std;
#include <iostream>


	enum class Player : char {
		X,
		O,
		None,
	};
Player X;
const Player board[9] = { X,X,X,X,X,X,X,X,X };

int index(int i, int j)
{
	int ans = i * 3 + j;

	return  ans;
}

void copyBoard(const Player orig[9], Player copy[9])
{
	for (int i = 0; i<9; i++)
		copy[i] = orig[i];
}


Player checkBoard(const Player board[9]) {
	Player a = Player::X; 
	Player b = Player::o/>/>;
	Player c = Player::None;
	


	if (board[0] == a && board[1] == a && board[2] == a)
		return a;
	else if (board[3] == a && board[4] == a && board[5] == a)
		return a;
	else if (board[6] == a && board[7] == a && board[8] == a)
		return a;
	else if (board[0] == a && board[3] == a && board[6] == a)
		return a;
	else if (board[1] == a && board[4] == a && board[7] == a)
		return a;
	else if (board[2] == a && board[5] == a && board[8] == a)
		return a;
	else if (board[0] == a && board[4] == a && board[8] == a)
		return a;
	else if (board[2] == a && board[4] == a && board[6] == a)
		return a;
	if (board[0] == b && board[1] == b && board[2] == B)/>/>
		return b;
	else if (board[3] == b && board[4] == b && board[5] == B)/>/>
		return b;
	else if (board[6] == b && board[7] == b && board[8] == B)/>/>
		return b;
	else if (board[0] == b && board[3] == b && board[6] == B)/>/>
		return b;
	else if (board[1] == b && board[4] == b && board[7] == B)/>/>
		return b;
	else if (board[2] == b && board[5] == b && board[8] == B)/>/>
		return b;
	else if (board[0] == b && board[4] == b && board[8] == B)/>/>
		return b;
	else if (board[2] == b && board[4] == b && board[6] == B)/>/>
		return b;
		
	else
		return c;

}



int main(){
//int x;
//int y;
//cout<<index(0,1);
   //cout<< chooseNextMove(board, X, x,y);
  return 0;
}


Is This A Good Question/Topic? 0
  • +

Replies To: C++ Tictactoe code

#2 horace   User is offline

  • D.I.C Lover
  • member icon

Reputation: 768
  • View blog
  • Posts: 3,832
  • Joined: 25-October 06

Re: C++ Tictactoe code

Posted 03 October 2015 - 12:39 AM

in line 16 of chooseNextMove you have = should it be ==
  while (checkBoard(board)==false){

however, checkBoard() returns a Player
Player checkBoard(const Player board[9]) {

and you don't have an overloaded operator== method
Was This Post Helpful? 0
  • +
  • -

#3 helloworld135   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 03-October 15

Re: C++ Tictactoe code

Posted 03 October 2015 - 01:14 AM

View Posthorace, on 03 October 2015 - 12:39 AM, said:

in line 16 of chooseNextMove you have = should it be ==
  while (checkBoard(board)==false){

however, checkBoard() returns a Player
Player checkBoard(const Player board[9]) {

and you don't have an overloaded operator== method

How could I make the bottom part of the code work for "cout checkBoard(board, copy) for example?

The first part of my code isn't really what I'm working on yet, I can't test any of it because the bottom part of my code is giving me errors when I try to get an answer from any of the functions excluding index. It has something do with the class/enum's, it was working before when I had them as const int's.
Was This Post Helpful? 0
  • +
  • -

#4 baavgai   User is offline

  • Dreaming Coder
  • member icon


Reputation: 7507
  • View blog
  • Posts: 15,558
  • Joined: 16-October 07

Re: C++ Tictactoe code

Posted 03 October 2015 - 04:40 AM

I'd use more functions. Break down the problem. And no magic numbers. And no globals.

e.g.
enum class Player : char { X, O, None, };
const int BoardSize = 9;
typedef Player Board[BoardSize];

bool win(Board, Player, int, int, int);
bool playerWin(Board, Player);

Player checkBoard(Board board) {
    // I'll give you this one
    // you just need the other two
    // actually, you only need playerWin
    // however, if you can figure out
    // how playerWin would call win
    // your code will be easier
    if (playerWin(board, Player::X)) { return Player::X; }
    if (playerWin(board, Player::o/>)) { return Player::o/>; }
    return Player::None;
}



As a programming rule of thumb, you want to do the minimum of amount of testable stuff first, then test it. While you will get to "not working yet" states, you want them to be as short as possible. The very first thing I'd when programming tic tac toe would be print the board, as you kind of see that for each successive step. Then, take a turn on the board and print it again. And so on. Take small steps.

Hope this helps.
Was This Post Helpful? 0
  • +
  • -

#5 helloworld135   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 03-October 15

Re: C++ Tictactoe code

Posted 03 October 2015 - 10:26 AM

I'm not allowed to use more functions or change the function parameters(they were all that were given, and they will also be called by a main test code.)

I don't know how to call the board function in any of my set functions

For example, if I want to call checkBoard when board use to be a const in I'd just type checkBoard(board) and it would work. When I changed checkBoard to an enum class, it now gives me an error

I find it hard to test the logic of the new function I need because my old code won't work
Was This Post Helpful? 0
  • +
  • -

#6 horace   User is offline

  • D.I.C Lover
  • member icon

Reputation: 768
  • View blog
  • Posts: 3,832
  • Joined: 25-October 06

Re: C++ Tictactoe code

Posted 03 October 2015 - 10:31 AM

what is the specification and test code that you were given?
Was This Post Helpful? 0
  • +
  • -

#7 helloworld135   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 03-October 15

Re: C++ Tictactoe code

Posted 03 October 2015 - 11:24 AM

I was given header files which weren't allowed to be changed and I have to implement a code to do what's inside. Here they are below:

#if !defined(BOARD_H)
#define BOARD_H

#include <string>


namespace tictactoe {

//! A player in the game or the player that owns a square.
enum class Player : char {
	X,
	O,
	None,
};

//! Converts a Player value into a user-readable string.
std::string str(Player);


/**
 * Return the index within a 9-element array that corresponds to
 * row i and column j of the Tic-Tac-Toe board.
 *
 * Note that the 9-element array is laid out with row 0 first,
 * followed by row 1 and row 2.
 *
 * @param   i    a row of the board
 * @param   j    a column of the board
 *
 * @returns the corresponding index in a 9-element array
 *          (e.g., row 1 and column 2 => 5)
 */
int index(int i, int j);


/**
 * Copy the contents of one game matrix to another matrix.
 *
 * @param[in]   orig    the original game board
 * @param[out]  copy    where to put the copied game board
 */
void copyBoard(const Player orig[9], Player copy[9]);


/**
 * Check to see whether a Tic-Tac-Toe board is in a winning configuration.
 *
 * @param  board    a 3 x 3 matrix containing values that represent
 *                  Xs (X), Os (O) or empty spaces (None)
 *
 * @return X if the X side has won
 *         O if the O side has won
 *         None if neither X nor O has won
 */
Player checkBoard(const Player board[9]);

} // namespace tictactoe

#endif


/*!
 * @file      ai.h
 * @brief     Declarations of functions for the Tic-Tac-Toe AI player.
 *
 * @author    Jonathan Anderson <[email protected]>
 * @copyright (c) 2015 Jonathan Anderson. All rights reserved.
 * @license   Apache License, Version 2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License.  You may obtain a copy
 * of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

#if !defined(AI_H)
#define AI_H

#include "board.h"

namespace tictactoe {

/**
 * Choose the next move for a player.
 *
 * Given a current state of a board, choose the best next move
 * for a particular player.
 *
 * @param[in]  board    the current board state (Xs, Os and Nones)
 * @param[in]  player   whose turn it is (X or O)
 * @param[out] row      the row that the player should choose
 * @param[out] col      the column that the player should choose
 *
 * @returns    whether or not this move can result in a win
 */
bool chooseNextMove(const Player board[9], Player player, int &row, int &col);

} // namespace tictactoe

#endif


Was This Post Helpful? 0
  • +
  • -

#8 horace   User is offline

  • D.I.C Lover
  • member icon

Reputation: 768
  • View blog
  • Posts: 3,832
  • Joined: 25-October 06

Re: C++ Tictactoe code

Posted 03 October 2015 - 12:13 PM

for a start I would expect your test code to be using the header files given to you, e.g.
#include <iostream>
using namespace std;
#include "board.h"
#include "ai.h"

namespace tictactoe {

Player X;
const Player board[9] = { X,X,X,X,X,X,X,X,X };
....



should the start of chooseNextMove() be something along the lines of
bool chooseNextMove(const Player board[9], Player player, int &row, int &col){
  while (checkBoard(board)==Player::None){
    Player copy[9];
    copyBoard(board,copy);//copies array
 ...


Was This Post Helpful? 0
  • +
  • -

#9 baavgai   User is offline

  • Dreaming Coder
  • member icon


Reputation: 7507
  • View blog
  • Posts: 15,558
  • Joined: 16-October 07

Re: C++ Tictactoe code

Posted 03 October 2015 - 01:29 PM

Interesting. Note, in C++, there is no requirement that files ONLY have functions that are defined in their headers. Indeed, functions in headers are only the functions you wish to share.
Was This Post Helpful? 0
  • +
  • -

#10 helloworld135   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 03-October 15

Re: C++ Tictactoe code

Posted 03 October 2015 - 02:22 PM

I have my main code written with headers, I just put it all in one file to test it easier

So when I try to call my checkBoard function like this(cout in main) it gives me an error saying cannot bind to STD stream

As for the ai part of the code(checkBestNextMove) is there a way I can input the "Player X or O" defined by the user? Like, if someone puts O ... I'd want my code to say if(checkBoard(board)==O) for example. I basically want to take the "Player player" part in the function header and take the input and make it a condition for my code.

  using namespace std;
#include <iostream>


	enum class Player : char {
		X,
		O,
		None,
	};
Player X;
Player None;
Player O;
const Player board[9]={None,None,X,X,X,X,X,X,X};

int index(int i, int j)
{
	int ans = i * 3 + j;

	return  ans;
}

void copyBoard(const Player orig[9], Player copy[9])
{
	for (int i = 0; i<9; i++)
		copy[i] = orig[i];
}


Player checkBoard(const Player board[9]) {
	Player a = Player::X; 
	Player b = Player::o/>;
	Player c = Player::None;
	


	if (board[0] == a && board[1] == a && board[2] == a)
		return a;
	else if (board[3] == a && board[4] == a && board[5] == a)
		return a;
	else if (board[6] == a && board[7] == a && board[8] == a)
		return a;
	else if (board[0] == a && board[3] == a && board[6] == a)
		return a;
	else if (board[1] == a && board[4] == a && board[7] == a)
		return a;
	else if (board[2] == a && board[5] == a && board[8] == a)
		return a;
	else if (board[0] == a && board[4] == a && board[8] == a)
		return a;
	else if (board[2] == a && board[4] == a && board[6] == a)
		return a;
	if (board[0] == b && board[1] == b && board[2] == B)/>
		return b;
	else if (board[3] == b && board[4] == b && board[5] == B)/>
		return b;
	else if (board[6] == b && board[7] == b && board[8] == B)/>
		return b;
	else if (board[0] == b && board[3] == b && board[6] == B)/>
		return b;
	else if (board[1] == b && board[4] == b && board[7] == B)/>
		return b;
	else if (board[2] == b && board[5] == b && board[8] == B)/>
		return b;
	else if (board[0] == b && board[4] == b && board[8] == B)/>
		return b;
	else if (board[2] == b && board[4] == b && board[6] == B)/>
		return b;
	else
		return c;

}


bool chooseNextMove(const Player board[9], Player player, int &row, int &col){



  //else if(checkBoard(board)==Player::player);
  //return 1;
  //else if
    
  //  Player copy[9];
  //  copyBoard(board,copy);
  }
int main(){
  
   cout<<(checkBoard(board));
    return 0;
}

Was This Post Helpful? 0
  • +
  • -

#11 baavgai   User is offline

  • Dreaming Coder
  • member icon


Reputation: 7507
  • View blog
  • Posts: 15,558
  • Joined: 16-October 07

Re: C++ Tictactoe code

Posted 03 October 2015 - 03:28 PM

Don't forget to implement this:
std::string str(Player);



Indeed, I'd implement that first.

You cant test with:
Player p(Player::X);
// this doesn't work
// std::cout << Player::X << std::endl;
std::cout << str(Player::X) << std::endl;
std::cout << (p==Player::X) << std::endl;
std::cout << (str(Player::X)=="X") << std::endl;



To process user input, read a string from the user and look at the last line of my test.

Hope this helps.

This post has been edited by baavgai: 03 October 2015 - 03:29 PM

Was This Post Helpful? 0
  • +
  • -

#12 helloworld135   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 03-October 15

Re: C++ Tictactoe code

Posted 04 October 2015 - 02:36 PM

I tried and it still won't putput for checkBoard

  using namespace std;
#include <iostream>
#include <sstream>




	enum class Player : char {
		X,
		O,
		None,
	};
Player X;
Player None;
Player O;
string str(Player);

const Player board[9]={None,None,X,X,X,X,X,X,X};

int index(int i, int j)
{
	int ans = i * 3 + j;

	return  ans;
}

void copyBoard(const Player orig[9], Player copy[9])
{
	for (int i = 0; i<9; i++)
		copy[i] = orig[i];
}


Player checkBoard(const Player board[9]) {
	Player a = Player::X; 
	Player b = Player::o/>    ;
	Player c = Player::None;
	


	if (board[0] == a && board[1] == a && board[2] == a)
		return a;
	else if (board[3] == a && board[4] == a && board[5] == a)
		return a;
	else if (board[6] == a && board[7] == a && board[8] == a)
		return a;
	else if (board[0] == a && board[3] == a && board[6] == a)
		return a;
	else if (board[1] == a && board[4] == a && board[7] == a)
		return a;
	else if (board[2] == a && board[5] == a && board[8] == a)
		return a;
	else if (board[0] == a && board[4] == a && board[8] == a)
		return a;
	else if (board[2] == a && board[4] == a && board[6] == a)
		return a;
	if (board[0] == b && board[1] == b && board[2] == B)/>
		return b;
	else if (board[3] == b && board[4] == b && board[5] ==  B)/>
		return b;
	else if (board[6] == b && board[7] == b && board[8] ==B)/>
		return b;
	else if (board[0] == b && board[3] == b && board[6] == B)/>
		return b;
	else if (board[1] == b && board[4] == b && board[7] == B)/>
		return b;
	else if (board[2] == b && board[5] == b && board[8] == B)/>
		return b;
	else if (board[0] == b && board[4] == b && board[8] == B)/>
		return b;
	else if (board[2] == b && board[4] == b && board[6] ==B)/>
		return b;
	else
		return c;

}


bool chooseNextMove(const Player board[9], Player player, int &row, int &col){

   // Player p;
//string str(Player);
//cout << str(Player::X);
//cout << (player==Player::X);
//cout << (str(Player::X)=="X");


  //else if(checkBoard(board)==Player::player);
  //return 1;
  //else if
    
  //  Player copy[9];
  //  copyBoard(board,copy);
  return 0;
  }
int main(){

cout << str(checkBoard(board)) ;




   //std::cout<<(checkBoard(board));
    return 0;
}


Was This Post Helpful? 0
  • +
  • -

#13 baavgai   User is offline

  • Dreaming Coder
  • member icon


Reputation: 7507
  • View blog
  • Posts: 15,558
  • Joined: 16-October 07

Re: C++ Tictactoe code

Posted 04 October 2015 - 05:19 PM

I don't see the implementation code for std::string str(Player);. If you've implemented it to show Player::None as " ", consider a visible placeholder for now (e.g. ".") just to see what's going on.

This post has been edited by baavgai: 04 October 2015 - 05:19 PM

Was This Post Helpful? 1
  • +
  • -

#14 #define   User is offline

  • Cannot compute!
  • member icon

Reputation: 1868
  • View blog
  • Posts: 6,763
  • Joined: 19-February 09

Re: C++ Tictactoe code

Posted 04 October 2015 - 05:25 PM

Are you allowed to set the characters for Player? :

	enum class Player : char {
		X = 'X',
		O,
		None,
	};




Edit: it is likely not needed but might help with the logic while creating the program.
.

This post has been edited by #define: 04 October 2015 - 06:11 PM

Was This Post Helpful? 0
  • +
  • -

#15 helloworld135   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 03-October 15

Re: C++ Tictactoe code

Posted 05 October 2015 - 04:45 AM

View Post#define, on 04 October 2015 - 05:25 PM, said:

Are you allowed to set the characters for Player? :

	enum class Player : char {
		X = 'X',
		O,
		None,
	};




Edit: it is likely not needed but might help with the logic while creating the program.
.
No, but my code won't compile right now. The cout line is giving me a compile error.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2