Prompt Details
Model
Completion - GPT-3.5 (text-davinci-003)
Token size
114 ($0.00230 / call)
Example input
Use this version of C++: [C++98, C++03, C++11, C++14,C++17]. My first request is "[Tic Tac Toe game]". Make this code optimized for time and space complexity.
Example output
// .hpp
class CTikTakToe
{
public:
enum class EPlayer
{
None,
Player1,
Player2
};
struct SMove
{
int x;
int y;
};
CTikTakToe();
bool MakeMove(int x, int y);
bool IsFinished() const;
EPlayer GetWinner() const;
SMove GetLastMove() const;
EPlayer GetPlayerAt(int x, int y) const;
private:
EPlayer m_aBoard[3][3]; //game board
EPlayer m_eCurrentPlayer; // current player
EPlayer m_eWinner; // winner player
SMove m_sLastMove; // last move made
bool m_bFinished; // flag to check game status
};
private:
// Check if a line of 3 cells is a win
bool IsLineWin(int a_Row1, int a_Col1, int a_Row2, int a_Col2, int a_Row3, int a_Col3, char a_Player) const;
std::array<std::array<char, kBoardSize>, kBoardSize> m_Board;
};
// .cpp
bool CTikTakToe::MakeMove(int x, int y)
{
if (x < 0 || x >= 3 || y < 0 || y >= 3)
{
return false; // Invalid move
}
if (m_aBoard[x][y] != EPlayer::None)
{
return false; // Position already filled
}
if (m_bFinished)
{
return false; // Game already finished
}
m_aBoard[x][y] = m_eCurrentPlayer;
m_sLastMove = { x, y };
// Check for winner or draw
if (CheckForWinner())
{
return true;
}
// Switch current player
m_eCurrentPlayer = (m_eCurrentPlayer == EPlayer::Player1) ? EPlayer::Player2 : EPlayer::Player1;
return true;
}
Get this prompt + 9 more with Select$14 first month, then $19/mo · Cancel anytime$14 first month · then $19/mo
View SelectBy purchasing this prompt, you agree to our terms of service
TEXT-DAVINCI-003
This AI prompt is designed to generate high-quality, efficient code in the C++ programming language as if it were written by a senior software engineer.
It trains the AI to optimize for both time and space complexity, making use of advanced algorithms and data structures to create efficient and performant software. Additionally, it directs the AI to use object-oriented programming principles, allowing it to create well-organized and reusable code.
The AI also places a strong emphasis on documentation, ensuring that the code it generates is clear, well-commented, and easy to understand.
We appreciate your time and feedback, please share your experience with our Senior C++ Software Engineer by writing a review. Thank you!
...more
Added over 1 month ago

