diff --git a/Lab03_1/Debug/Lab03_1.exe b/Lab03_1/Debug/Lab03_1.exe new file mode 100644 index 0000000..1ae0094 Binary files /dev/null and b/Lab03_1/Debug/Lab03_1.exe differ diff --git a/Lab03_1/Debug/Lab03_1.ilk b/Lab03_1/Debug/Lab03_1.ilk new file mode 100644 index 0000000..fb32306 Binary files /dev/null and b/Lab03_1/Debug/Lab03_1.ilk differ diff --git a/Lab03_1/Debug/Lab03_1.pdb b/Lab03_1/Debug/Lab03_1.pdb new file mode 100644 index 0000000..e303c57 Binary files /dev/null and b/Lab03_1/Debug/Lab03_1.pdb differ diff --git a/Lab03_1/Lab03_1.sdf b/Lab03_1/Lab03_1.sdf new file mode 100644 index 0000000..f6459c2 Binary files /dev/null and b/Lab03_1/Lab03_1.sdf differ diff --git a/Lab03_1/Lab03_1.sln b/Lab03_1/Lab03_1.sln new file mode 100644 index 0000000..b8bf551 --- /dev/null +++ b/Lab03_1/Lab03_1.sln @@ -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 diff --git a/Lab03_1/Lab03_1.v12.suo b/Lab03_1/Lab03_1.v12.suo new file mode 100644 index 0000000..ab75ed1 Binary files /dev/null and b/Lab03_1/Lab03_1.v12.suo differ diff --git a/Lab03_1/Lab03_1/Debug/Lab03_1.log b/Lab03_1/Lab03_1/Debug/Lab03_1.log new file mode 100644 index 0000000..e99a654 --- /dev/null +++ b/Lab03_1/Lab03_1/Debug/Lab03_1.log @@ -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 diff --git a/Lab03_1/Lab03_1/Debug/Lab03_1.obj b/Lab03_1/Lab03_1/Debug/Lab03_1.obj new file mode 100644 index 0000000..e61d448 Binary files /dev/null and b/Lab03_1/Lab03_1/Debug/Lab03_1.obj differ diff --git a/Lab03_1/Lab03_1/Debug/Lab03_1.pch b/Lab03_1/Lab03_1/Debug/Lab03_1.pch new file mode 100644 index 0000000..26bef2c Binary files /dev/null and b/Lab03_1/Lab03_1/Debug/Lab03_1.pch differ diff --git a/Lab03_1/Lab03_1/Debug/Lab03_1.tlog/CL.read.1.tlog b/Lab03_1/Lab03_1/Debug/Lab03_1.tlog/CL.read.1.tlog new file mode 100644 index 0000000..454fe96 Binary files /dev/null and b/Lab03_1/Lab03_1/Debug/Lab03_1.tlog/CL.read.1.tlog differ diff --git a/Lab03_1/Lab03_1/Debug/Lab03_1.tlog/CL.write.1.tlog b/Lab03_1/Lab03_1/Debug/Lab03_1.tlog/CL.write.1.tlog new file mode 100644 index 0000000..caf5761 Binary files /dev/null and b/Lab03_1/Lab03_1/Debug/Lab03_1.tlog/CL.write.1.tlog differ diff --git a/Lab03_1/Lab03_1/Debug/Lab03_1.tlog/Lab03_1.lastbuildstate b/Lab03_1/Lab03_1/Debug/Lab03_1.tlog/Lab03_1.lastbuildstate new file mode 100644 index 0000000..1ed828e --- /dev/null +++ b/Lab03_1/Lab03_1/Debug/Lab03_1.tlog/Lab03_1.lastbuildstate @@ -0,0 +1,2 @@ +#TargetFrameworkVersion=v4.0:PlatformToolSet=v120:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit +Debug|Win32|C:\Users\IEUser\Desktop\Cpp_Lab_03\Lab03_1\| diff --git a/Lab03_1/Lab03_1/Debug/Lab03_1.tlog/cl.command.1.tlog b/Lab03_1/Lab03_1/Debug/Lab03_1.tlog/cl.command.1.tlog new file mode 100644 index 0000000..ae83604 Binary files /dev/null and b/Lab03_1/Lab03_1/Debug/Lab03_1.tlog/cl.command.1.tlog differ diff --git a/Lab03_1/Lab03_1/Debug/Lab03_1.tlog/link.command.1.tlog b/Lab03_1/Lab03_1/Debug/Lab03_1.tlog/link.command.1.tlog new file mode 100644 index 0000000..13809e2 Binary files /dev/null and b/Lab03_1/Lab03_1/Debug/Lab03_1.tlog/link.command.1.tlog differ diff --git a/Lab03_1/Lab03_1/Debug/Lab03_1.tlog/link.read.1.tlog b/Lab03_1/Lab03_1/Debug/Lab03_1.tlog/link.read.1.tlog new file mode 100644 index 0000000..319f0d1 Binary files /dev/null and b/Lab03_1/Lab03_1/Debug/Lab03_1.tlog/link.read.1.tlog differ diff --git a/Lab03_1/Lab03_1/Debug/Lab03_1.tlog/link.write.1.tlog b/Lab03_1/Lab03_1/Debug/Lab03_1.tlog/link.write.1.tlog new file mode 100644 index 0000000..dade29a Binary files /dev/null and b/Lab03_1/Lab03_1/Debug/Lab03_1.tlog/link.write.1.tlog differ diff --git a/Lab03_1/Lab03_1/Debug/stdafx.obj b/Lab03_1/Lab03_1/Debug/stdafx.obj new file mode 100644 index 0000000..2d714f1 Binary files /dev/null and b/Lab03_1/Lab03_1/Debug/stdafx.obj differ diff --git a/Lab03_1/Lab03_1/Debug/vc120.idb b/Lab03_1/Lab03_1/Debug/vc120.idb new file mode 100644 index 0000000..9925158 Binary files /dev/null and b/Lab03_1/Lab03_1/Debug/vc120.idb differ diff --git a/Lab03_1/Lab03_1/Debug/vc120.pdb b/Lab03_1/Lab03_1/Debug/vc120.pdb new file mode 100644 index 0000000..4b503f2 Binary files /dev/null and b/Lab03_1/Lab03_1/Debug/vc120.pdb differ diff --git a/Lab03_1/Lab03_1/Lab03_1.cpp b/Lab03_1/Lab03_1/Lab03_1.cpp new file mode 100644 index 0000000..3272bad --- /dev/null +++ b/Lab03_1/Lab03_1/Lab03_1.cpp @@ -0,0 +1,221 @@ +// Lab3_1.cpp : tic tack toe game. +// Matt Gilmore & Michael Coyne + +#include "stdafx.h" +#include +#include +#include + +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 << ""; + 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; + } + } + + + +} \ No newline at end of file diff --git a/Lab03_1/Lab03_1/Lab03_1.vcxproj b/Lab03_1/Lab03_1/Lab03_1.vcxproj new file mode 100644 index 0000000..b72ead5 --- /dev/null +++ b/Lab03_1/Lab03_1/Lab03_1.vcxproj @@ -0,0 +1,95 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {457C0730-59BF-4140-AB2B-D8E26DC17AF1} + Win32Proj + Lab03_1 + + + + Application + true + v120 + Unicode + + + Application + false + v120 + true + Unicode + + + + + + + + + + + + + true + + + false + + + + Use + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + Create + Create + + + + + + \ No newline at end of file diff --git a/Lab03_1/Lab03_1/Lab03_1.vcxproj.filters b/Lab03_1/Lab03_1/Lab03_1.vcxproj.filters new file mode 100644 index 0000000..7fa4856 --- /dev/null +++ b/Lab03_1/Lab03_1/Lab03_1.vcxproj.filters @@ -0,0 +1,36 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + + + + Header Files + + + Header Files + + + + + Source Files + + + Source Files + + + \ No newline at end of file diff --git a/Lab03_1/Lab03_1/ReadMe.txt b/Lab03_1/Lab03_1/ReadMe.txt new file mode 100644 index 0000000..7a52c6e --- /dev/null +++ b/Lab03_1/Lab03_1/ReadMe.txt @@ -0,0 +1,40 @@ +======================================================================== + CONSOLE APPLICATION : Lab03_1 Project Overview +======================================================================== + +AppWizard has created this Lab03_1 application for you. + +This file contains a summary of what you will find in each of the files that +make up your Lab03_1 application. + + +Lab03_1.vcxproj + This is the main project file for VC++ projects generated using an Application Wizard. + It contains information about the version of Visual C++ that generated the file, and + information about the platforms, configurations, and project features selected with the + Application Wizard. + +Lab03_1.vcxproj.filters + This is the filters file for VC++ projects generated using an Application Wizard. + It contains information about the association between the files in your project + and the filters. This association is used in the IDE to show grouping of files with + similar extensions under a specific node (for e.g. ".cpp" files are associated with the + "Source Files" filter). + +Lab03_1.cpp + This is the main application source file. + +///////////////////////////////////////////////////////////////////////////// +Other standard files: + +StdAfx.h, StdAfx.cpp + These files are used to build a precompiled header (PCH) file + named Lab03_1.pch and a precompiled types file named StdAfx.obj. + +///////////////////////////////////////////////////////////////////////////// +Other notes: + +AppWizard uses "TODO:" comments to indicate parts of the source code you +should add to or customize. + +///////////////////////////////////////////////////////////////////////////// diff --git a/Lab03_1/Lab03_1/stdafx.cpp b/Lab03_1/Lab03_1/stdafx.cpp new file mode 100644 index 0000000..fb5927f --- /dev/null +++ b/Lab03_1/Lab03_1/stdafx.cpp @@ -0,0 +1,8 @@ +// stdafx.cpp : source file that includes just the standard includes +// Lab03_1.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + +// TODO: reference any additional headers you need in STDAFX.H +// and not in this file diff --git a/Lab03_1/Lab03_1/stdafx.h b/Lab03_1/Lab03_1/stdafx.h new file mode 100644 index 0000000..b005a83 --- /dev/null +++ b/Lab03_1/Lab03_1/stdafx.h @@ -0,0 +1,15 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + +#include "targetver.h" + +#include +#include + + + +// TODO: reference additional headers your program requires here diff --git a/Lab03_1/Lab03_1/targetver.h b/Lab03_1/Lab03_1/targetver.h new file mode 100644 index 0000000..87c0086 --- /dev/null +++ b/Lab03_1/Lab03_1/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include diff --git a/Lab03_1/ipch/lab03_1-3d86940d/lab03_1-309799ce.ipch b/Lab03_1/ipch/lab03_1-3d86940d/lab03_1-309799ce.ipch new file mode 100644 index 0000000..6c774bf Binary files /dev/null and b/Lab03_1/ipch/lab03_1-3d86940d/lab03_1-309799ce.ipch differ