-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit. Computer can calculate best move (depth set to 3), bu…
…t only from set-up positions.
- Loading branch information
Showing
8 changed files
with
418 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{C71875CC-2ED7-46AB-B115-F310E08E5263}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<RootNamespace>MerelsRules.ConsoleApp</RootNamespace> | ||
<AssemblyName>MerelsRules.ConsoleApp</AssemblyName> | ||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\MerelsRules\MerelsRules.csproj"> | ||
<Project>{5667b2df-d76c-4f31-809e-569597600193}</Project> | ||
<Name>MerelsRules</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using System; | ||
|
||
namespace MerelsRules.ConsoleApp | ||
{ | ||
public class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
gm = GameManager.GetInstance(); | ||
//for(int i = 0; i < 6; i++) | ||
//{ | ||
// Console.WriteLine(PrintBoard()); | ||
// GameManager.Piece p = i % 2 == 0 ? GameManager.Piece.O : GameManager.Piece.X; | ||
// Console.WriteLine("Where do you want to place a " + p.ToString() + "? "); | ||
// int loc = int.Parse(Console.ReadLine()); | ||
// gm.Board[loc] = p; | ||
// gm.PieceLocations[((i % 2) * 3) + (i / 2)] = loc; | ||
//} | ||
int[] locations = new[] { 0, 1, 2, 3, 7, 8 }; | ||
for (int i = 0; i < 6; i++) | ||
{ | ||
GameManager.Piece p = i % 2 == 0 ? GameManager.Piece.O : GameManager.Piece.X; | ||
int loc = locations[i]; | ||
gm.Board[loc] = p; | ||
gm.PieceLocations[((i % 2) * 3) + (i / 2)] = loc; | ||
} | ||
|
||
Console.WriteLine("\nBeginning Game\n"); | ||
|
||
while(true) | ||
{ | ||
Console.WriteLine(PrintBoard()); | ||
Console.WriteLine("What piece do you want to move (0-9)? "); | ||
int initial = int.Parse(Console.ReadLine()); | ||
Console.WriteLine("Where do you want to move the piece (0-9)? "); | ||
int destination = int.Parse(Console.ReadLine()); | ||
Console.WriteLine(); | ||
//player | ||
gm.MakeMove(initial, destination); | ||
Console.WriteLine("Your move:"); | ||
Console.WriteLine(PrintBoard() + "\n"); | ||
if (gm.CheckGameEnd()) | ||
{ | ||
Console.WriteLine("You won!"); | ||
break; | ||
} | ||
//computer | ||
Tuple<int, int> compMove = gm.MakeMove(initial, destination); | ||
Console.WriteLine("The computer moved the piece on " + compMove.Item1 + " to " + compMove.Item2); | ||
Console.WriteLine(PrintBoard()); | ||
if (gm.CheckGameEnd()) | ||
{ | ||
Console.WriteLine("Computer won."); | ||
break; | ||
} | ||
} | ||
|
||
Console.ReadLine(); | ||
} | ||
|
||
private static GameManager gm; | ||
|
||
|
||
private static string PrintBoard() | ||
{ | ||
string result = ""; | ||
result += PrintRow(SubArray(gm.Board, 0, 3)) + "\n"; | ||
result += "|\\|/|" + "\n"; | ||
result += PrintRow(SubArray(gm.Board, 3, 3)) + "\n"; | ||
result += "|/|\\|" + "\n"; | ||
result += PrintRow(SubArray(gm.Board, 6, 3)); | ||
return result; | ||
} | ||
|
||
private static string PrintRow(GameManager.Piece[] row) | ||
{ | ||
string result = (row[0] == GameManager.Piece.Empty ? " " : row[0].ToString()); | ||
for(int i = 1; i < row.Length; i++) | ||
{ | ||
result += "-" + (row[i]==GameManager.Piece.Empty?" ":row[i].ToString()); | ||
} | ||
return result; | ||
} | ||
|
||
private static T[] SubArray<T>(T[] data, int index, int length) | ||
{ | ||
T[] result = new T[length]; | ||
Array.Copy(data, index, result, 0, length); | ||
return result; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("MerelsRules.ConsoleApp")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("MerelsRules.ConsoleApp")] | ||
[assembly: AssemblyCopyright("Copyright © 2018")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("c71875cc-2ed7-46ab-b115-f310e08e5263")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.