├── Bin ├── README.md ├── 0.jpg ├── 1.jpg ├── 2.jpg ├── 3.jpg ├── 4.jpg ├── 5.jpg ├── 6.jpg ├── 7.jpg ├── 8.jpg ├── 9.jpg ├── 10.jpg ├── 11.jpg ├── 12.jpg ├── track4+6.jpg └── track6+8.jpg ├── Anki.Tracks ├── App.config ├── Properties │ └── AssemblyInfo.cs ├── Anki.Tracks.csproj └── Program.cs ├── README.md ├── Anki.sln ├── .gitattributes └── .gitignore /Bin/README.md: -------------------------------------------------------------------------------- 1 | Images for html file 2 | -------------------------------------------------------------------------------- /Bin/0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiety/AnkiOverdrive/HEAD/Bin/0.jpg -------------------------------------------------------------------------------- /Bin/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiety/AnkiOverdrive/HEAD/Bin/1.jpg -------------------------------------------------------------------------------- /Bin/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiety/AnkiOverdrive/HEAD/Bin/2.jpg -------------------------------------------------------------------------------- /Bin/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiety/AnkiOverdrive/HEAD/Bin/3.jpg -------------------------------------------------------------------------------- /Bin/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiety/AnkiOverdrive/HEAD/Bin/4.jpg -------------------------------------------------------------------------------- /Bin/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiety/AnkiOverdrive/HEAD/Bin/5.jpg -------------------------------------------------------------------------------- /Bin/6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiety/AnkiOverdrive/HEAD/Bin/6.jpg -------------------------------------------------------------------------------- /Bin/7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiety/AnkiOverdrive/HEAD/Bin/7.jpg -------------------------------------------------------------------------------- /Bin/8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiety/AnkiOverdrive/HEAD/Bin/8.jpg -------------------------------------------------------------------------------- /Bin/9.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiety/AnkiOverdrive/HEAD/Bin/9.jpg -------------------------------------------------------------------------------- /Bin/10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiety/AnkiOverdrive/HEAD/Bin/10.jpg -------------------------------------------------------------------------------- /Bin/11.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiety/AnkiOverdrive/HEAD/Bin/11.jpg -------------------------------------------------------------------------------- /Bin/12.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiety/AnkiOverdrive/HEAD/Bin/12.jpg -------------------------------------------------------------------------------- /Bin/track4+6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiety/AnkiOverdrive/HEAD/Bin/track4+6.jpg -------------------------------------------------------------------------------- /Bin/track6+8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiety/AnkiOverdrive/HEAD/Bin/track6+8.jpg -------------------------------------------------------------------------------- /Anki.Tracks/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AnkiOverdrive 2 | Generates all possible Anki Overdrive tracks that you can build using your pieces 3 | 4 | http://xiety666.blogspot.com/2016/05/anki-overdrive.html 5 | 6 | Here are all posible tracks for my own 6 straight and 8 corner pieces (100 tracks): 7 | 8 | ![Output](/Bin/track6%2B8.jpg) 9 | 10 | Starter kit has only 9 tracks available: 11 | 12 | ![Output](/Bin/track4%2B6.jpg) 13 | -------------------------------------------------------------------------------- /Anki.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25123.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Anki.Tracks", "Anki.Tracks\Anki.Tracks.csproj", "{CD35B6A2-3280-45E8-BBFB-D7BE05CF3851}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {CD35B6A2-3280-45E8-BBFB-D7BE05CF3851}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {CD35B6A2-3280-45E8-BBFB-D7BE05CF3851}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {CD35B6A2-3280-45E8-BBFB-D7BE05CF3851}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {CD35B6A2-3280-45E8-BBFB-D7BE05CF3851}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /Anki.Tracks/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Anki.Tracks")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Anki.Tracks")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("cd35b6a2-3280-45e8-bbfb-d7be05cf3851")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /Anki.Tracks/Anki.Tracks.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {CD35B6A2-3280-45E8-BBFB-D7BE05CF3851} 8 | Exe 9 | Properties 10 | Anki.Tracks 11 | Anki.Tracks 12 | v4.6.1 13 | 512 14 | true 15 | 16 | 17 | 18 | AnyCPU 19 | true 20 | full 21 | false 22 | ..\Bin\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | 27 | 28 | AnyCPU 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 61 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | [Xx]64/ 19 | [Xx]86/ 20 | [Bb]uild/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | 85 | # Visual Studio profiler 86 | *.psess 87 | *.vsp 88 | *.vspx 89 | *.sap 90 | 91 | # TFS 2012 Local Workspace 92 | $tf/ 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | *.DotSettings.user 101 | 102 | # JustCode is a .NET coding add-in 103 | .JustCode 104 | 105 | # TeamCity is a build add-in 106 | _TeamCity* 107 | 108 | # DotCover is a Code Coverage Tool 109 | *.dotCover 110 | 111 | # NCrunch 112 | _NCrunch_* 113 | .*crunch*.local.xml 114 | nCrunchTemp_* 115 | 116 | # MightyMoose 117 | *.mm.* 118 | AutoTest.Net/ 119 | 120 | # Web workbench (sass) 121 | .sass-cache/ 122 | 123 | # Installshield output folder 124 | [Ee]xpress/ 125 | 126 | # DocProject is a documentation generator add-in 127 | DocProject/buildhelp/ 128 | DocProject/Help/*.HxT 129 | DocProject/Help/*.HxC 130 | DocProject/Help/*.hhc 131 | DocProject/Help/*.hhk 132 | DocProject/Help/*.hhp 133 | DocProject/Help/Html2 134 | DocProject/Help/html 135 | 136 | # Click-Once directory 137 | publish/ 138 | 139 | # Publish Web Output 140 | *.[Pp]ublish.xml 141 | *.azurePubxml 142 | 143 | # TODO: Un-comment the next line if you do not want to checkin 144 | # your web deploy settings because they may include unencrypted 145 | # passwords 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # NuGet Packages 150 | *.nupkg 151 | # The packages folder can be ignored because of Package Restore 152 | **/packages/* 153 | # except build/, which is used as an MSBuild target. 154 | !**/packages/build/ 155 | # Uncomment if necessary however generally it will be regenerated when needed 156 | #!**/packages/repositories.config 157 | # NuGet v3's project.json files produces more ignoreable files 158 | *.nuget.props 159 | *.nuget.targets 160 | 161 | # Microsoft Azure Build Output 162 | csx/ 163 | *.build.csdef 164 | 165 | # Microsoft Azure Emulator 166 | ecf/ 167 | rcf/ 168 | 169 | # Microsoft Azure ApplicationInsights config file 170 | ApplicationInsights.config 171 | 172 | # Windows Store app package directory 173 | AppPackages/ 174 | BundleArtifacts/ 175 | 176 | # Visual Studio cache files 177 | # files ending in .cache can be ignored 178 | *.[Cc]ache 179 | # but keep track of directories ending in .cache 180 | !*.[Cc]ache/ 181 | 182 | # Others 183 | ClientBin/ 184 | [Ss]tyle[Cc]op.* 185 | ~$* 186 | *~ 187 | *.dbmdl 188 | *.dbproj.schemaview 189 | *.pfx 190 | *.publishsettings 191 | node_modules/ 192 | orleans.codegen.cs 193 | 194 | # RIA/Silverlight projects 195 | Generated_Code/ 196 | 197 | # Backup & report files from converting an old project file 198 | # to a newer Visual Studio version. Backup files are not needed, 199 | # because we have git ;-) 200 | _UpgradeReport_Files/ 201 | Backup*/ 202 | UpgradeLog*.XML 203 | UpgradeLog*.htm 204 | 205 | # SQL Server files 206 | *.mdf 207 | *.ldf 208 | 209 | # Business Intelligence projects 210 | *.rdl.data 211 | *.bim.layout 212 | *.bim_*.settings 213 | 214 | # Microsoft Fakes 215 | FakesAssemblies/ 216 | 217 | # GhostDoc plugin setting file 218 | *.GhostDoc.xml 219 | 220 | # Node.js Tools for Visual Studio 221 | .ntvs_analysis.dat 222 | 223 | # Visual Studio 6 build log 224 | *.plg 225 | 226 | # Visual Studio 6 workspace options file 227 | *.opt 228 | 229 | # Visual Studio LightSwitch build output 230 | **/*.HTMLClient/GeneratedArtifacts 231 | **/*.DesktopClient/GeneratedArtifacts 232 | **/*.DesktopClient/ModelManifest.xml 233 | **/*.Server/GeneratedArtifacts 234 | **/*.Server/ModelManifest.xml 235 | _Pvt_Extensions 236 | 237 | # LightSwitch generated files 238 | GeneratedArtifacts/ 239 | ModelManifest.xml 240 | 241 | # Paket dependency manager 242 | .paket/paket.exe 243 | 244 | # FAKE - F# Make 245 | .fake/ -------------------------------------------------------------------------------- /Anki.Tracks/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Anki.Tracks 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | var tb = new TrackBuilder(); 14 | tb.Run(); 15 | } 16 | } 17 | 18 | public class TrackBuilder 19 | { 20 | private readonly List all = new List(); 21 | 22 | public void Run() 23 | { 24 | System.IO.File.WriteAllText(@"tracks.txt", ""); 25 | System.IO.File.WriteAllText(@"tracks.html", ""); 26 | 27 | //set your available pieces here 28 | var palette = new Palette(straight: 4 + 2, corner: 6 + 2); 29 | 30 | try 31 | { 32 | Recurse(new List { new Cell(new Pos(0, 0), 1) }, palette, 1); 33 | Recurse(new List { new Cell(new Pos(0, 0), 5) }, palette, 1); 34 | } 35 | finally 36 | { 37 | System.IO.File.AppendAllText(@"tracks.html", "
"); 38 | } 39 | } 40 | 41 | void Recurse(List cells, Palette palette, int level) 42 | { 43 | if (palette.IsEmpty()) 44 | return; 45 | 46 | var last = cells.Last(); 47 | var nextpos = NextPos(last); 48 | 49 | var hitcell = HitCell(cells, nextpos); 50 | 51 | if (hitcell == null) 52 | { 53 | for (var mode = 1; mode <= 12; ++mode) 54 | { 55 | DoNext(cells, palette, level, mode, last, nextpos); 56 | } 57 | } 58 | else 59 | { 60 | var first = cells.First(); 61 | 62 | if (first.Pos == nextpos && CanStack(last.Mode, first.Mode)) 63 | { 64 | Good(cells); 65 | } 66 | else 67 | { 68 | //straight track over (or under) another straight track here 69 | if (hitcell.Value.Mode == 1 || hitcell.Value.Mode == 2) 70 | { 71 | DoNext(cells, palette, level, 3, last, nextpos); 72 | DoNext(cells, palette, level, 4, last, nextpos); 73 | } 74 | else if (hitcell.Value.Mode == 3 || hitcell.Value.Mode == 4) 75 | { 76 | DoNext(cells, palette, level, 1, last, nextpos); 77 | DoNext(cells, palette, level, 2, last, nextpos); 78 | } 79 | } 80 | } 81 | } 82 | 83 | private void DoNext(List cells, Palette palette, int level, int mode, Cell last, Pos nextpos) 84 | { 85 | if (palette.Avail(mode)) 86 | { 87 | if (CanStack(last.Mode, mode)) 88 | { 89 | Recurse(cells.Union(new[] { new Cell(nextpos, mode) }).ToList(), palette.Without(mode), level + 1); 90 | } 91 | } 92 | } 93 | 94 | private static bool CanStack(int f, int to) 95 | { 96 | return (new[] { 1, 9, 12 }.Contains(to) && new[] { 1, 5, 7 }.Contains(f)) 97 | || (new[] { 2, 6, 8 }.Contains(to) && new[] { 2, 10, 11 }.Contains(f)) 98 | || (new[] { 3, 7, 11 }.Contains(to) && new[] { 3, 6, 9 }.Contains(f)) 99 | || (new[] { 4, 5, 10 }.Contains(to) && new[] { 4, 8, 12 }.Contains(f)); 100 | } 101 | 102 | private void Good(List cells) 103 | { 104 | //if (cells.Count == 14) //track length 105 | { 106 | var orig = GenerateMap(cells); 107 | 108 | //remove already found tracks 109 | if (!HasSame(orig)) 110 | { 111 | all.Add(orig); 112 | 113 | var text = GenerateTxt(cells); 114 | System.IO.File.AppendAllText(@"tracks.txt", text); 115 | 116 | var html = GenerateHtml(cells); 117 | 118 | html = "" + html + ""; 119 | 120 | if (all.Count != 0 && (all.Count - 1) % 16 == 0) 121 | { 122 | html = "" + html; 123 | } 124 | 125 | System.IO.File.AppendAllText(@"tracks.html", html); 126 | 127 | Console.WriteLine(text); 128 | } 129 | } 130 | } 131 | 132 | private bool HasSame(int[,] orig) 133 | { 134 | var rotate = orig; 135 | if (HasFlip(rotate)) return true; 136 | 137 | rotate = Rotate(rotate); 138 | if (HasFlip(rotate)) return true; 139 | 140 | rotate = Rotate(rotate); 141 | if (HasFlip(rotate)) return true; 142 | 143 | rotate = Rotate(rotate); 144 | if (HasFlip(rotate)) return true; 145 | 146 | return false; 147 | } 148 | 149 | private int[,] Rotate(int[,] map) 150 | { 151 | var lenx = map.GetLength(0); 152 | var leny = map.GetLength(1); 153 | 154 | var ret = new int[leny, lenx]; 155 | 156 | for (var x = 0; x < lenx; ++x) 157 | { 158 | for (var y = 0; y < leny; ++y) 159 | { 160 | ret[leny - y - 1, x] = map[x, y]; 161 | } 162 | } 163 | 164 | return ret; 165 | } 166 | 167 | private bool HasFlip(int[,] map) 168 | { 169 | if (HasMap(map)) return true; 170 | 171 | var flip = FlipHor(map); 172 | 173 | if (HasMap(flip)) return true; 174 | 175 | flip = FlipVert(map); 176 | 177 | if (HasMap(flip)) return true; 178 | 179 | return false; 180 | } 181 | 182 | private void DumpMap(int[,] map) 183 | { 184 | var lenx = map.GetLength(0); 185 | var leny = map.GetLength(1); 186 | 187 | for (var y = 0; y < leny; ++y) 188 | { 189 | for (var x = 0; x < lenx; ++x) 190 | { 191 | Console.Write(map[x, y]); 192 | } 193 | 194 | Console.WriteLine(); 195 | } 196 | 197 | Console.WriteLine(); 198 | } 199 | 200 | private int[,] FlipVert(int[,] map) 201 | { 202 | var lenx = map.GetLength(0); 203 | var leny = map.GetLength(1); 204 | 205 | var ret = new int[lenx, leny]; 206 | 207 | for (var x = 0; x < lenx; ++x) 208 | { 209 | for (var y = 0; y < leny; ++y) 210 | { 211 | ret[x, leny - y - 1] = map[x, y]; 212 | } 213 | } 214 | 215 | return ret; 216 | } 217 | 218 | private int[,] FlipHor(int[,] map) 219 | { 220 | var lenx = map.GetLength(0); 221 | var leny = map.GetLength(1); 222 | 223 | var ret = new int[lenx, leny]; 224 | 225 | for (var x = 0; x < lenx; ++x) 226 | { 227 | for (var y = 0; y < leny; ++y) 228 | { 229 | ret[lenx - x - 1, y] = map[x, y]; 230 | } 231 | } 232 | 233 | return ret; 234 | } 235 | 236 | private bool HasMap(int[,] map) 237 | { 238 | return all.Any(old => MapEquals(old, map)); 239 | } 240 | 241 | private bool MapEquals(int[,] a1, int[,] a2) 242 | { 243 | var lenx1 = a1.GetLength(0); 244 | var leny1 = a1.GetLength(1); 245 | 246 | var lenx2 = a2.GetLength(0); 247 | var leny2 = a2.GetLength(1); 248 | 249 | if (lenx1 != lenx2 || leny1 != leny2) return false; 250 | 251 | for (var x = 0; x < lenx1; ++x) 252 | { 253 | for (var y = 0; y < leny1; ++y) 254 | { 255 | if (a1[x, y] != a2[x, y]) 256 | return false; 257 | } 258 | } 259 | 260 | return true; 261 | } 262 | 263 | private string GenerateHtml(List cells) 264 | { 265 | var text = new StringBuilder(); 266 | 267 | var minx = cells.Min(a => a.Pos.X); 268 | var maxx = cells.Max(a => a.Pos.X); 269 | var miny = cells.Min(a => a.Pos.Y); 270 | var maxy = cells.Max(a => a.Pos.Y); 271 | 272 | for (var y = miny; y <= maxy; ++y) 273 | { 274 | for (var x = minx; x <= maxx; ++x) 275 | { 276 | var pos = new Pos(x, y); 277 | var symbol = 0; 278 | 279 | if (cells.Any(a => a.Pos == pos)) 280 | { 281 | var cell = cells.First(a => a.Pos == pos); 282 | symbol = cell.Mode; 283 | } 284 | 285 | text.Append($""); 286 | } 287 | 288 | text.Append("
"); 289 | } 290 | 291 | text.Append("
"); 292 | 293 | return text.ToString(); 294 | } 295 | 296 | private int[,] GenerateMap(List cells) 297 | { 298 | var minx = cells.Min(a => a.Pos.X); 299 | var maxx = cells.Max(a => a.Pos.X); 300 | var miny = cells.Min(a => a.Pos.Y); 301 | var maxy = cells.Max(a => a.Pos.Y); 302 | 303 | var ret = new int[(maxx - minx + 1) * 3, (maxy - miny + 1) * 3]; 304 | 305 | for (var y = miny; y <= maxy; ++y) 306 | { 307 | for (var x = minx; x <= maxx; ++x) 308 | { 309 | var pos = new Pos(x, y); 310 | 311 | foreach (var hit in cells.Where(cell => cell.Pos == pos)) 312 | { 313 | var symbol = GetPircePattern(hit.Mode); 314 | 315 | for (var ya = 0; ya <= 2; ++ya) 316 | { 317 | for (var xa = 0; xa <= 2; ++xa) 318 | { 319 | if (symbol[ya, xa] == 1) 320 | ret[(x - minx) * 3 + xa, (y - miny) * 3 + ya] = 1; 321 | } 322 | } 323 | } 324 | } 325 | } 326 | 327 | return ret; 328 | } 329 | 330 | private static int[,] GetPircePattern(int mode) 331 | { 332 | switch (mode) 333 | { 334 | case 1: 335 | case 2: 336 | return new[,] 337 | { 338 | {0, 1, 0}, 339 | {0, 1, 0}, 340 | {0, 1, 0} 341 | }; 342 | case 3: 343 | case 4: 344 | return new[,] 345 | { 346 | {0, 0, 0}, 347 | {1, 1, 1}, 348 | {0, 0, 0} 349 | }; 350 | case 5: 351 | case 6: 352 | return new[,] 353 | { 354 | {0, 0, 0}, 355 | {0, 1, 1}, 356 | {0, 1, 0} 357 | }; 358 | case 7: 359 | case 8: 360 | return new[,] 361 | { 362 | {0, 0, 0}, 363 | {1, 1, 0}, 364 | {0, 1, 0} 365 | }; 366 | case 9: 367 | case 10: 368 | return new[,] 369 | { 370 | {0, 1, 0}, 371 | {0, 1, 1}, 372 | {0, 0, 0} 373 | }; 374 | case 11: 375 | case 12: 376 | return new[,] 377 | { 378 | {0, 1, 0}, 379 | {1, 1, 0}, 380 | {0, 0, 0} 381 | }; 382 | default: 383 | return new[,] 384 | { 385 | {0, 0, 0}, 386 | {0, 0, 0}, 387 | {0, 0, 0} 388 | }; 389 | } 390 | } 391 | 392 | private string GenerateTxt(List cells) 393 | { 394 | var text = new StringBuilder(); 395 | 396 | text.AppendLine(all.Count + ": " + String.Join("-", cells.Select(a => a.Mode))); 397 | 398 | var minx = cells.Min(a => a.Pos.X); 399 | var maxx = cells.Max(a => a.Pos.X); 400 | var miny = cells.Min(a => a.Pos.Y); 401 | var maxy = cells.Max(a => a.Pos.Y); 402 | 403 | for (var y = miny; y <= maxy; ++y) 404 | { 405 | for (var x = minx; x <= maxx; ++x) 406 | { 407 | var pos = new Pos(x, y); 408 | var symbol = ' '; 409 | 410 | if (cells.Any(a => a.Pos == pos)) 411 | { 412 | var cell = cells.First(a => a.Pos == pos); 413 | 414 | symbol = Symbol(cell.Mode); 415 | } 416 | 417 | text.Append(symbol); 418 | } 419 | 420 | text.AppendLine(); 421 | } 422 | 423 | text.AppendLine(); 424 | 425 | return text.ToString(); 426 | } 427 | 428 | private static char Symbol(int mode) 429 | { 430 | switch (mode) 431 | { 432 | case 1: 433 | case 2: 434 | return '│'; 435 | case 3: 436 | case 4: 437 | return '─'; 438 | case 5: 439 | case 6: 440 | return '┌'; 441 | case 11: 442 | case 12: 443 | return '┘'; 444 | case 7: 445 | case 8: 446 | return '┐'; 447 | case 9: 448 | case 10: 449 | return '└'; 450 | default: 451 | return '*'; 452 | } 453 | } 454 | 455 | private Cell? HitCell(List cells, Pos nextpos) 456 | { 457 | if (cells.All(cell => cell.Pos != nextpos)) 458 | return null; 459 | 460 | return cells.First(cell => cell.Pos == nextpos); 461 | } 462 | 463 | private Pos NextPos(Cell last) 464 | { 465 | switch (last.Mode) 466 | { 467 | case 02: return last.Pos.Up(); 468 | case 10: return last.Pos.Up(); 469 | case 11: return last.Pos.Up(); 470 | case 01: return last.Pos.Down(); 471 | case 05: return last.Pos.Down(); 472 | case 07: return last.Pos.Down(); 473 | case 04: return last.Pos.Left(); 474 | case 08: return last.Pos.Left(); 475 | case 12: return last.Pos.Left(); 476 | case 03: return last.Pos.Right(); 477 | case 09: return last.Pos.Right(); 478 | case 06: return last.Pos.Right(); 479 | } 480 | 481 | throw new Exception(); 482 | } 483 | } 484 | 485 | public struct Palette 486 | { 487 | readonly int straight; 488 | readonly int corner; 489 | 490 | public Palette(int straight, int corner) 491 | { 492 | this.straight = straight; 493 | this.corner = corner; 494 | } 495 | 496 | public bool Avail(int mode) 497 | { 498 | if (mode >= 1 && mode <= 4) 499 | { 500 | return straight > 0; 501 | } 502 | else if (mode >= 5 && mode <= 12) 503 | { 504 | return corner > 0; 505 | } 506 | 507 | throw new Exception(); 508 | } 509 | 510 | public Palette Without(int mode) 511 | { 512 | var nexts = straight; 513 | var nextc = corner; 514 | 515 | if (mode >= 1 && mode <= 4) nexts--; 516 | if (mode >= 5 && mode <= 12) nextc--; 517 | 518 | return new Palette(nexts, nextc); 519 | } 520 | 521 | public bool IsEmpty() 522 | { 523 | return straight == 0 && corner == 0; 524 | } 525 | } 526 | 527 | [DebuggerDisplay("{X}, {Y}")] 528 | public struct Pos 529 | { 530 | public int X { get; } 531 | public int Y { get; } 532 | 533 | public Pos(int x, int y) 534 | { 535 | X = x; 536 | Y = y; 537 | } 538 | 539 | public Pos Down() 540 | { 541 | return new Pos(X, Y + 1); 542 | } 543 | 544 | public Pos Up() 545 | { 546 | return new Pos(X, Y - 1); 547 | } 548 | 549 | public Pos Left() 550 | { 551 | return new Pos(X - 1, Y); 552 | } 553 | 554 | public Pos Right() 555 | { 556 | return new Pos(X + 1, Y); 557 | } 558 | 559 | public static bool operator ==(Pos a, Pos b) 560 | { 561 | return a.X == b.X && a.Y == b.Y; 562 | } 563 | 564 | public static bool operator !=(Pos a, Pos b) 565 | { 566 | return a.X != b.X || a.Y != b.Y; 567 | } 568 | 569 | public bool Equals(Pos other) 570 | { 571 | return X == other.X && Y == other.Y; 572 | } 573 | 574 | public override bool Equals(object obj) 575 | { 576 | if (ReferenceEquals(null, obj)) return false; 577 | return obj is Pos && Equals((Pos)obj); 578 | } 579 | 580 | public override int GetHashCode() 581 | { 582 | unchecked 583 | { 584 | return (X * 397) ^ Y; 585 | } 586 | } 587 | } 588 | 589 | [DebuggerDisplay("{Pos.X}, {Pos.Y}, {Mode}")] 590 | public struct Cell 591 | { 592 | public Pos Pos { get; } 593 | public int Mode { get; } 594 | 595 | public Cell(Pos pos, int mode) 596 | { 597 | Pos = pos; 598 | Mode = mode; 599 | } 600 | } 601 | } 602 | --------------------------------------------------------------------------------