Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Lab03_1/Debug/Lab03_1.exe
Binary file not shown.
Binary file added Lab03_1/Debug/Lab03_1.ilk
Binary file not shown.
Binary file added Lab03_1/Debug/Lab03_1.pdb
Binary file not shown.
Binary file added Lab03_1/Lab03_1.sdf
Binary file not shown.
22 changes: 22 additions & 0 deletions Lab03_1/Lab03_1.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30501.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Lab03_1", "Lab03_1\Lab03_1.vcxproj", "{457C0730-59BF-4140-AB2B-D8E26DC17AF1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{457C0730-59BF-4140-AB2B-D8E26DC17AF1}.Debug|Win32.ActiveCfg = Debug|Win32
{457C0730-59BF-4140-AB2B-D8E26DC17AF1}.Debug|Win32.Build.0 = Debug|Win32
{457C0730-59BF-4140-AB2B-D8E26DC17AF1}.Release|Win32.ActiveCfg = Release|Win32
{457C0730-59BF-4140-AB2B-D8E26DC17AF1}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Binary file added Lab03_1/Lab03_1.v12.suo
Binary file not shown.
14 changes: 14 additions & 0 deletions Lab03_1/Lab03_1/Debug/Lab03_1.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Build started 1/28/2015 6:06:12 AM.
Project "C:\Users\IEUser\Desktop\Cpp_Lab_03\Lab03_1\Lab03_1\Lab03_1.vcxproj" on node 2 (Build target(s)).
ClCompile:
C:\Program Files\Microsoft Visual Studio 12.0\VC\bin\CL.exe /c /ZI /nologo /W3 /WX- /sdl /Od /Oy- /D WIN32 /D _DEBUG /D _CONSOLE /D _LIB /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Yu"stdafx.h" /Fp"Debug\Lab03_1.pch" /Fo"Debug\\" /Fd"Debug\vc120.pdb" /Gd /TP /analyze- /errorReport:prompt Lab03_1.cpp
Lab03_1.cpp
Link:
C:\Program Files\Microsoft Visual Studio 12.0\VC\bin\link.exe /ERRORREPORT:PROMPT /OUT:"C:\Users\IEUser\Desktop\Cpp_Lab_03\Lab03_1\Debug\Lab03_1.exe" /INCREMENTAL /NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"C:\Users\IEUser\Desktop\Cpp_Lab_03\Lab03_1\Debug\Lab03_1.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:\Users\IEUser\Desktop\Cpp_Lab_03\Lab03_1\Debug\Lab03_1.lib" /MACHINE:X86 Debug\Lab03_1.obj
Debug\stdafx.obj
Lab03_1.vcxproj -> C:\Users\IEUser\Desktop\Cpp_Lab_03\Lab03_1\Debug\Lab03_1.exe
Done Building Project "C:\Users\IEUser\Desktop\Cpp_Lab_03\Lab03_1\Lab03_1\Lab03_1.vcxproj" (Build target(s)).

Build succeeded.

Time Elapsed 00:00:00.27
Binary file added Lab03_1/Lab03_1/Debug/Lab03_1.obj
Binary file not shown.
Binary file added Lab03_1/Lab03_1/Debug/Lab03_1.pch
Binary file not shown.
Binary file added Lab03_1/Lab03_1/Debug/Lab03_1.tlog/CL.read.1.tlog
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions Lab03_1/Lab03_1/Debug/Lab03_1.tlog/Lab03_1.lastbuildstate
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#TargetFrameworkVersion=v4.0:PlatformToolSet=v120:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit
Debug|Win32|C:\Users\IEUser\Desktop\Cpp_Lab_03\Lab03_1\|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added Lab03_1/Lab03_1/Debug/Lab03_1.tlog/link.write.1.tlog
Binary file not shown.
Binary file added Lab03_1/Lab03_1/Debug/stdafx.obj
Binary file not shown.
Binary file added Lab03_1/Lab03_1/Debug/vc120.idb
Binary file not shown.
Binary file added Lab03_1/Lab03_1/Debug/vc120.pdb
Binary file not shown.
221 changes: 221 additions & 0 deletions Lab03_1/Lab03_1/Lab03_1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
// Lab3_1.cpp : tic tack toe game.
// Matt Gilmore & Michael Coyne

#include "stdafx.h"
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;
char x = 'X';
char o = 'O';
char EMPTY = ' ';
string TIE = "TIE";
int NUM_SQUARES = 9;

void new_board(char[]);
void display_board(char[]);
int human_move(char[], char);
void display_instruct();
char ask_yes_no(string);
int ask_number(string, int, int);
char pieces();
char next_turn(char);
string winner(char[]);
int computer_move(char[], char, char);


int _tmain(int argc, _TCHAR* argv[])
{
char human = NULL;
char computer = NULL;
char turn = X;
char board[9];
int move = NULL;


display_instruct();
computer, human = pieces();
new_board();
display_board();

while (!winner())
{
if (turn == human)
{
move = human_move(human);
board[move] = human;
}
else
{
move = computer_move(board, computer, human);
board[move] = computer;
}
display_board(board);
turn = next_turn(turn);
the_winner = winner(board);
congrat_winner(the_winner, computer, human);
}
return 0;
}

void new_board(char board[])
{
for (int i = 0; i < NUM_SQUARES; i++)
{
board[i] = ' ';

}
}

void display_board(char board[])
{
cout << board[0] << "|" << board[1] << '|' << board[2] << endl;
cout << "-----";
cout << board[3] << "|" << board[4] << '|' << board[5] << endl;
cout << "-----";
cout << board[6] << "|" << board[7] << '|' << board[8] << endl;
}


int human_move(char board[], char human)
{
//Get human move.
int move = NULL;
while (board[move] != ' ');
{
move = ask_number("Where will you move? (0 - 8):", 0, NUM_SQUARES);
if (move != ' ')
{
cout << "\nThat square is already occupied, foolish human. Choose another.\n";
}
}
cout << "Fine...";
return move;
}

void display_instruct()
{
cout << "Welcome to the greatest intellectual challenge of all time : Tic - Tac - Toe." << endl;
cout << "This will be a showdown between your human brain and my silicon processor." << endl;
cout << "You will make your move known by entering a number, 0 - 8. The number " << endl;
cout << "will correspond to the board position as illustrated: " << endl << endl;

cout << "7 | 8 | 9" << endl;
cout << "---------" << endl;
cout << "4 | 5 | 6" << endl;
cout << "---------" << endl;
cout << "1 | 2 | 3" << endl << endl;
cout << "Prepare yourself, human. The ultimate battle is about to begin." << endl << endl;

cout << "<Press Enter to Begin>";
cin.ignore();

}

char ask_yes_no(string question)
{ //Ask a yes or no question and return respones
char response = NULL;

cout << question << endl;
cin >> response;

while (response == !'y' || response == !'n')
{//Ask question again
cout << question << endl;
cin >> response;
}
return response;
}

int ask_number(string question, int low, int high)
{//Check if user choice is on board
int response = 0;

cout << question << endl;
cin >> response;

if (response < 1 || response > 9)
{
cout << question << endl;
cin >> response;
}
return response;
}

char pieces()
{//Determine who goes first

char human = NULL;
char computer = NULL;

char go_first = ask_yes_no("Do you want to go first? (y/n): ");
if (go_first == 'y')
{
cout << "Then take the first move. You will need it.";

human = x;
computer = o;
}
else
{
cout << "Your bravery will be your undoing... I will go first.";

human = o;
computer = x;
}
return human, computer;
}

char next_turn(char turn)
{//Switch Turns
if (turn == x)
{
return o;
}
else
{
return x;
}
}

string winner(char board[])
{
int WAYS_TO_WIN[8][3] =
{ { 0, 1, 2 },
{ 3, 4, 5 },
{ 6, 7, 8 },
{ 0, 3, 6 },
{ 1, 4, 7 },
{ 2, 5, 8 },
{ 0, 4, 8 },
{ 2, 4, 6 }
};

for (int i = 0; i < 8; i++)
{
if (board[WAYS_TO_WIN[i][0]] == board[WAYS_TO_WIN[i][1]] == board[WAYS_TO_WIN[i][2]] != NULL)
{
char winner = board[i[0]];
return winner;
}
}

}


int computer_move(char board[], char computer, char humnan)
{
int BEST_MOVES[] = { 4, 0, 2, 6, 8, 1, 3, 5, 7 };

for (int i = 0; i < 9; i++)
{
if (board[i] == ' ')
{
board[i] = computer;
}
}



}
95 changes: 95 additions & 0 deletions Lab03_1/Lab03_1/Lab03_1.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.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>{457C0730-59BF-4140-AB2B-D8E26DC17AF1}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>Lab03_1</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</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>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>Use</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<Text Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Lab03_1.cpp" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
36 changes: 36 additions & 0 deletions Lab03_1/Lab03_1/Lab03_1.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?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;hh;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>
<Text Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="stdafx.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="targetver.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Lab03_1.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
Loading