-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDebug.cs
More file actions
207 lines (187 loc) · 7.13 KB
/
Debug.cs
File metadata and controls
207 lines (187 loc) · 7.13 KB
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
using System;
using System.Collections.Generic;
using System.Text;
using static coil.Navigation;
using static coil.Util;
using static coil.Coilutil;
namespace coil
{
public static class Debug
{
//this should really check everything about the board - regen hits and replay everything.
public static void DoDebug(Level l, bool show=false, bool validateBoard = false)
{
if (validateBoard)
{
if (show)
{
ShowSeg(l);
ShowHit(l);
Show(l);
}
//always validate segs.
uint lastIndex = 0;
foreach (var seg in l.Segs)
{
if (seg.Len == 0)
{
WL("Bada");
}
if (show)
{
WL(seg.ToString());
}
if (lastIndex == 0)
{
lastIndex = seg.Index;
continue;
}
if (seg.Index < lastIndex)
{
//in preparation for well-spaced indexes, this should be > last rather than ==last+1
WL("Badb");
}
lastIndex = seg.Index;
}
Seg lastSeg = null;
foreach (var seg in l.Segs)
{
if (lastSeg != null)
{
if ((HDirs.Contains(lastSeg.Dir) && !VDirs.Contains(seg.Dir))
|| (VDirs.Contains(lastSeg.Dir) && !HDirs.Contains(seg.Dir)))
{
WL("Badc");
}
}
lastSeg = seg;
}
//recalculate the entire board and segs.
var fakeRows = new Dictionary<(int, int), Seg>();
var fakeHits = new Dictionary<(int, int), List<Seg>>();
for (var yy = 0; yy < l.Height; yy++)
{
for (var xx = 0; xx < l.Width; xx++)
{
fakeHits[(xx, yy)] = new List<Seg>();
fakeRows[(xx, yy)] = null;
}
}
var current = l.Segs.First.Value.Start;
fakeRows[current] = l.Segs.First.Value;
Seg lastSeg2 = null;
foreach (var seg in l.Segs)
{
lastSeg2 = seg;
//trace path
var lstep = 0;
while (lstep < seg.Len)
{
fakeRows[current] = seg;
current = Add(current, seg.Dir);
lstep++;
}
if (fakeRows[current] != null)
{
WL("Badd");
}
//track hits.
var seghit = Add(seg.Start, seg.Dir, seg.Len + 1);
if (!fakeHits.ContainsKey(seghit))
{
fakeHits[seghit] = new List<Seg>();
}
fakeHits[seghit].Add(seg);
}
var end = Add(lastSeg2.Start, lastSeg2.Dir, lastSeg2.Len);
fakeRows[end] = lastSeg2;
//validate that every hit is in a null row!
//this is not currently true.
foreach (var seg in l.Segs)
{
var candidate = seg.Start;
var ii = 1;
//you don't own your last square (unless at end, not accounted for)
while (ii < seg.Len)
{
candidate = Add(candidate, seg.Dir);
var rv = l.GetRowValue(candidate);
if (rv.Index == seg.Index)
{
ii++;
continue;
}
Show(l);
ShowSeg(l);
SaveWithPath(l, "../../../abc.png");
WL("Bad - mismapped square");
}
var segend = seg.GetHit();
var hit = l.GetRowValue(segend);
if (hit == null)
{
continue;
}
if (hit.Index < seg.Index)
{
continue;
}
WL("Bade");
Show(l);
ShowSeg(l);
SaveWithPath(l, "../../../abc.png");
WL(l.LevelConfiguration.GetStr());
}
//check both ways!
for (var xx = 0; xx < l.Width; xx++)
{
for (var yy = 0; yy < l.Height; yy++)
{
var key = (xx, yy);
var realHitvalue = l.Hits.Get(key);
var fakeHitValue = new List<Seg>();
if (fakeHits.ContainsKey(key))
{
fakeHitValue = fakeHits[key];
}
//just check count for now.
if (realHitvalue.Count != fakeHitValue.Count)
{
WL("Badf");
}
}
}
foreach (var key in fakeHits.Keys)
{
var realHitvalue = l.Hits.Get(key);
var fakeHitValue = fakeHits[key];
//just check count for now.
if (realHitvalue.Count != fakeHitValue.Count)
{
WL("Badg");
var ae = 3;
}
}
for (var yy = 0; yy < l.Height;yy++)
{
for (var xx = 0; xx < l.Width; xx++)
{
var sq = (xx, yy);
if (l.GetRowValue(sq)?.Index != fakeRows[sq]?.Index)
{
WL("Badh");
ShowSeg(l);
Show(l);
SaveWithPath(l, "../../../abc.png");
}
if (fakeRows[sq]?.Index != l.GetRowValue(sq)?.Index)
{
WL("Badi");
}
}
}
//validate fakehits and fakerows match rows!
}
}
}
}