-
Notifications
You must be signed in to change notification settings - Fork 1
/
Program.cs
175 lines (154 loc) · 6.59 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using System.Numerics;
using System.Reflection;
using System.Reflection.BASeCamp;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using BASeCamp.BASeScores;
using BASeCamp.Logging;
using BASeTris.AI;
using BASeTris.Blocks;
using BASeTris.Choosers;
using BASeTris.GameStates.GameHandlers;
using BASeTris.Tetrominoes;
using OpenTK;
using OpenTK.Input;
using static BASeTris.NNominoGenerator;
namespace BASeTris
{
static class Program
{
private const int SPI_GETWORKAREA = 48;
[DllImport("user32.dll", EntryPoint = "SystemParametersInfoA")]
private static extern int SystemParametersInfo(int uAction, IntPtr uParam, ref RECT lpvParam, int fuWinIni);
[StructLayout(LayoutKind.Sequential)]
private struct RECT
{
internal int Left;
internal int Top;
internal int Right;
internal int Bottom;
}
public static System.Reflection.BASeCamp.MultiTypeManager DITypes = null;
public static Type[] LoadTypes = new Type[] { typeof(NominoTheme), typeof(IBlockGameCustomizationHandler), typeof(BlockGroupChooser) };
public enum StartMode
{
Mode_WinForms,
Mode_OpenTK
}
public static StartMode RunMode = StartMode.Mode_OpenTK;
private static Dictionary<Type, Type[]> CacheHandlerTheme = new Dictionary<Type, Type[]>();
public static IEnumerable<Type> GetHandlerThemes(Type HandlerType)
{
if (CacheHandlerTheme.ContainsKey(HandlerType))
{
return CacheHandlerTheme[HandlerType];
}
var TheTypes = DITypes[typeof(NominoTheme)].GetManagedTypes();
List<Type> ConstructType = new List<Type>();
foreach (var iteratetype in TheTypes)
{
var attrib = (HandlerThemeAttribute)iteratetype.GetCustomAttribute(typeof(HandlerThemeAttribute));
if (attrib != null)
{
if (!attrib.Flags.HasFlag(HandlerThemeAttribute.HandlerThemeFlags.ThemeFlags_NonBrowsable) && attrib.HandlerType.Any((t) => t.IsAssignableFrom(HandlerType)))
//if(attrib.HandlerType.Contains(HandlerType))
{
ConstructType.Add(iteratetype);
}
}
}
CacheHandlerTheme.Add(HandlerType, ConstructType.ToArray());
return CacheHandlerTheme[HandlerType];
}
public static IEnumerable<Type> GetGameHandlers()
{
return DITypes[typeof(IBlockGameCustomizationHandler)].ManagedTypes;
}
const double Phi = 1.618033988749895;
const double phi = -1 / Phi;
public static double Fibonacci(int n)
{
return Math.Round((Math.Pow(Phi, n) - Math.Pow(phi, n)) / Math.Sqrt(5), 2);
}
private static void MultiMinoTest()
{
var firstresult = NNominoGenerator.GetPieces(6, null).ToList();
var result = NNominoGenerator.FilterPieces(firstresult).ToList();
StringBuilder sbreport = new StringBuilder();
int CurrentCount = 1;
foreach (var iterate in result)
{
String str = NNominoGenerator.GetDirectionString(iterate);
String strrep = NNominoGenerator.StringRepresentation(iterate);
sbreport.AppendLine("N-omino " + CurrentCount);
sbreport.AppendLine("");
sbreport.AppendLine(strrep);
CurrentCount++;
}
String strresult = sbreport.ToString();
//System.IO.File.WriteAllText("T:\\NominoOut.txt", strresult);
}
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
//Nomino MakeTester = new Tetromino_Y((a) => new LineSeriesBlock());
//var testresult = MakeTester.GetContiguousSets();
/* foreach(var iterate in NominoBuilder.BuildNominoes(5))
{
var buildstring = NominoBuilder.NominoToString(iterate);
}*/
//DebugLogger.EnableLogging = true;
//var testresult = SimpleAIEvolver.RunSimulation(new StoredBoardState.AIScoringRuleData());
//SimpleAIEvolver.RunSimulations();
//return;
DebugLogger.EnableLogging = true;
Debug.Print("Started");
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
DebugLogger.EnableLogging = true;
iManagerCallback cback = new LoggingCallback();
DITypes = new System.Reflection.BASeCamp.MultiTypeManager(
new Assembly[] { Assembly.GetExecutingAssembly() }.AsEnumerable(),
LoadTypes,
cback,
null,
null,
null);
if (RunMode == StartMode.Mode_WinForms)
{
Application.Run(new BASeTris());
}
else
{
/*var testresult = SNESTetrominoTheme.GetUnsetImage(0, 'T');
SkiaSharp.Views.Desktop.Extensions.ToBitmap(testresult).Save("T:\\T_SNES_UNSET.PNG");
var unsetTest = SNESTetrominoTheme.GetUnsetImage(0, 'Z');
SkiaSharp.Views.Desktop.Extensions.ToBitmap(unsetTest).Save("T:\\Z_SNES_UNSET.PNG");
var unsetTestS = SNESTetrominoTheme.GetUnsetImage(0, 'S');
SkiaSharp.Views.Desktop.Extensions.ToBitmap(unsetTestS).Save("T:\\S_SNES_UNSET.PNG");
var testresult2 = SNESTetrominoTheme.GetUnsetImage(6, 'I');
SkiaSharp.Views.Desktop.Extensions.ToBitmap(testresult2).Save("T:\\I_UNSET_SNES.PNG");*/
//return;
RECT returnedvalue = new RECT();
SystemParametersInfo(SPI_GETWORKAREA, IntPtr.Zero, ref returnedvalue, 0);
var DesiredHeight = (int)(((returnedvalue.Bottom - returnedvalue.Top) - 64) * .80f);
var DesiredWidth = (int)((float)DesiredHeight * .95f);
//DesiredHeight = 1557;
//DesiredWidth = 1672;
//1557,1672
Debug.Print($"Starting BTTK: {DesiredWidth},{DesiredHeight}");
new BASeTrisTK((int)(DesiredWidth*1.5f), (int)(DesiredHeight*1.5f)).Run();
}
}
}
}