Skip to content

Commit

Permalink
Demo console app for JAVA and C# - looks nice
Browse files Browse the repository at this point in the history
  • Loading branch information
mariuszgromada committed Apr 15, 2016
1 parent 8631464 commit eff1066
Show file tree
Hide file tree
Showing 97 changed files with 4,300 additions and 383 deletions.
7 changes: 6 additions & 1 deletion CURRENT/c-sharp/Janet-Sudoku.csproj
Expand Up @@ -6,7 +6,7 @@
<ProjectGuid>{C1A7A455-9810-45A2-8C2F-584572AE6A0D}</ProjectGuid>
<OutputType>Library</OutputType>
<NoStandardLibraries>false</NoStandardLibraries>
<AssemblyName>janet-sudoku</AssemblyName>
<AssemblyName>janetsudoku</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
Expand Down Expand Up @@ -54,6 +54,10 @@
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="src\org\mariuszgromada\math\janetsudoku\BoardCell.cs" />
<Compile Include="src\org\mariuszgromada\math\janetsudoku\demoapp\JanetConsole.cs" />
<Compile Include="src\org\mariuszgromada\math\janetsudoku\demoapp\JanetSudoku.cs" />
<Compile Include="src\org\mariuszgromada\math\janetsudoku\demoapp\Menu.cs" />
<Compile Include="src\org\mariuszgromada\math\janetsudoku\demoapp\MenuData.cs" />
<Compile Include="src\org\mariuszgromada\math\janetsudoku\ErrorCodes.cs" />
<Compile Include="src\org\mariuszgromada\math\janetsudoku\regtests\RegTests.cs" />
<Compile Include="src\org\mariuszgromada\math\janetsudoku\regtests\RegTestsApi.cs" />
Expand All @@ -73,6 +77,7 @@
<ItemGroup>
<None Include="mariuszgromada.org.pfx" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSHARP.Targets" />
<ProjectExtensions>
<VisualStudio AllowExistingFolder="true" />
Expand Down
6 changes: 6 additions & 0 deletions CURRENT/c-sharp/Janet-Sudoku.sln
Expand Up @@ -17,6 +17,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Run-Tests-Generator", "exe-
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Run-Tests-Store", "exe-lib-tests\Run-Tests-Store\Run-Tests-Store.csproj", "{A269C8E3-9CFB-41F7-B2D7-09FA3164F384}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Janet-Sudoku-Demop-App", "exe-lib-tests\Janet-Sudoku-Demop-App\Janet-Sudoku-Demop-App.csproj", "{F9FC5225-D42C-4F62-BA4C-BC2B38E9785F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -51,6 +53,10 @@ Global
{A269C8E3-9CFB-41F7-B2D7-09FA3164F384}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A269C8E3-9CFB-41F7-B2D7-09FA3164F384}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A269C8E3-9CFB-41F7-B2D7-09FA3164F384}.Release|Any CPU.Build.0 = Release|Any CPU
{F9FC5225-D42C-4F62-BA4C-BC2B38E9785F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F9FC5225-D42C-4F62-BA4C-BC2B38E9785F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F9FC5225-D42C-4F62-BA4C-BC2B38E9785F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F9FC5225-D42C-4F62-BA4C-BC2B38E9785F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" 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>{F9FC5225-D42C-4F62-BA4C-BC2B38E9785F}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>janetsudoku.demoapp</RootNamespace>
<AssemblyName>janetsudoku-demo</AssemblyName>
<TargetFrameworkVersion>v4.5.2</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>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>..\..\..\..\..\..\pfx-keys\mariuszgromada.org.pfx</AssemblyOriginatorKeyFile>
</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="JanetSudokuDemoApp.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="mariuszgromada.org.pfx" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Janet-Sudoku.csproj">
<Project>{c1a7a455-9810-45a2-8c2f-584572ae6a0d}</Project>
<Name>Janet-Sudoku</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
@@ -0,0 +1,9 @@
using org.mariuszgromada.math.janetsudoku.demoapp;

namespace janetsudoku.demoapp {
class JanetSudokuDemoApp {
static void Main(string[] args) {
JanetSudoku.Start();
}
}
}
@@ -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("Janet Sudoku - Demo App")]
[assembly: AssemblyDescription("Janet Sudoku - Demo Application")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("MariuszGromada.org")]
[assembly: AssemblyProduct("Janet Sudoku")]
[assembly: AssemblyCopyright("Copyright © 2016 Mariusz Gromada")]
[assembly: AssemblyTrademark("Janet Sudoku")]
[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("f9fc5225-d42c-4f62-ba4c-bc2b38e9785f")]

