Archives from S:\ Drive
Good to keep around methinks
This commit is contained in:
1 parent
eadaf70b9e
commit
6dd63cc439
606 files changed
+50212
No files matched your search
@@ -0,0 +1,20 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 10.00
|
||||
# Visual Studio 2008
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Tic-Tac-Toe", "Tic-Tac-Toe\Tic-Tac-Toe.vcproj", "{863E75FC-8626-4DBC-A121-25BC87C72E82}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{863E75FC-8626-4DBC-A121-25BC87C72E82}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{863E75FC-8626-4DBC-A121-25BC87C72E82}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{863E75FC-8626-4DBC-A121-25BC87C72E82}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{863E75FC-8626-4DBC-A121-25BC87C72E82}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 9.00
|
||||
# Visual Studio 2005
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Tic-Tac-Toe", "Tic-Tac-Toe\Tic-Tac-Toe.vcproj", "{863E75FC-8626-4DBC-A121-25BC87C72E82}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{863E75FC-8626-4DBC-A121-25BC87C72E82}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{863E75FC-8626-4DBC-A121-25BC87C72E82}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{863E75FC-8626-4DBC-A121-25BC87C72E82}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{863E75FC-8626-4DBC-A121-25BC87C72E82}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
Binary file not shown.
@@ -0,0 +1,19 @@
|
||||
#include "Tic_Tac_Toe.h"
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
Tic_Tac_Toe ttt;
|
||||
while (true)
|
||||
{
|
||||
ttt.run();
|
||||
cout << endl << "Would you like to play again?" << endl << "[Y/n]:";
|
||||
string input;
|
||||
cin >> input;
|
||||
if (toupper(input[0]) != 'Y')
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="9.00"
|
||||
Name="Tic-Tac-Toe"
|
||||
ProjectGUID="{863E75FC-8626-4DBC-A121-25BC87C72E82}"
|
||||
RootNamespace="TicTacToe"
|
||||
TargetFrameworkVersion="131072"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
GenerateDebugInformation="true"
|
||||
RandomizedBaseAddress="1"
|
||||
DataExecutionPrevention="0"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="2"
|
||||
WholeProgramOptimization="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
RuntimeLibrary="2"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
GenerateDebugInformation="true"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
RandomizedBaseAddress="1"
|
||||
DataExecutionPrevention="0"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\Main.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Tic_Tac_Toe.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\Tic_Tac_Toe.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
|
||||
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
|
||||
>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
+196
@@ -0,0 +1,196 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8.00"
|
||||
Name="Tic-Tac-Toe"
|
||||
ProjectGUID="{863E75FC-8626-4DBC-A121-25BC87C72E82}"
|
||||
RootNamespace="TicTacToe"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
GenerateDebugInformation="true"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="2"
|
||||
WholeProgramOptimization="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
RuntimeLibrary="2"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
GenerateDebugInformation="true"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\Main.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Tic_Tac_Toe.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\Tic_Tac_Toe.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
|
||||
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
|
||||
>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
@@ -0,0 +1,686 @@
|
||||
#include "Tic_Tac_Toe.h"
|
||||
|
||||
|
||||
Tic_Tac_Toe::Tic_Tac_Toe()
|
||||
{
|
||||
initboard();
|
||||
sethuman('X');
|
||||
setcomputer('O');
|
||||
initeasymoves();
|
||||
instructionsdisplayed = false;
|
||||
}
|
||||
|
||||
void Tic_Tac_Toe::initeasymoves()
|
||||
{
|
||||
int easymoofs[] = { 4,0,2,6,8,1,3,5,7 };
|
||||
for (int i = 0; i < 9; i++)
|
||||
{
|
||||
easyMoves[i] = easymoofs[i];
|
||||
}
|
||||
}
|
||||
|
||||
bool Tic_Tac_Toe::winner()
|
||||
{
|
||||
for (int i = 0; i <= 2; i++)
|
||||
{
|
||||
char curCheck = gethuman();
|
||||
if (i == 1)
|
||||
{
|
||||
curCheck = getcomputer();
|
||||
}
|
||||
|
||||
//vertical
|
||||
if ((board[0] == curCheck && board[3] == curCheck && board[6] == curCheck) ||
|
||||
(board[1] == curCheck && board[4] == curCheck && board[7] == curCheck) ||
|
||||
(board[2] == curCheck && board[5] == curCheck && board[8] == curCheck))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// horizontal
|
||||
if ((board[0] == curCheck && board[1] == curCheck && board[2] == curCheck) ||
|
||||
(board[6] == curCheck && board[7] == curCheck && board[8] == curCheck) ||
|
||||
(board[3] == curCheck && board[4] == curCheck && board[5] == curCheck))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// diagonal
|
||||
if ((board[4] == curCheck && board[0] == curCheck && board[8] == curCheck) ||
|
||||
(board[4] == curCheck && board[2] == curCheck && board[6] == curCheck))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Tic_Tac_Toe::displayInstructions()
|
||||
{
|
||||
cout << "Instructions: Use your keyboard to type in coordinates to place a "
|
||||
<< endl << "token on the game board. " << endl << endl;
|
||||
cout << "You are X - the protagonast in the story - you have been chrosen by the high " << endl
|
||||
<< "council of Tic-Toe to defeat the evil lord O, played by the computer. " << endl;
|
||||
cout << "Being the chosen one you are able to place your 'X'" << endl
|
||||
<< "token first, in an any open space." << endl;
|
||||
cout << "The computer then places the O token in a free space until " << endl
|
||||
<< "all spaces are filled" << endl;
|
||||
cout << "You and the computer continue to place tokens in free spaces until the game" << endl
|
||||
<< "board is filled " << endl;
|
||||
cout << "If all spaces are filled and no winner has been declared then a rematch is "
|
||||
<< endl << "called and the forces of good and evil spar once again." << endl;
|
||||
system("pause");
|
||||
system("cls");
|
||||
}
|
||||
|
||||
void Tic_Tac_Toe::initboard()
|
||||
{
|
||||
for (int i = 0; i < 9; i++)
|
||||
{
|
||||
board[i] = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
void Tic_Tac_Toe::run()
|
||||
{
|
||||
bool iseasy = true;
|
||||
if (!instructionsdisplayed)
|
||||
{
|
||||
displayInstructions();
|
||||
instructionsdisplayed = true;
|
||||
}
|
||||
initboard();
|
||||
while (true)
|
||||
{
|
||||
cout << "Would you like to play in Easy mode or Hard mode ?" << endl << "[E/h]:";
|
||||
string input;
|
||||
cin >> input;
|
||||
if (toupper(input[0]) == 'E')
|
||||
{
|
||||
iseasy = true;
|
||||
break;
|
||||
}
|
||||
else if (toupper(input[0]) == 'H')
|
||||
{
|
||||
iseasy = false;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Invalid selection, please try again." << endl;
|
||||
}
|
||||
}
|
||||
while (true)
|
||||
{
|
||||
displayBoard();
|
||||
if (stalemate())
|
||||
{
|
||||
cout << "Stale mate!" << endl;
|
||||
system("pause");
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
setisWin(winner());
|
||||
if(getisWin())
|
||||
{
|
||||
cout << "Sorry, the computer wins this round." << endl;
|
||||
system("pause");
|
||||
break;
|
||||
}
|
||||
getInput();
|
||||
}
|
||||
displayBoard();
|
||||
if (stalemate())
|
||||
{
|
||||
cout << "Stale mate!" << endl;
|
||||
system("pause");
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
setisWin(winner());
|
||||
if(getisWin())
|
||||
{
|
||||
cout << "Congradulations! A Winner is You!" << endl;
|
||||
system("pause");
|
||||
break;
|
||||
}
|
||||
think(iseasy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Tic_Tac_Toe::stalemate()
|
||||
{
|
||||
for (int i = 0; i < 9; i++)
|
||||
{
|
||||
if (board[i] == ' ')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Tic_Tac_Toe::think(bool easy)
|
||||
{
|
||||
if (easy)
|
||||
{
|
||||
for (int i = 0; i <= 8; i++)
|
||||
{
|
||||
if (board[easyMoves[i]] == ' ')
|
||||
{
|
||||
board[easyMoves[i]] = getcomputer();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// offencive think -- special cases || win in two
|
||||
if (board[0] == getcomputer() && board[2] == getcomputer() && board[1] == ' ' )
|
||||
{
|
||||
board[1] = getcomputer();
|
||||
return;
|
||||
} else if (board[3] == getcomputer() && board[5] == getcomputer() && board[4] == ' ' )
|
||||
{
|
||||
board[4] = getcomputer();
|
||||
return;
|
||||
} else if (board[6] == getcomputer() && board[8] == getcomputer() && board[7] == ' ' )
|
||||
{
|
||||
board[7] = getcomputer();
|
||||
return;
|
||||
} else if (board[0] == getcomputer() && board[6] == getcomputer() && board[3] == ' ' )
|
||||
{
|
||||
board[3] = getcomputer();
|
||||
return;
|
||||
} else if (board[1] == getcomputer() && board[7] == getcomputer() && board[4] == ' ' )
|
||||
{
|
||||
board[4] = getcomputer();
|
||||
return;
|
||||
} else if (board[2] == getcomputer() && board[8] == getcomputer() && board[5] == ' ' )
|
||||
{
|
||||
board[5] = getcomputer();
|
||||
return;
|
||||
} else if (board[0] == getcomputer() && board[8] == getcomputer() && board[4] == ' ' )
|
||||
{
|
||||
board[4] = getcomputer();
|
||||
return;
|
||||
} else if (board[2] == getcomputer() && board[6] == getcomputer() && board[4] == ' ' )
|
||||
{
|
||||
board[4] = getcomputer();
|
||||
return;
|
||||
}
|
||||
// offencive think -- main think || win in one
|
||||
for (int i = 0; i <= 8; i++)
|
||||
{
|
||||
switch(i)
|
||||
{
|
||||
case 0:
|
||||
if (board[0] == getcomputer() && board[1] == getcomputer() && board[2] == ' ') //across
|
||||
{
|
||||
board[2] = getcomputer();
|
||||
return;
|
||||
}
|
||||
else if (board[0] == getcomputer() && board[4] == getcomputer() && board[8] == ' ') //diag
|
||||
{
|
||||
board[8] = getcomputer();
|
||||
return;
|
||||
}
|
||||
else if (board[0] == getcomputer() && board[3] == getcomputer() && board[6] == ' ') //down
|
||||
{
|
||||
board[6] = getcomputer();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (board[1] == getcomputer() && board[4] == getcomputer() && board[7] == ' ') //down
|
||||
{
|
||||
board[7] = getcomputer();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (board[2] == getcomputer() && board[4] == getcomputer() && board[6] == ' ') //diag
|
||||
{
|
||||
board[6] = getcomputer();
|
||||
return;
|
||||
}
|
||||
else if (board[2] == getcomputer() && board[5] == getcomputer() && board[8] == ' ') // down
|
||||
{
|
||||
board[8] = getcomputer();
|
||||
return;
|
||||
}
|
||||
else if (board[2] == getcomputer() && board[1] == getcomputer() && board[0] == ' ') //across
|
||||
{
|
||||
board[0] = getcomputer();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (board[3] == getcomputer() && board[4] == getcomputer() && board[5] == ' ') // across
|
||||
{
|
||||
board[5] = getcomputer();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
// this is the middle square. doesn't really matter.
|
||||
// case is checked virtually everywhere else
|
||||
break;
|
||||
case 5:
|
||||
if (board[5] == getcomputer() && board[4] == getcomputer() && board[3] == ' ')
|
||||
{
|
||||
board[3] = getcomputer();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
if (board[6] == getcomputer() && board[7] == getcomputer() && board[8] == ' ') //across
|
||||
{
|
||||
board[8] = getcomputer();
|
||||
return;
|
||||
}
|
||||
else if (board[6] == getcomputer() && board[4] == getcomputer() && board[2] == ' ') //diag
|
||||
{
|
||||
board[8] = getcomputer();
|
||||
return;
|
||||
}
|
||||
else if (board[6] == getcomputer() && board[3] == getcomputer() && board[0] == ' ') //down
|
||||
{
|
||||
board[0] = getcomputer();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
if (board[7] == getcomputer() && board[4] == getcomputer() && board[1] == ' ') //down
|
||||
{
|
||||
board[1] = getcomputer();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 8:
|
||||
if (board[8] == getcomputer() && board[4] == getcomputer() && board[0] == ' ') //diag
|
||||
{
|
||||
board[0] = getcomputer();
|
||||
return;
|
||||
}
|
||||
else if (board[8] == getcomputer() && board[5] == getcomputer() && board[2] == ' ') // down
|
||||
{
|
||||
board[2] = getcomputer();
|
||||
return;
|
||||
}
|
||||
else if (board[8] == getcomputer() && board[7] == getcomputer() && board[6] == ' ') //across
|
||||
{
|
||||
board[6] = getcomputer();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// defencive think -- special cases || block in one
|
||||
if (board[0] == gethuman() && board[2] == gethuman() && board[1] == ' ' )
|
||||
{
|
||||
board[1] = getcomputer();
|
||||
return;
|
||||
} else if (board[3] == gethuman() && board[5] == gethuman() && board[4] == ' ' )
|
||||
{
|
||||
board[4] = getcomputer();
|
||||
return;
|
||||
} else if (board[6] == gethuman() && board[8] == gethuman() && board[7] == ' ' )
|
||||
{
|
||||
board[7] = getcomputer();
|
||||
return;
|
||||
} else if (board[0] == gethuman() && board[6] == gethuman() && board[3] == ' ' )
|
||||
{
|
||||
board[3] = getcomputer();
|
||||
return;
|
||||
} else if (board[1] == gethuman() && board[7] == gethuman() && board[4] == ' ' )
|
||||
{
|
||||
board[4] = getcomputer();
|
||||
return;
|
||||
} else if (board[2] == gethuman() && board[8] == gethuman() && board[5] == ' ' )
|
||||
{
|
||||
board[5] = getcomputer();
|
||||
return;
|
||||
} else if (board[0] == gethuman() && board[8] == gethuman() && board[4] == ' ' )
|
||||
{
|
||||
board[4] = getcomputer();
|
||||
return;
|
||||
} else if (board[2] == gethuman() && board[6] == gethuman() && board[4] == ' ' )
|
||||
{
|
||||
board[4] = getcomputer();
|
||||
return;
|
||||
}
|
||||
//main defencive think || blocks
|
||||
for (int i = 0; i <= 8; i++)
|
||||
{
|
||||
switch(i)
|
||||
{
|
||||
case 0:
|
||||
if (board[0] == gethuman() && board[1] == gethuman() && board[2] == ' ') //across
|
||||
{
|
||||
board[2] = getcomputer();
|
||||
return;
|
||||
}
|
||||
else if (board[0] == gethuman() && board[4] == gethuman() && board[8] == ' ') //diag
|
||||
{
|
||||
board[8] = getcomputer();
|
||||
return;
|
||||
}
|
||||
else if (board[0] == gethuman() && board[3] == gethuman() && board[6] == ' ') //down
|
||||
{
|
||||
board[6] = getcomputer();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (board[1] == gethuman() && board[4] == gethuman() && board[7] == ' ') //down
|
||||
{
|
||||
board[7] = getcomputer();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (board[2] == gethuman() && board[4] == gethuman() && board[6] == ' ') //diag
|
||||
{
|
||||
board[6] = getcomputer();
|
||||
return;
|
||||
}
|
||||
else if (board[2] == gethuman() && board[5] == gethuman() && board[8] == ' ') // down
|
||||
{
|
||||
board[8] = getcomputer();
|
||||
return;
|
||||
}
|
||||
else if (board[2] == gethuman() && board[1] == gethuman() && board[0] == ' ') //across
|
||||
{
|
||||
board[0] = getcomputer();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (board[3] == gethuman() && board[4] == gethuman() && board[5] == ' ') // across
|
||||
{
|
||||
board[5] = getcomputer();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
// this is the middle square. doesn't really matter.
|
||||
// case is checked virtually everywhere else
|
||||
break;
|
||||
case 5:
|
||||
if (board[5] == gethuman() && board[4] == gethuman() && board[3] == ' ')
|
||||
{
|
||||
board[3] = getcomputer();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
if (board[6] == gethuman() && board[7] == gethuman() && board[8] == ' ') //across
|
||||
{
|
||||
board[8] = getcomputer();
|
||||
return;
|
||||
}
|
||||
else if (board[6] == gethuman() && board[4] == gethuman() && board[2] == ' ') //diag
|
||||
{
|
||||
board[8] = getcomputer();
|
||||
return;
|
||||
}
|
||||
else if (board[6] == gethuman() && board[3] == gethuman() && board[0] == ' ') //down
|
||||
{
|
||||
board[0] = getcomputer();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
if (board[7] == gethuman() && board[4] == gethuman() && board[1] == ' ') //down
|
||||
{
|
||||
board[1] = getcomputer();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 8:
|
||||
if (board[8] == gethuman() && board[4] == gethuman() && board[0] == ' ') //diag
|
||||
{
|
||||
board[0] = getcomputer();
|
||||
return;
|
||||
}
|
||||
else if (board[8] == gethuman() && board[5] == gethuman() && board[2] == ' ') // down
|
||||
{
|
||||
board[2] = getcomputer();
|
||||
return;
|
||||
}
|
||||
else if (board[8] == gethuman() && board[7] == gethuman() && board[6] == ' ') //across
|
||||
{
|
||||
board[6] = getcomputer();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i <= 8; i++)
|
||||
{
|
||||
if (board[easyMoves[i]] == ' ')
|
||||
{
|
||||
board[easyMoves[i]] = getcomputer();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Tic_Tac_Toe::getInput()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
cout << "Coordinates" << endl << ">:";
|
||||
string input;
|
||||
cin >> input;
|
||||
bool isBad = false;
|
||||
if (isalpha(input[0]) && isdigit(input[1]))
|
||||
{
|
||||
if ((toupper(input[0]) != 'A' && toupper(input[0]) != 'B' && toupper(input[0]) != 'C') ||
|
||||
(input[1] != '1' && input[1] != '2' && input[1] != '3'))
|
||||
{
|
||||
cout << "Error: Bad coordinates" << endl;
|
||||
}
|
||||
switch (toupper(input[0]))
|
||||
{
|
||||
case 'A':
|
||||
switch (input[1])
|
||||
{
|
||||
case '1':
|
||||
if (board[0] == ' ')
|
||||
{
|
||||
board[0] = gethuman();
|
||||
}
|
||||
else
|
||||
{
|
||||
isBad = true;
|
||||
}
|
||||
break;
|
||||
case '2':
|
||||
if (board[1] == ' ')
|
||||
{
|
||||
board[1] = gethuman();
|
||||
}
|
||||
else
|
||||
{
|
||||
isBad = true;
|
||||
}
|
||||
break;
|
||||
case '3':
|
||||
if (board[2] == ' ')
|
||||
{
|
||||
board[2] = gethuman();
|
||||
}
|
||||
else
|
||||
{
|
||||
isBad = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'B':
|
||||
switch (input[1])
|
||||
{
|
||||
case '1':
|
||||
if (board[3] == ' ')
|
||||
{
|
||||
board[3] = gethuman();
|
||||
}
|
||||
else
|
||||
{
|
||||
isBad = true;
|
||||
}
|
||||
break;
|
||||
case '2':
|
||||
if (board[4] == ' ')
|
||||
{
|
||||
board[4] = gethuman();
|
||||
}
|
||||
else
|
||||
{
|
||||
isBad = true;
|
||||
}
|
||||
break;
|
||||
case '3':
|
||||
if (board[5] == ' ')
|
||||
{
|
||||
board[5] = gethuman();
|
||||
}
|
||||
else
|
||||
{
|
||||
isBad = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'C':
|
||||
switch (input[1])
|
||||
{
|
||||
case '1':
|
||||
if (board[6] == ' ')
|
||||
{
|
||||
board[6] = gethuman();
|
||||
}
|
||||
else
|
||||
{
|
||||
isBad = true;
|
||||
}
|
||||
break;
|
||||
case '2':
|
||||
if (board[7] == ' ')
|
||||
{
|
||||
board[7] = gethuman();
|
||||
}
|
||||
else
|
||||
{
|
||||
isBad = true;
|
||||
}
|
||||
break;
|
||||
case '3':
|
||||
if (board[8] == ' ')
|
||||
{
|
||||
board[8] = gethuman();
|
||||
}
|
||||
else
|
||||
{
|
||||
isBad = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (isBad)
|
||||
{
|
||||
cout << "Error: bad coordinates" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Input accepted!" << endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Error: bad coordinates" << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Tic_Tac_Toe::displayBoard()
|
||||
{
|
||||
cout << " ____________" << endl;
|
||||
cout << "A | " << board[0] << " | " << board[1] << " | " << board[2] << " |" << endl;
|
||||
cout << " ------------" << endl;
|
||||
cout << "B | " << board[3] << " | " << board[4] << " | " << board[5] << " |" << endl;
|
||||
cout << " ------------" << endl;
|
||||
cout << "C | " << board[6] << " | " << board[7] << " | " << board[8] << " |" << endl;
|
||||
cout << " ____________" << endl;
|
||||
cout << " 1 2 3 " << endl << endl;
|
||||
}
|
||||
|
||||
void Tic_Tac_Toe::isTie()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Tic_Tac_Toe::setisWin(bool isWin)
|
||||
{
|
||||
this->isWin = isWin;
|
||||
}
|
||||
bool Tic_Tac_Toe::getisWin()
|
||||
{
|
||||
return isWin;
|
||||
}
|
||||
|
||||
void Tic_Tac_Toe::sethuman(char human)
|
||||
{
|
||||
this->human = human;
|
||||
}
|
||||
char Tic_Tac_Toe::gethuman()
|
||||
{
|
||||
return human;
|
||||
}
|
||||
|
||||
void Tic_Tac_Toe::setcomputer(char computer)
|
||||
{
|
||||
this->computer = computer;
|
||||
}
|
||||
char Tic_Tac_Toe::getcomputer()
|
||||
{
|
||||
return computer;
|
||||
}
|
||||
|
||||
//void Tic_Tac_Toe::setboard(char* board)
|
||||
//{
|
||||
// this->board = *board;
|
||||
//}
|
||||
//char* Tic_Tac_Toe::getboard()
|
||||
//{
|
||||
// return board;
|
||||
//}
|
||||
|
||||
void Tic_Tac_Toe::setposition(int position)
|
||||
{
|
||||
this->position = position;
|
||||
}
|
||||
int Tic_Tac_Toe::getposition()
|
||||
{
|
||||
return position;
|
||||
}
|
||||
|
||||
//void Tic_Tac_Toe::seteasyMoves(char* moves)
|
||||
//{
|
||||
// this->easyMoves = *moves;
|
||||
//}
|
||||
//char* Tic_Tac_Toe::geteasyMoves()
|
||||
//{
|
||||
// return easyMoves;
|
||||
//}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <Windows.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#ifndef TIC_TAC_TOE_H
|
||||
#define TIC_TAC_TOE_H
|
||||
|
||||
class Tic_Tac_Toe {
|
||||
private:
|
||||
bool isWin;
|
||||
char human;
|
||||
char computer;
|
||||
char board[9];
|
||||
int position;
|
||||
int easyMoves[9];
|
||||
bool instructionsdisplayed;
|
||||
|
||||
public:
|
||||
Tic_Tac_Toe();
|
||||
|
||||
bool winner();
|
||||
bool stalemate();
|
||||
|
||||
void displayInstructions();
|
||||
void run();
|
||||
void displayBoard();
|
||||
void isTie();
|
||||
|
||||
void think(bool mode);
|
||||
void getInput();
|
||||
void initeasymoves();
|
||||
void initboard();
|
||||
|
||||
void setisWin(bool isWin);
|
||||
bool getisWin();
|
||||
|
||||
void sethuman(char human);
|
||||
char gethuman();
|
||||
|
||||
void setcomputer(char computer);
|
||||
char getcomputer();
|
||||
|
||||
void setboard(char* board);
|
||||
char* getboard();
|
||||
|
||||
void setposition(int position);
|
||||
int getposition();
|
||||
|
||||
void seteasyMoves(char* moves);
|
||||
char* geteasyMoves();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Visual Studio 2010
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Tic-Tac-Toe", "Tic-Tac-Toe\Tic-Tac-Toe.vcxproj", "{7FB90B9D-C85F-43E5-B174-11929EA4213F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{7FB90B9D-C85F-43E5-B174-11929EA4213F}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{7FB90B9D-C85F-43E5-B174-11929EA4213F}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{7FB90B9D-C85F-43E5-B174-11929EA4213F}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{7FB90B9D-C85F-43E5-B174-11929EA4213F}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,88 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{7FB90B9D-C85F-43E5-B174-11929EA4213F}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>TicTacToe</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="Tic_Tac_Toe.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Tic_Tac_Toe.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Tic_Tac_Toe.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Tic_Tac_Toe.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,686 @@
|
||||
#include "Tic_Tac_Toe.h"
|
||||
|
||||
|
||||
Tic_Tac_Toe::Tic_Tac_Toe()
|
||||
{
|
||||
initboard();
|
||||
sethuman('X');
|
||||
setcomputer('O');
|
||||
initeasymoves();
|
||||
instructionsdisplayed = false;
|
||||
}
|
||||
|
||||
void Tic_Tac_Toe::initeasymoves()
|
||||
{
|
||||
int easymoofs[] = { 4,0,2,6,8,1,3,5,7 };
|
||||
for (int i = 0; i < 9; i++)
|
||||
{
|
||||
easyMoves[i] = easymoofs[i];
|
||||
}
|
||||
}
|
||||
|
||||
bool Tic_Tac_Toe::winner()
|
||||
{
|
||||
for (int i = 0; i <= 2; i++)
|
||||
{
|
||||
char curCheck = gethuman();
|
||||
if (i == 1)
|
||||
{
|
||||
curCheck = getcomputer();
|
||||
}
|
||||
|
||||
//vertical
|
||||
if ((board[0] == curCheck && board[3] == curCheck && board[6] == curCheck) ||
|
||||
(board[1] == curCheck && board[4] == curCheck && board[7] == curCheck) ||
|
||||
(board[2] == curCheck && board[5] == curCheck && board[8] == curCheck))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// horizontal
|
||||
if ((board[0] == curCheck && board[1] == curCheck && board[2] == curCheck) ||
|
||||
(board[6] == curCheck && board[7] == curCheck && board[8] == curCheck) ||
|
||||
(board[3] == curCheck && board[4] == curCheck && board[5] == curCheck))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// diagonal
|
||||
if ((board[4] == curCheck && board[0] == curCheck && board[8] == curCheck) ||
|
||||
(board[4] == curCheck && board[2] == curCheck && board[6] == curCheck))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Tic_Tac_Toe::displayInstructions()
|
||||
{
|
||||
cout << "Instructions: Use your keyboard to type in coordinates to place a "
|
||||
<< endl << "token on the game board. " << endl << endl;
|
||||
cout << "You are X - the protagonist in the story - you have been chosen by the high " << endl
|
||||
<< "council of Tic-Toe to defeat the evil lord O, played by the computer. " << endl;
|
||||
cout << "Being the chosen one you are able to place your 'X'" << endl
|
||||
<< "token first, in an any open space." << endl;
|
||||
cout << "The computer then places the O token in a free space until " << endl
|
||||
<< "all spaces are filled" << endl;
|
||||
cout << "You and the computer continue to place tokens in free spaces until the game" << endl
|
||||
<< "board is filled " << endl;
|
||||
cout << "If all spaces are filled and no winner has been declared then a rematch is "
|
||||
<< endl << "called and the forces of good and evil spar once again." << endl;
|
||||
system("pause");
|
||||
system("cls");
|
||||
}
|
||||
|
||||
void Tic_Tac_Toe::initboard()
|
||||
{
|
||||
for (int i = 0; i < 9; i++)
|
||||
{
|
||||
board[i] = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
void Tic_Tac_Toe::run()
|
||||
{
|
||||
bool iseasy = true;
|
||||
if (!instructionsdisplayed)
|
||||
{
|
||||
displayInstructions();
|
||||
instructionsdisplayed = true;
|
||||
}
|
||||
initboard();
|
||||
while (true)
|
||||
{
|
||||
cout << "Would you like to play in Easy mode or Hard mode ?" << endl << "[E/h]:";
|
||||
string input;
|
||||
cin >> input;
|
||||
if (toupper(input[0]) == 'E')
|
||||
{
|
||||
iseasy = true;
|
||||
break;
|
||||
}
|
||||
else if (toupper(input[0]) == 'H')
|
||||
{
|
||||
iseasy = false;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Invalid selection, please try again." << endl;
|
||||
}
|
||||
}
|
||||
while (true)
|
||||
{
|
||||
displayBoard();
|
||||
if (stalemate())
|
||||
{
|
||||
cout << "Stale mate!" << endl;
|
||||
system("pause");
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
setisWin(winner());
|
||||
if(getisWin())
|
||||
{
|
||||
cout << "Sorry, the computer wins this round." << endl;
|
||||
system("pause");
|
||||
break;
|
||||
}
|
||||
getInput();
|
||||
}
|
||||
displayBoard();
|
||||
if (stalemate())
|
||||
{
|
||||
cout << "Stale mate!" << endl;
|
||||
system("pause");
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
setisWin(winner());
|
||||
if(getisWin())
|
||||
{
|
||||
cout << "Congratulations! A Winner is You!" << endl;
|
||||
system("pause");
|
||||
break;
|
||||
}
|
||||
think(iseasy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Tic_Tac_Toe::stalemate()
|
||||
{
|
||||
for (int i = 0; i < 9; i++)
|
||||
{
|
||||
if (board[i] == ' ')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Tic_Tac_Toe::think(bool easy)
|
||||
{
|
||||
if (easy)
|
||||
{
|
||||
for (int i = 0; i <= 8; i++)
|
||||
{
|
||||
if (board[easyMoves[i]] == ' ')
|
||||
{
|
||||
board[easyMoves[i]] = getcomputer();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// offensive think -- special cases || win in two
|
||||
if (board[0] == getcomputer() && board[2] == getcomputer() && board[1] == ' ' )
|
||||
{
|
||||
board[1] = getcomputer();
|
||||
return;
|
||||
} else if (board[3] == getcomputer() && board[5] == getcomputer() && board[4] == ' ' )
|
||||
{
|
||||
board[4] = getcomputer();
|
||||
return;
|
||||
} else if (board[6] == getcomputer() && board[8] == getcomputer() && board[7] == ' ' )
|
||||
{
|
||||
board[7] = getcomputer();
|
||||
return;
|
||||
} else if (board[0] == getcomputer() && board[6] == getcomputer() && board[3] == ' ' )
|
||||
{
|
||||
board[3] = getcomputer();
|
||||
return;
|
||||
} else if (board[1] == getcomputer() && board[7] == getcomputer() && board[4] == ' ' )
|
||||
{
|
||||
board[4] = getcomputer();
|
||||
return;
|
||||
} else if (board[2] == getcomputer() && board[8] == getcomputer() && board[5] == ' ' )
|
||||
{
|
||||
board[5] = getcomputer();
|
||||
return;
|
||||
} else if (board[0] == getcomputer() && board[8] == getcomputer() && board[4] == ' ' )
|
||||
{
|
||||
board[4] = getcomputer();
|
||||
return;
|
||||
} else if (board[2] == getcomputer() && board[6] == getcomputer() && board[4] == ' ' )
|
||||
{
|
||||
board[4] = getcomputer();
|
||||
return;
|
||||
}
|
||||
// offensive think -- main think || win in one
|
||||
for (int i = 0; i <= 8; i++)
|
||||
{
|
||||
switch(i)
|
||||
{
|
||||
case 0:
|
||||
if (board[0] == getcomputer() && board[1] == getcomputer() && board[2] == ' ') //across
|
||||
{
|
||||
board[2] = getcomputer();
|
||||
return;
|
||||
}
|
||||
else if (board[0] == getcomputer() && board[4] == getcomputer() && board[8] == ' ') //diag
|
||||
{
|
||||
board[8] = getcomputer();
|
||||
return;
|
||||
}
|
||||
else if (board[0] == getcomputer() && board[3] == getcomputer() && board[6] == ' ') //down
|
||||
{
|
||||
board[6] = getcomputer();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (board[1] == getcomputer() && board[4] == getcomputer() && board[7] == ' ') //down
|
||||
{
|
||||
board[7] = getcomputer();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (board[2] == getcomputer() && board[4] == getcomputer() && board[6] == ' ') //diag
|
||||
{
|
||||
board[6] = getcomputer();
|
||||
return;
|
||||
}
|
||||
else if (board[2] == getcomputer() && board[5] == getcomputer() && board[8] == ' ') // down
|
||||
{
|
||||
board[8] = getcomputer();
|
||||
return;
|
||||
}
|
||||
else if (board[2] == getcomputer() && board[1] == getcomputer() && board[0] == ' ') //across
|
||||
{
|
||||
board[0] = getcomputer();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (board[3] == getcomputer() && board[4] == getcomputer() && board[5] == ' ') // across
|
||||
{
|
||||
board[5] = getcomputer();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
// this is the middle square. doesn't really matter.
|
||||
// case is checked virtually everywhere else
|
||||
break;
|
||||
case 5:
|
||||
if (board[5] == getcomputer() && board[4] == getcomputer() && board[3] == ' ')
|
||||
{
|
||||
board[3] = getcomputer();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
if (board[6] == getcomputer() && board[7] == getcomputer() && board[8] == ' ') //across
|
||||
{
|
||||
board[8] = getcomputer();
|
||||
return;
|
||||
}
|
||||
else if (board[6] == getcomputer() && board[4] == getcomputer() && board[2] == ' ') //diag
|
||||
{
|
||||
board[8] = getcomputer();
|
||||
return;
|
||||
}
|
||||
else if (board[6] == getcomputer() && board[3] == getcomputer() && board[0] == ' ') //down
|
||||
{
|
||||
board[0] = getcomputer();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
if (board[7] == getcomputer() && board[4] == getcomputer() && board[1] == ' ') //down
|
||||
{
|
||||
board[1] = getcomputer();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 8:
|
||||
if (board[8] == getcomputer() && board[4] == getcomputer() && board[0] == ' ') //diag
|
||||
{
|
||||
board[0] = getcomputer();
|
||||
return;
|
||||
}
|
||||
else if (board[8] == getcomputer() && board[5] == getcomputer() && board[2] == ' ') // down
|
||||
{
|
||||
board[2] = getcomputer();
|
||||
return;
|
||||
}
|
||||
else if (board[8] == getcomputer() && board[7] == getcomputer() && board[6] == ' ') //across
|
||||
{
|
||||
board[6] = getcomputer();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// defensive think -- special cases || block in one
|
||||
if (board[0] == gethuman() && board[2] == gethuman() && board[1] == ' ' )
|
||||
{
|
||||
board[1] = getcomputer();
|
||||
return;
|
||||
} else if (board[3] == gethuman() && board[5] == gethuman() && board[4] == ' ' )
|
||||
{
|
||||
board[4] = getcomputer();
|
||||
return;
|
||||
} else if (board[6] == gethuman() && board[8] == gethuman() && board[7] == ' ' )
|
||||
{
|
||||
board[7] = getcomputer();
|
||||
return;
|
||||
} else if (board[0] == gethuman() && board[6] == gethuman() && board[3] == ' ' )
|
||||
{
|
||||
board[3] = getcomputer();
|
||||
return;
|
||||
} else if (board[1] == gethuman() && board[7] == gethuman() && board[4] == ' ' )
|
||||
{
|
||||
board[4] = getcomputer();
|
||||
return;
|
||||
} else if (board[2] == gethuman() && board[8] == gethuman() && board[5] == ' ' )
|
||||
{
|
||||
board[5] = getcomputer();
|
||||
return;
|
||||
} else if (board[0] == gethuman() && board[8] == gethuman() && board[4] == ' ' )
|
||||
{
|
||||
board[4] = getcomputer();
|
||||
return;
|
||||
} else if (board[2] == gethuman() && board[6] == gethuman() && board[4] == ' ' )
|
||||
{
|
||||
board[4] = getcomputer();
|
||||
return;
|
||||
}
|
||||
//main defensive think || blocks
|
||||
for (int i = 0; i <= 8; i++)
|
||||
{
|
||||
switch(i)
|
||||
{
|
||||
case 0:
|
||||
if (board[0] == gethuman() && board[1] == gethuman() && board[2] == ' ') //across
|
||||
{
|
||||
board[2] = getcomputer();
|
||||
return;
|
||||
}
|
||||
else if (board[0] == gethuman() && board[4] == gethuman() && board[8] == ' ') //diag
|
||||
{
|
||||
board[8] = getcomputer();
|
||||
return;
|
||||
}
|
||||
else if (board[0] == gethuman() && board[3] == gethuman() && board[6] == ' ') //down
|
||||
{
|
||||
board[6] = getcomputer();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (board[1] == gethuman() && board[4] == gethuman() && board[7] == ' ') //down
|
||||
{
|
||||
board[7] = getcomputer();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (board[2] == gethuman() && board[4] == gethuman() && board[6] == ' ') //diag
|
||||
{
|
||||
board[6] = getcomputer();
|
||||
return;
|
||||
}
|
||||
else if (board[2] == gethuman() && board[5] == gethuman() && board[8] == ' ') // down
|
||||
{
|
||||
board[8] = getcomputer();
|
||||
return;
|
||||
}
|
||||
else if (board[2] == gethuman() && board[1] == gethuman() && board[0] == ' ') //across
|
||||
{
|
||||
board[0] = getcomputer();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (board[3] == gethuman() && board[4] == gethuman() && board[5] == ' ') // across
|
||||
{
|
||||
board[5] = getcomputer();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
// this is the middle square. doesn't really matter.
|
||||
// case is checked virtually everywhere else
|
||||
break;
|
||||
case 5:
|
||||
if (board[5] == gethuman() && board[4] == gethuman() && board[3] == ' ')
|
||||
{
|
||||
board[3] = getcomputer();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
if (board[6] == gethuman() && board[7] == gethuman() && board[8] == ' ') //across
|
||||
{
|
||||
board[8] = getcomputer();
|
||||
return;
|
||||
}
|
||||
else if (board[6] == gethuman() && board[4] == gethuman() && board[2] == ' ') //diag
|
||||
{
|
||||
board[8] = getcomputer();
|
||||
return;
|
||||
}
|
||||
else if (board[6] == gethuman() && board[3] == gethuman() && board[0] == ' ') //down
|
||||
{
|
||||
board[0] = getcomputer();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
if (board[7] == gethuman() && board[4] == gethuman() && board[1] == ' ') //down
|
||||
{
|
||||
board[1] = getcomputer();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 8:
|
||||
if (board[8] == gethuman() && board[4] == gethuman() && board[0] == ' ') //diag
|
||||
{
|
||||
board[0] = getcomputer();
|
||||
return;
|
||||
}
|
||||
else if (board[8] == gethuman() && board[5] == gethuman() && board[2] == ' ') // down
|
||||
{
|
||||
board[2] = getcomputer();
|
||||
return;
|
||||
}
|
||||
else if (board[8] == gethuman() && board[7] == gethuman() && board[6] == ' ') //across
|
||||
{
|
||||
board[6] = getcomputer();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i <= 8; i++)
|
||||
{
|
||||
if (board[easyMoves[i]] == ' ')
|
||||
{
|
||||
board[easyMoves[i]] = getcomputer();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Tic_Tac_Toe::getInput()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
cout << "Coordinates" << endl << ">:";
|
||||
string input;
|
||||
cin >> input;
|
||||
bool isBad = false;
|
||||
if (isalpha(input[0]) && isdigit(input[1]))
|
||||
{
|
||||
if ((toupper(input[0]) != 'A' && toupper(input[0]) != 'B' && toupper(input[0]) != 'C') ||
|
||||
(input[1] != '1' && input[1] != '2' && input[1] != '3'))
|
||||
{
|
||||
cout << "Error: Bad coordinates" << endl;
|
||||
}
|
||||
switch (toupper(input[0]))
|
||||
{
|
||||
case 'A':
|
||||
switch (input[1])
|
||||
{
|
||||
case '1':
|
||||
if (board[0] == ' ')
|
||||
{
|
||||
board[0] = gethuman();
|
||||
}
|
||||
else
|
||||
{
|
||||
isBad = true;
|
||||
}
|
||||
break;
|
||||
case '2':
|
||||
if (board[1] == ' ')
|
||||
{
|
||||
board[1] = gethuman();
|
||||
}
|
||||
else
|
||||
{
|
||||
isBad = true;
|
||||
}
|
||||
break;
|
||||
case '3':
|
||||
if (board[2] == ' ')
|
||||
{
|
||||
board[2] = gethuman();
|
||||
}
|
||||
else
|
||||
{
|
||||
isBad = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'B':
|
||||
switch (input[1])
|
||||
{
|
||||
case '1':
|
||||
if (board[3] == ' ')
|
||||
{
|
||||
board[3] = gethuman();
|
||||
}
|
||||
else
|
||||
{
|
||||
isBad = true;
|
||||
}
|
||||
break;
|
||||
case '2':
|
||||
if (board[4] == ' ')
|
||||
{
|
||||
board[4] = gethuman();
|
||||
}
|
||||
else
|
||||
{
|
||||
isBad = true;
|
||||
}
|
||||
break;
|
||||
case '3':
|
||||
if (board[5] == ' ')
|
||||
{
|
||||
board[5] = gethuman();
|
||||
}
|
||||
else
|
||||
{
|
||||
isBad = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'C':
|
||||
switch (input[1])
|
||||
{
|
||||
case '1':
|
||||
if (board[6] == ' ')
|
||||
{
|
||||
board[6] = gethuman();
|
||||
}
|
||||
else
|
||||
{
|
||||
isBad = true;
|
||||
}
|
||||
break;
|
||||
case '2':
|
||||
if (board[7] == ' ')
|
||||
{
|
||||
board[7] = gethuman();
|
||||
}
|
||||
else
|
||||
{
|
||||
isBad = true;
|
||||
}
|
||||
break;
|
||||
case '3':
|
||||
if (board[8] == ' ')
|
||||
{
|
||||
board[8] = gethuman();
|
||||
}
|
||||
else
|
||||
{
|
||||
isBad = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (isBad)
|
||||
{
|
||||
cout << "Error: bad coordinates" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Input accepted!" << endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Error: bad coordinates" << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Tic_Tac_Toe::displayBoard()
|
||||
{
|
||||
cout << " ____________" << endl;
|
||||
cout << "A | " << board[0] << " | " << board[1] << " | " << board[2] << " |" << endl;
|
||||
cout << " ------------" << endl;
|
||||
cout << "B | " << board[3] << " | " << board[4] << " | " << board[5] << " |" << endl;
|
||||
cout << " ------------" << endl;
|
||||
cout << "C | " << board[6] << " | " << board[7] << " | " << board[8] << " |" << endl;
|
||||
cout << " ____________" << endl;
|
||||
cout << " 1 2 3 " << endl << endl;
|
||||
}
|
||||
|
||||
void Tic_Tac_Toe::isTie()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Tic_Tac_Toe::setisWin(bool isWin)
|
||||
{
|
||||
this->isWin = isWin;
|
||||
}
|
||||
bool Tic_Tac_Toe::getisWin()
|
||||
{
|
||||
return isWin;
|
||||
}
|
||||
|
||||
void Tic_Tac_Toe::sethuman(char human)
|
||||
{
|
||||
this->human = human;
|
||||
}
|
||||
char Tic_Tac_Toe::gethuman()
|
||||
{
|
||||
return human;
|
||||
}
|
||||
|
||||
void Tic_Tac_Toe::setcomputer(char computer)
|
||||
{
|
||||
this->computer = computer;
|
||||
}
|
||||
char Tic_Tac_Toe::getcomputer()
|
||||
{
|
||||
return computer;
|
||||
}
|
||||
|
||||
//void Tic_Tac_Toe::setboard(char* board)
|
||||
//{
|
||||
// this->board = *board;
|
||||
//}
|
||||
//char* Tic_Tac_Toe::getboard()
|
||||
//{
|
||||
// return board;
|
||||
//}
|
||||
|
||||
void Tic_Tac_Toe::setposition(int position)
|
||||
{
|
||||
this->position = position;
|
||||
}
|
||||
int Tic_Tac_Toe::getposition()
|
||||
{
|
||||
return position;
|
||||
}
|
||||
|
||||
//void Tic_Tac_Toe::seteasyMoves(char* moves)
|
||||
//{
|
||||
// this->easyMoves = *moves;
|
||||
//}
|
||||
//char* Tic_Tac_Toe::geteasyMoves()
|
||||
//{
|
||||
// return easyMoves;
|
||||
//}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <Windows.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#ifndef TIC_TAC_TOE_H
|
||||
#define TIC_TAC_TOE_H
|
||||
|
||||
class Tic_Tac_Toe {
|
||||
private:
|
||||
bool isWin;
|
||||
char human;
|
||||
char computer;
|
||||
char board[9];
|
||||
int position;
|
||||
int easyMoves[9];
|
||||
bool instructionsdisplayed;
|
||||
|
||||
public:
|
||||
Tic_Tac_Toe();
|
||||
|
||||
bool winner();
|
||||
bool stalemate();
|
||||
|
||||
void displayInstructions();
|
||||
void run();
|
||||
void displayBoard();
|
||||
void isTie();
|
||||
|
||||
void think(bool mode);
|
||||
void getInput();
|
||||
void initeasymoves();
|
||||
void initboard();
|
||||
|
||||
void setisWin(bool isWin);
|
||||
bool getisWin();
|
||||
|
||||
void sethuman(char human);
|
||||
char gethuman();
|
||||
|
||||
void setcomputer(char computer);
|
||||
char getcomputer();
|
||||
|
||||
void setboard(char* board);
|
||||
char* getboard();
|
||||
|
||||
void setposition(int position);
|
||||
int getposition();
|
||||
|
||||
void seteasyMoves(char* moves);
|
||||
char* geteasyMoves();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,19 @@
|
||||
#include "Tic_Tac_Toe.h"
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
Tic_Tac_Toe ttt;
|
||||
while (true)
|
||||
{
|
||||
ttt.run();
|
||||
cout << endl << "Would you like to play again?" << endl << "[Y/n]:";
|
||||
string input;
|
||||
cin >> input;
|
||||
if (toupper(input[0]) != 'Y')
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user