// 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")]
Expand Up @@ -8,7 +8,7 @@
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>janetsudoku.runtests</RootNamespace>
<AssemblyName>janet-sudoku-run-tests-api</AssemblyName>
<AssemblyName>janetsudoku-runtests-api</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
Expand Down
Expand Up @@ -8,7 +8,7 @@
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>janetsudoku.runtests</RootNamespace>
<AssemblyName>janet-sudoku-run-tests-generator</AssemblyName>
<AssemblyName>janetsudoku-runtests-generator</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
Expand Down
Expand Up @@ -8,7 +8,7 @@
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>janetsudoku.runtests</RootNamespace>
<AssemblyName>janet-sudoku-run-tests-solver</AssemblyName>
<AssemblyName>janetsudoku-runtests-solver</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
Expand Down
Expand Up @@ -8,7 +8,7 @@
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>janetsudoku.runtests</RootNamespace>
<AssemblyName>janet-sudoku-run-tests-store</AssemblyName>
<AssemblyName>janetsudoku-runtests-store</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
Expand Down
2 changes: 1 addition & 1 deletion CURRENT/c-sharp/exe-lib-tests/Run-Tests/Run-Tests.csproj
Expand Up @@ -8,7 +8,7 @@
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>janetsudoku.runtests</RootNamespace>
<AssemblyName>janet-sudoku-run-tests-all</AssemblyName>
<AssemblyName>janetsudoku-runtests-all</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
Expand Down
Expand Up @@ -8,7 +8,7 @@
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>janetsudoku.runtests</RootNamespace>
<AssemblyName>janet-sudoku-run-tutorial</AssemblyName>
<AssemblyName>janetsudoku-run-tutorial</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
Expand Down
Expand Up @@ -383,6 +383,74 @@ class Runner {
}
return sudokuBoard;
}
/**
* Loads Sudoku board from one string line ('0' and' '.' treated as empty cell).
* Any other char than '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.'
* is being filtered out.
*
* @param boardDefinition Board definition in one string line containing
* row after row.
* @return Loaded board if data is sufficient to fill 81 cells
* (including empty cells), otherwise null.
*/
public static int[,] loadBoardFromStringLine(String boardDefinition) {
int lastInex = BOARD_SIZE - 1;
if (boardDefinition == null) return null;
if (boardDefinition.Length < SudokuBoard.BOARD_CELLS_NUMBER) return null;
int[,] board = boardCopy(SudokuPuzzles.PUZZLE_EMPTY);
int cellNum = 0;
int i = 0;
int j = -1;
char[] line = boardDefinition.ToCharArray();
for (int k = 0; k < line.Length; k++) {
char c = line[k];
int d = -1;
if (c == '1') d = 1;
else if (c == '2') d = 2;
else if (c == '3') d = 3;
else if (c == '4') d = 4;
else if (c == '5') d = 5;
else if (c == '6') d = 6;
else if (c == '7') d = 7;
else if (c == '8') d = 8;
else if (c == '9') d = 9;
else if (c == '0') d = 0;
else if (c == '.') d = 0;
if ((d >= 0) && (cellNum < SudokuBoard.BOARD_CELLS_NUMBER)) {
j++;
cellNum++;
board[i, j] = d;
if (j == lastInex) {
i++;
j = -1;
}
}
}
if (cellNum == SudokuBoard.BOARD_CELLS_NUMBER) return board;
else return null;
}
/**
* Loads Sudoku board from variadic list of strings (each string as a
* one row)
*
* Format:
* Any character different than '1-9' and '.' is being removed.
* Any line starting with '#' is being removed.
* Any empty line is being removed.
* Any final line having less than 9 characters is being removed.
*
* If number of final lines is less then 9 then null is returned.
*
* Finally 9 starting characters for first 9 lines is the
* loaded board definition.
*
* @param boardDefinition Board definition (variadic list of strings).
* @return Array representing loaded Sudoku board,
* null - if problem occurred while loading.
*/
public static int[,] loadBoardFromStrings(params String[] boardDefinition) {
return loadBoard(boardDefinition);
}
/**
* Saves board to the text file.
*
Expand Down Expand Up @@ -1375,29 +1443,39 @@ class Runner {
*/
private static String convBoardToString(int[,] sudokuBoard, String headComment, String tailComment) {
String boardStr = "";
String oneLineDefDot = "";
String oneLineDefZero = "";
if (headComment != null)
if (headComment.Length > 0)
boardStr = boardStr + "# " + headComment + NEW_LINE_SEPARATOR + NEW_LINE_SEPARATOR;
boardStr = boardStr + "# " + headComment + NEW_LINE_SEPARATOR + NEW_LINE_SEPARATOR;
if (sudokuBoard == null) return "NULL sudoku board.";
boardStr = boardStr + "+-------+-------+-------+" + NEW_LINE_SEPARATOR;
for (int i = 0; i < SudokuBoard.BOARD_SIZE; i ++) {
for (int i = 0; i < SudokuBoard.BOARD_SIZE; i++) {
if ((i > 0) && (i < SudokuBoard.BOARD_SIZE) && (i % SudokuBoard.BOARD_SUB_SQURE_SIZE == 0))
boardStr = boardStr + "+-------+-------+-------+" + NEW_LINE_SEPARATOR ;
boardStr = boardStr + "+-------+-------+-------+" + NEW_LINE_SEPARATOR;
boardStr = boardStr + "| ";
for (int j = 0; j < SudokuBoard.BOARD_SIZE; j++) {
if ((j > 0) && (j < SudokuBoard.BOARD_SIZE) && (j % SudokuBoard.BOARD_SUB_SQURE_SIZE == 0))
boardStr = boardStr + "| ";
if (sudokuBoard[i, j] != BoardCell.EMPTY)
if (sudokuBoard[i, j] != BoardCell.EMPTY) {
boardStr = boardStr + sudokuBoard[i, j] + " ";
else
oneLineDefDot = oneLineDefDot + sudokuBoard[i, j];
oneLineDefZero = oneLineDefZero + sudokuBoard[i, j];
} else {
boardStr = boardStr + ". ";
oneLineDefDot = oneLineDefDot + '.';
oneLineDefZero = oneLineDefZero + '0';
}
}
boardStr = boardStr + "|" + NEW_LINE_SEPARATOR;
}
boardStr = boardStr + "+-------+-------+-------+" + NEW_LINE_SEPARATOR + NEW_LINE_SEPARATOR;
boardStr = boardStr + "# One line definition:" + NEW_LINE_SEPARATOR;
boardStr = boardStr + "# " + oneLineDefDot + NEW_LINE_SEPARATOR;
boardStr = boardStr + "# " + oneLineDefZero + NEW_LINE_SEPARATOR + NEW_LINE_SEPARATOR;
if (tailComment != null)
if (tailComment.Length > 0)
boardStr = boardStr + "# " + tailComment;
boardStr = NEW_LINE_SEPARATOR + NEW_LINE_SEPARATOR + boardStr + "# " + tailComment;
return boardStr;
}
/**
Expand Down

0 comments on commit eff1066

Please sign in to comment.