/
circuit.c
5729 lines (5169 loc) · 171 KB
/
circuit.c
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
circuit.c
Copyright 2017-2020 Matthew T. Pandina. All rights reserved.
This file is part of Circuit Puzzle.
Circuit Puzzle is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
Circuit Puzzle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with Circuit Puzzle. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdint.h>
#include <stdbool.h>
#include <avr/io.h>
#include <stdlib.h>
#include <string.h>
#include <avr/pgmspace.h>
#include <uzebox.h>
#include <avr/interrupt.h>
#include "data/tileset.inc"
#include "data/sprites.inc"
#include "data/titlescreen.inc"
#include "data/patches.inc"
#include "data/mainsong.h"
#include "data/win_tileset.inc"
//#define OPTION_PERSIST_MUSIC_PREF
//#define OPTION_HIDE_CURSOR_DURING_LEVEL_COMPLETE
#define OPTION_HIDE_CURSOR_DURING_DRAG_AND_DROP
//#define OPTION_DEBUG_NETLIST
//#define OPTION_DEBUG_NETLIST_MATRIX
//#define OPTION_DEBUG_DISPLAY_PRUNED_BOARD
//#define OPTION_DEBUG_DISPLAY_GOAL_STATES
//#define OPTION_DEBUG_EPIC_WIN
#define EEPROM_ID 0x0400
#define EEPROM_SAVEGAME_VERSION 0x0001
struct EEPROM_SAVEGAME;
typedef struct EEPROM_SAVEGAME EEPROM_SAVEGAME;
struct EEPROM_SAVEGAME {
uint16_t id;
uint16_t version;
uint8_t bits[8];
char reserved[32 - 8];
} __attribute__ ((packed));
static void LoadHighScore(uint8_t* const bits)
{
EEPROM_SAVEGAME save = {0};
uint8_t retval = EepromReadBlock(EEPROM_ID, (struct EepromBlockStruct*)&save);
if (retval == EEPROM_ERROR_BLOCK_NOT_FOUND || save.version == 0xFFFF) {
save.id = EEPROM_ID;
save.version = EEPROM_SAVEGAME_VERSION;
for (uint8_t i = 0; i < 8; ++i)
save.bits[i] = 0;
EepromWriteBlock((struct EepromBlockStruct*)&save);
}
memcpy(bits, save.bits, 8);
}
static void SaveHighScore(const uint8_t* bits)
{
EEPROM_SAVEGAME save = {0};
save.id = EEPROM_ID;
save.version = EEPROM_SAVEGAME_VERSION;
memcpy(save.bits, bits, 8);
EepromWriteBlock((struct EepromBlockStruct*)&save);
}
// we need to store 61 bits, 0 = music on/off, 1-60 = level passed
uint8_t bitarray[8];
void BitArray_setBit(uint8_t index)
{
uint8_t offset = index / 8;
uint8_t mask = 1 << (index % 8);
bitarray[offset] |= mask;
}
void BitArray_clearBit(uint8_t index)
{
uint8_t offset = index / 8;
uint8_t mask = 1 << (index % 8);
bitarray[offset] &= mask ^ (uint8_t)0xFF;
}
bool BitArray_readBit(uint8_t index)
{
uint8_t offset = index / 8;
uint8_t mask = 1 << (index % 8);
return (bool)(bitarray[offset] & mask);
}
bool CompletedGame(void)
{
return ((bitarray[0] & 0xFE) == 0xFE && bitarray[1] == 0xFF && bitarray[2] == 0xFF && bitarray[3] == 0xFF &&
bitarray[4] == 0xFF && bitarray[5] == 0xFF && bitarray[6] == 0xFF && (bitarray[7] & 0x1F) == 0x1F);
}
void MyStopSong()
{
StopSong();
#if defined(OPTION_PERSIST_MUSIC_PREF)
BitArray_setBit(0);
SaveHighScore(bitarray);
#endif
}
void MyResumeSong()
{
ResumeSong();
#if defined(OPTION_PERSIST_MUSIC_PREF)
BitArray_clearBit(0);
SaveHighScore(bitarray);
#endif
}
#define UZEMH _SFR_IO8(25)
#define UZEMC _SFR_IO8(26)
#define TOKEN_WIDTH 3
#define TOKEN_HEIGHT 3
#define BOARD_WIDTH 5
#define BOARD_HEIGHT 5
#define BOARD_START_X 1
#define BOARD_START_Y 1
#define BOARD_H_SPACING 3
#define BOARD_V_SPACING 3
#define GOAL_WIDTH 4
#define GOAL_HEIGHT 3
#define GOAL_START_X 19
#define GOAL_START_Y 3
#define GOAL_H_SPACING 3
#define GOAL_V_SPACING 4
#define HAND_WIDTH 5
#define HAND_HEIGHT 2
#define HAND_START_X 1
#define HAND_START_Y 20
#define HAND_H_SPACING 4
#define HAND_V_SPACING 4
#define CONTROLS_LR_START_X (GOAL_START_X + 3)
#define CONTROLS_LR_START_Y (HAND_START_Y + 2)
#define CONTROLS_DPAD_START_X CONTROLS_LR_START_X
#define CONTROLS_DPAD_START_Y (CONTROLS_LR_START_Y + 2)
#define CONTROLS_A_START_X (CONTROLS_LR_START_X + 6)
#define CONTROLS_A_START_Y (CONTROLS_LR_START_Y + 2)
#define CONTROLS_B_START_X (CONTROLS_LR_START_X + 4)
#define CONTROLS_B_START_Y (CONTROLS_LR_START_Y + 3)
#define GAME_USER_RAM_TILES_COUNT 3
#define OVERLAY_SPRITE_START 0
#define PIECE_MASK 0x3F
#define FLAGS_MASK 0xC0
#define FLAG_ROTATE 0x40
#define FLAG_LOCKED 0x80
bool boardChanged = false;
bool switchChanged = false;
bool startAdvancesLevel = false;
bool startWinsGame = false;
typedef struct {
uint16_t held;
uint16_t prev;
uint16_t pressed;
uint16_t released;
} __attribute__ ((packed)) BUTTON_INFO;
void BoardChanged(BUTTON_INFO* buttons);
uint8_t GetLevelColor(uint8_t level);
void RamFont_Load2Digits(const uint8_t* ramfont, uint8_t ramfont_index, uint8_t number, uint8_t fg_color, uint8_t bg_color);
#define TILE_BACKGROUND 0
#define TILE_FOREGROUND 1
#define TILE_SHORT_VCC 2
#define TILE_SHORT_GND 3
#define TILE_SHORT_GND_ROT 4
#define TILE_VCC 5
#define TILE_GND 6
#define TILE_GND_ROT 7
#define TILE_BREADBOARD_TOP 8
#define TILE_BREADBOARD_BOTTOM 9
#define TILE_GOAL_MET 10
#define TILE_GOAL_UNMET 11
#define TILE_DPAD_LEFT 12
#define TILE_DPAD_RIGHT 13
// Defines for the pieces. Rotations are treated as different pieces.
#define P_BLANK 0
#define P_VCC_T 1
#define P_VCC_R 2
#define P_VCC_B 3
#define P_VCC_L 4
#define P_GND_LTR 5
#define P_GND_TRB 6
#define P_GND_RBL 7
#define P_GND_BLT 8
#define P_SW1_BL 9
#define P_SW1_LT 10
#define P_SW1_TR 11
#define P_SW1_RB 12
#define P_RLED_AB_CR 13
#define P_RLED_AL_CB 14
#define P_RLED_AT_CL 15
#define P_RLED_AR_CT 16
#define P_SW2_BT 17
#define P_SW2_LR 18
#define P_SW2_TB 19
#define P_SW2_RL 20
#define P_YLED_AL_CR 21
#define P_YLED_AT_CB 22
#define P_YLED_AR_CL 23
#define P_YLED_AB_CT 24
#define P_SW3_BR 25
#define P_SW3_LB 26
#define P_SW3_TL 27
#define P_SW3_RT 28
#define P_GLED_AB_CL 29
#define P_GLED_AL_CT 30
#define P_GLED_AT_CR 31
#define P_GLED_AR_CB 32
#define P_STRAIGHT_LR 33
#define P_STRAIGHT_TB 34
#define P_DBL_CORNER_TL_BR 35
#define P_DBL_CORNER_TR_BL 36
#define P_CORNER_BL 37
#define P_CORNER_TL 38
#define P_CORNER_TR 39
#define P_CORNER_BR 40
#define P_TPIECE_RBL 41
#define P_TPIECE_BLT 42
#define P_TPIECE_LTR 43
#define P_TPIECE_TRB 44
#define P_BRIDGE1_TB_LR 45
#define P_BRIDGE2_TB_LR 46
#define P_BLOCKER 47
// Unknown rotations (these only exist in the level definitions)
#define P_VCC_U 48
#define P_GND_U 49
#define P_SW1_U 50
#define P_RLED_U 51
#define P_SW2_U 52
#define P_YLED_U 53
#define P_SW3_U 54
#define P_GLED_U 55
#define P_STRAIGHT_U 56
#define P_DBL_CORNER_U 57
#define P_CORNER_U 58
#define P_TPIECE_U 59
#define P_BRIDGE_U 60
// Defines for the goals. There are no rotations.
#define P_GOAL_BLANK 0
#define P_GOAL_RLED_OFF 1
#define P_GOAL_YLED_OFF 2
#define P_GOAL_GLED_OFF 3
#define P_GOAL_RLED_ON 4
#define P_GOAL_YLED_ON 5
#define P_GOAL_GLED_ON 6
#define P_GOAL_SW1 7
#define P_GOAL_SW2 8
#define P_GOAL_SW3 9
////////////////////////////////////////////////////////////////////////
// For "mouse" acceleration
// Defined screen lower and upper boundaries
#define X_LB (TOKEN_WIDTH * TILE_WIDTH / 2)
#define X_UB (((SCREEN_TILES_H) * TILE_WIDTH) - (TOKEN_WIDTH * TILE_WIDTH / 2))
#define Y_LB (TOKEN_HEIGHT * TILE_HEIGHT / 2)
#define Y_UB (((SCREEN_TILES_V) * TILE_HEIGHT) - (TOKEN_HEIGHT * TILE_HEIGHT / 2))
// 1/32th of a second per frame (not really, but it makes the math faster, and the constants below have been adjusted to compensate)
#define CURSOR_FRAMES_PER_SECOND 32
#define CURSOR_FIXED_POINT_SHIFT 2
#define CURSOR_MAX_VELOCITY (64 << CURSOR_FIXED_POINT_SHIFT)
#define CURSOR_ACCELERATION 655
#define CURSOR_FRICTION 2800
// Converts from internal fixed point representation into screen pixels
#define CURSOR_NEAREST_SCREEN_PIXEL(p) (((p) + (1 << (CURSOR_FIXED_POINT_SHIFT - 1))) >> CURSOR_FIXED_POINT_SHIFT)
struct CURSOR;
typedef struct CURSOR CURSOR;
struct CURSOR {
uint8_t tag;
int16_t x;
int16_t y;
int16_t dx;
int16_t dy;
} __attribute__ ((packed));
CURSOR cursor;
void cursor_init(CURSOR* const c, const uint8_t tag, const uint8_t tileIndex, const uint8_t x, const uint8_t y)
{
c->tag = tag;
sprites[tag].tileIndex = tileIndex;
sprites[tag].x = x;
sprites[tag].y = y;
c->x = (int16_t)x << CURSOR_FIXED_POINT_SHIFT;
c->y = (int16_t)y << CURSOR_FIXED_POINT_SHIFT;
c->dx = c->dy = 0;
}
//__attribute__((optimize("O3")))
void cursor_update(CURSOR* c, uint16_t held)
{
bool wasLeft = (c->dx < 0);
bool wasRight = (c->dx > 0);
int16_t ddx = 0;
if (held & BTN_LEFT)
ddx -= CURSOR_ACCELERATION; // cursor wants to go left
else if (wasLeft)
ddx += CURSOR_FRICTION; // cursor was going left, but not anymore
if (held & BTN_RIGHT)
ddx += CURSOR_ACCELERATION; // cursor wants to go right
else if (wasRight)
ddx -= CURSOR_FRICTION; // cursor was going right, but not anymore
if ((held & BTN_LEFT) || (held & BTN_RIGHT) || wasLeft || wasRight) { // smaller and faster than 'if (ddx)'
// Integrate the X forces to calculate the new position (x,y) and the new velocity (dx,dy)
c->x += (c->dx / CURSOR_FRAMES_PER_SECOND);
c->dx += (ddx / CURSOR_FRAMES_PER_SECOND);
if (c->dx < -CURSOR_MAX_VELOCITY)
c->dx = -CURSOR_MAX_VELOCITY;
else if (c->dx > CURSOR_MAX_VELOCITY)
c->dx = CURSOR_MAX_VELOCITY;
// Clamp horizontal velocity to zero if we detect that the cursor's direction has changed
if ((wasLeft && (c->dx > 0)) || (wasRight && (c->dx < 0)))
c->dx = 0; // clamp at zero to prevent friction from making the cursor jiggle side to side
// Clamp X to within defined screen bounds
if (c->x > (X_UB << CURSOR_FIXED_POINT_SHIFT)) {
c->x = (X_UB << CURSOR_FIXED_POINT_SHIFT);
c->dx = 0;
} else if (c->x < (X_LB << CURSOR_FIXED_POINT_SHIFT)) {
c->x = X_LB << CURSOR_FIXED_POINT_SHIFT;
c->dx = 0;
}
}
bool wasUp = (c->dy < 0);
bool wasDown = (c->dy > 0);
int16_t ddy = 0;
if (held & BTN_UP)
ddy -= CURSOR_ACCELERATION; // cursor wants to go up
else if (wasUp)
ddy += CURSOR_FRICTION; // cursor was going up, but not anymore
if (held & BTN_DOWN)
ddy += CURSOR_ACCELERATION; // cursor wants to go down
else if (wasDown)
ddy -= CURSOR_FRICTION; // cursor was going down, but not anymore
if (held & BTN_UP || held & BTN_DOWN || wasUp || wasDown) { // smaller and faster than 'if (ddy)'
// Integrate the Y forces to calculate the new position (x,y) and the new velocity (dx,dy)
c->y += (c->dy / CURSOR_FRAMES_PER_SECOND);
c->dy += (ddy / CURSOR_FRAMES_PER_SECOND);
if (c->dy < -CURSOR_MAX_VELOCITY)
c->dy = -CURSOR_MAX_VELOCITY;
else if (c->dy > CURSOR_MAX_VELOCITY)
c->dy = CURSOR_MAX_VELOCITY;
// Clamp vertical velocity to zero if we detect that the cursor's direction has changed
if ((wasUp && (c->dy > 0)) || (wasDown && (c->dy < 0)))
c->dy = 0; // clamp at zero to prevent friction from making the cursor jiggle up and down
// Clamp Y to within defined screen bounds
if (c->y > (Y_UB << CURSOR_FIXED_POINT_SHIFT)) {
c->y = Y_UB << CURSOR_FIXED_POINT_SHIFT;
c->dy = 0;
} else if (c->y < (Y_LB << CURSOR_FIXED_POINT_SHIFT)) {
c->y = Y_LB << CURSOR_FIXED_POINT_SHIFT;
c->dy = 0;
}
}
// Set the cursor sprite to the screen pixel location that corresponds to our fixed point representation of x and y
sprites[c->tag].x = CURSOR_NEAREST_SCREEN_PIXEL(c->x);
sprites[c->tag].y = CURSOR_NEAREST_SCREEN_PIXEL(c->y);
}
////////////////////////////////////////////////////////////////////////
// We need to know the position of the X or checkbox when LoadLevel is called in order to update it in BoardChanged
uint8_t meetsRulesY = 0;
uint8_t currentLevel;
// XXX - Modify these arrays to use the #defines instead of hardcoded numbers
// The configuration of the playing board
uint8_t board[5][5] = {
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
};
// The pieces in the goal
uint8_t goal[3][4] = {
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 },
};
// To know when all 3 goals have been met when there is a switch in the level
bool met_goal[3] = { 0, 0, 0 };
// The pieces in your "hand" (that need to be placed on the board)
uint8_t hand[2][5] = {
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
};
// Used to prune pieces with loose ends before netlist generation
uint8_t pruned_board[5][5] = {
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
};
/* Each square may have an electron going in and/or out in any direction
IN OUT
0b 0000 0000
\\\\ \\\\__ top
\\\\ \\\__ right
\\\\ \\__ bottom
\\\\ \__ left
\\\\
\\\\__ top
\\\__ right
\\__ bottom
\__ left
*/
#define D_OUT_T 1
#define D_OUT_R 2
#define D_OUT_B 4
#define D_OUT_L 8
#define D_IN_T 16
#define D_IN_R 32
#define D_IN_B 64
#define D_IN_L 128
// The bitmap of where the electron is, and which direction(s) it is travelling
/* uint8_t directions[5][5] = { */
/* { 0, 0, 0, 0, 0 }, */
/* { 0, 0, 0, 0, 0 }, */
/* { 0, 0, 0, 0, 0 }, */
/* { 0, 0, 0, 0, 0 }, */
/* { 0, 0, 0, 0, 0 }, */
/* }; */
#define NL_VV 0
#define NL_00 1
#define NL_RA 2
#define NL_RC 3
#define NL_YA 4
#define NL_YC 5
#define NL_GA 6
#define NL_GC 7
// Used to store the netlist (can be made more efficient later)
uint8_t pruned_netlist[8][8] = {
{ 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0 },
};
const uint8_t levelData[] PROGMEM = {
// LEVEL 01
// Puzzle
P_VCC_B, 0, 0, 0, 0,
0, P_YLED_AL_CR, 0, 0, 0,
0, 0, P_STRAIGHT_TB, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
// Goal
P_GOAL_YLED_ON, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
// Hand
P_CORNER_U, P_CORNER_U, P_GND_U, 0, 0,
0, 0, 0, 0, 0,
// LEVEL 02
// Puzzle
0, 0, 0, 0, 0,
0, P_VCC_B, P_CORNER_BR, P_CORNER_BL, 0,
0, 0, P_BRIDGE2_TB_LR, P_CORNER_TL, 0,
0, P_GND_RBL, 0, 0, 0,
0, 0, 0, 0, 0,
// Goal
P_GOAL_GLED_ON, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
// Hand
P_CORNER_U, P_GLED_U, 0, 0, 0,
0, 0, 0, 0, 0,
// LEVEL 03
// Puzzle
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, P_CORNER_BL, 0, 0,
0, P_VCC_T, 0, P_CORNER_TL, 0,
0, 0, 0, 0, 0,
// Goal
P_GOAL_RLED_ON, P_GOAL_GLED_ON, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
// Hand
P_RLED_U, P_GLED_U, P_GND_U, 0, 0,
0, 0, 0, 0, 0,
// LEVEL 04
// Puzzle
0, 0, 0, 0, 0,
0, P_CORNER_BR, 0, P_CORNER_BL, 0,
0, 0, P_TPIECE_RBL, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
// Goal
P_GOAL_RLED_ON, P_GOAL_GLED_ON, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
// Hand
P_RLED_U, P_GLED_U, P_VCC_U, P_GND_U, 0,
0, 0, 0, 0, 0,
// LEVEL 05
// Puzzle
0, 0, 0, 0, 0,
P_VCC_R, P_TPIECE_RBL, P_TPIECE_RBL, 0, 0,
0, 0, P_GLED_AT_CR, 0, 0,
0, 0, P_STRAIGHT_LR, 0, 0,
0, 0, 0, 0, 0,
// Goal
P_GOAL_RLED_ON, P_GOAL_YLED_ON, P_GOAL_GLED_ON, 0,
0, 0, 0, 0,
0, 0, 0, 0,
// Hand
P_CORNER_U, P_CORNER_U, P_RLED_U, P_YLED_U, P_GND_U,
0, 0, 0, 0, 0,
// LEVEL 06
// Puzzle
0, P_GND_LTR, 0, P_VCC_B, 0,
0, 0, 0, 0, P_GLED_AB_CL,
0, P_BLOCKER, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
// Goal
P_GOAL_GLED_ON, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
// Hand
P_BRIDGE_U, P_CORNER_U, P_CORNER_U, P_CORNER_U, P_CORNER_U,
0, 0, 0, 0, 0,
// LEVEL 07
// Puzzle
0, P_RLED_AB_CR, 0, P_GLED_AB_CL, 0,
0, 0, 0, 0, 0,
0, 0, P_SW2_BT, 0, 0,
0, 0, P_VCC_T, 0, 0,
0, 0, 0, 0, 0,
// Goal
P_GOAL_SW1, P_GOAL_RLED_ON, P_GOAL_YLED_OFF, P_GOAL_GLED_OFF,
P_GOAL_SW2, P_GOAL_RLED_OFF, P_GOAL_YLED_ON, P_GOAL_GLED_OFF,
P_GOAL_SW3, P_GOAL_RLED_OFF, P_GOAL_YLED_OFF, P_GOAL_GLED_ON,
// Hand
P_STRAIGHT_U, P_STRAIGHT_U, P_CORNER_U, P_CORNER_U, P_YLED_U,
P_GND_U, 0, 0, 0, 0,
// LEVEL 08
// Puzzle
P_GLED_AR_CB, 0, P_VCC_L, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
P_GND_BLT, 0, 0, 0, 0,
0, 0, 0, 0, 0,
// Goal
P_GOAL_RLED_ON, P_GOAL_YLED_ON, P_GOAL_GLED_ON, 0,
0, 0, 0, 0,
0, 0, 0, 0,
// Hand
P_TPIECE_U, P_TPIECE_U, P_RLED_U, P_YLED_U, 0,
0, 0, 0, 0, 0,
// LEVEL 09
// Puzzle
0, 0, 0, P_RLED_AL_CB, 0,
0, 0, P_GLED_AT_CR, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
// Goal
P_GOAL_RLED_ON, P_GOAL_GLED_ON, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
// Hand
P_CORNER_U, P_CORNER_U, P_TPIECE_U, P_VCC_U, P_GND_U,
0, 0, 0, 0, 0,
// LEVEL 10
// Puzzle
0, 0, 0, 0, 0,
0, P_VCC_R, P_CORNER_BL, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, P_GLED_AT_CR, 0, 0,
// Goal
P_GOAL_YLED_ON, P_GOAL_GLED_ON, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
// Hand
P_CORNER_U, P_TPIECE_U, P_STRAIGHT_U, P_YLED_AB_CT, P_GND_U,
0, 0, 0, 0, 0,
// LEVEL 11
// Puzzle
0, 0, 0, P_STRAIGHT_LR, 0,
0, P_TPIECE_TRB, 0, 0, 0,
0, 0, P_GND_BLT, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
// Goal
P_GOAL_YLED_ON, P_GOAL_GLED_ON, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
// Hand
P_CORNER_U, P_CORNER_U, P_YLED_U, P_GLED_U, P_VCC_U,
0, 0, 0, 0, 0,
// LEVEL 12
// Puzzle
0, 0, P_BLOCKER, 0, 0,
P_STRAIGHT_TB, 0, 0, 0, 0,
0, 0, P_CORNER_BL, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
// Goal
P_GOAL_YLED_ON, P_GOAL_GLED_ON, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
// Hand
P_CORNER_U, P_TPIECE_U, P_YLED_U, P_GLED_U, P_VCC_U,
P_GND_U, 0, 0, 0, 0,
// LEVEL 13
// Puzzle
0, 0, P_GLED_AR_CB, 0, 0,
0, 0, 0, P_YLED_AR_CL, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
// Goal
P_GOAL_YLED_ON, P_GOAL_GLED_ON, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
// Hand
P_STRAIGHT_U, P_TPIECE_U, P_CORNER_U, P_CORNER_U, P_VCC_U,
P_GND_U, 0, 0, 0, 0,
// LEVEL 14
// Puzzle
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, P_CORNER_BL, 0,
0, P_SW2_LR, 0, P_GND_U, 0,
0, P_CORNER_TR, 0, 0, 0,
// Goal
P_GOAL_SW1, P_GOAL_RLED_ON, P_GOAL_YLED_OFF, P_GOAL_GLED_OFF,
P_GOAL_SW2, P_GOAL_RLED_OFF, P_GOAL_YLED_ON, P_GOAL_GLED_OFF,
P_GOAL_SW3, P_GOAL_RLED_OFF, P_GOAL_YLED_OFF, P_GOAL_GLED_ON,
// Hand
P_STRAIGHT_U, P_STRAIGHT_U, P_RLED_U, P_YLED_U, P_GLED_U,
P_VCC_U, 0, 0, 0, 0,
// LEVEL 15
// Puzzle
0, 0, P_VCC_B, 0, 0,
0, P_GLED_U, 0, 0, 0,
0, 0, 0, 0, 0,
P_GND_TRB, P_YLED_AR_CL, P_TPIECE_BLT, 0, 0,
P_CORNER_TR, P_STRAIGHT_LR, P_RLED_AT_CL, 0, 0,
// Goal
P_GOAL_RLED_OFF, P_GOAL_YLED_OFF, P_GOAL_GLED_ON, 0,
0, 0, 0, 0,
0, 0, 0, 0,
// Hand
P_TPIECE_U, P_CORNER_U, P_CORNER_U, P_CORNER_U, 0,
0, 0, 0, 0, 0,
// LEVEL 16
// Puzzle
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
P_SW2_BT, P_BRIDGE1_TB_LR, P_RLED_AL_CB, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
// Goal
P_GOAL_SW1, P_GOAL_RLED_OFF, P_GOAL_YLED_OFF, P_GOAL_GLED_OFF,
P_GOAL_SW2, P_GOAL_RLED_OFF, P_GOAL_YLED_ON, P_GOAL_GLED_ON,
P_GOAL_SW3, P_GOAL_RLED_ON, P_GOAL_YLED_ON, P_GOAL_GLED_OFF,
// Hand
P_CORNER_U, P_CORNER_U, P_YLED_U, P_GLED_U, P_VCC_U,
P_GND_U, 0, 0, 0, 0,
// LEVEL 17
// Puzzle
0, 0, 0, P_YLED_U, P_CORNER_BL,
0, P_BRIDGE1_TB_LR, 0, P_BLOCKER, 0,
P_CORNER_TR, P_GND_LTR, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
// Goal
P_GOAL_RLED_ON, P_GOAL_YLED_ON, P_GOAL_GLED_ON, 0,
0, 0, 0, 0,
0, 0, 0, 0,
// Hand
P_TPIECE_U, P_CORNER_U, P_RLED_U, P_GLED_U, P_VCC_U,
0, 0, 0, 0, 0,
// LEVEL 18
// Puzzle
P_BLOCKER, 0, P_GND_TRB, 0, 0,
0, 0, 0, 0, 0,
0, P_SW2_LR, 0, 0, 0,
0, 0, P_GLED_U, 0, 0,
P_VCC_T, 0, 0, 0, 0,
// Goal
P_GOAL_SW1, P_GOAL_RLED_ON, P_GOAL_YLED_ON, P_GOAL_GLED_OFF,
P_GOAL_SW2, P_GOAL_RLED_OFF, P_GOAL_YLED_ON, P_GOAL_GLED_OFF,
P_GOAL_SW3, P_GOAL_RLED_OFF, P_GOAL_YLED_ON, P_GOAL_GLED_ON,
// Hand
P_TPIECE_U, P_TPIECE_U, P_CORNER_U, P_CORNER_U, P_RLED_U,
P_YLED_U, 0, 0, 0, 0,
// LEVEL 19
// Puzzle
0, 0, P_GLED_AB_CL, 0, 0,
0, P_GND_BLT, 0, P_RLED_U, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, P_VCC_T, 0, 0,
// Goal
P_GOAL_RLED_ON, P_GOAL_YLED_ON, P_GOAL_GLED_ON, 0,
0, 0, 0, 0,
0, 0, 0, 0,
// Hand
P_TPIECE_U, P_BRIDGE_U, P_CORNER_U, P_CORNER_U, P_CORNER_U,
P_YLED_U, 0, 0, 0, 0,
// LEVEL 20
// Puzzle
0, 0, 0, 0, 0,
P_TPIECE_TRB, P_CORNER_BL, 0, 0, 0,
0, P_DBL_CORNER_U, 0, P_CORNER_BL, 0,
0, P_GLED_U, 0, 0, 0,
0, 0, 0, 0, 0,
// Goal
P_GOAL_RLED_ON, P_GOAL_GLED_ON, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
// Hand
P_CORNER_U, P_STRAIGHT_U, P_RLED_U, P_VCC_U, P_GND_U,
0, 0, 0, 0, 0,
// LEVEL 21
// Puzzle
0, 0, 0, 0, 0,
0, P_GLED_AR_CB, P_YLED_AR_CL, 0, 0,
0, P_CORNER_U, 0, P_CORNER_U, P_VCC_U,
0, 0, 0, 0, 0,
0, P_GND_BLT, 0, 0, 0,
// Goal
P_GOAL_RLED_ON, P_GOAL_YLED_OFF, P_GOAL_GLED_OFF, 0,
0, 0, 0, 0,
0, 0, 0, 0,
// Hand
P_CORNER_U, P_CORNER_U, P_TPIECE_U, P_TPIECE_U, P_RLED_U,
0, 0, 0, 0, 0,
// LEVEL 22
// Puzzle
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, P_CORNER_BL, 0, 0, 0,
0, 0, 0, P_GND_RBL, 0,
0, 0, P_STRAIGHT_LR, P_VCC_L, 0,
// Goal
P_GOAL_RLED_ON, P_GOAL_YLED_ON, P_GOAL_GLED_ON, 0,
0, 0, 0, 0,
0, 0, 0, 0,
// Hand
P_TPIECE_U, P_TPIECE_U, P_BRIDGE_U, P_RLED_AB_CR, P_YLED_AB_CT,
P_GLED_AB_CL, 0, 0, 0, 0,
// LEVEL 23
// Puzzle
0, 0, P_GND_TRB, 0, P_VCC_B,
0, 0, 0, P_GLED_AR_CB, 0,
0, 0, P_TPIECE_U, 0, 0,
0, 0, P_CORNER_TR, 0, 0,
0, 0, 0, 0, 0,
// Goal
P_GOAL_RLED_OFF, P_GOAL_YLED_ON, P_GOAL_GLED_OFF, 0,
0, 0, 0, 0,
0, 0, 0, 0,
// Hand
P_CORNER_U, P_TPIECE_U, P_BRIDGE_U, P_RLED_U, P_YLED_U,
0, 0, 0, 0, 0,
// LEVEL 24
// Puzzle
0, 0, 0, 0, 0,
0, P_GND_LTR, 0, 0, 0,
0, 0, P_DBL_CORNER_TL_BR, 0, 0,
P_CORNER_TR, 0, 0, P_CORNER_U, 0,
0, 0, P_VCC_U, 0, 0,
// Goal
P_GOAL_RLED_ON, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
// Hand
P_STRAIGHT_U, P_TPIECE_U, P_BRIDGE_U, P_CORNER_U, P_CORNER_U,
P_CORNER_U, P_RLED_U, 0, 0, 0,
// LEVEL 25
// Puzzle
0, 0, P_CORNER_BL, 0, 0,
P_VCC_B, P_YLED_U, P_RLED_U, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
// Goal
P_GOAL_RLED_ON, P_GOAL_YLED_ON, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
// Hand
P_STRAIGHT_U, P_TPIECE_U, P_CORNER_U, P_CORNER_U, P_CORNER_U,
P_GND_U, 0, 0, 0, 0,
// LEVEL 26
// Puzzle
0, 0, 0, 0, 0,
0, 0, 0, P_GND_TRB, 0,
P_RLED_AB_CR, 0, 0, P_TPIECE_TRB, 0,
0, P_DBL_CORNER_U, P_STRAIGHT_U, 0, 0,
0, 0, 0, 0, 0,
// Goal
P_GOAL_RLED_ON, P_GOAL_GLED_ON, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
// Hand
P_CORNER_U, P_CORNER_U, P_CORNER_U, P_CORNER_U, P_GLED_U,
P_VCC_U, 0, 0, 0, 0,
// LEVEL 27
// Puzzle
0, 0, P_CORNER_BR, 0, 0,
0, P_CORNER_U, P_SW2_BT, P_TPIECE_U, 0,
P_GND_RBL, 0, 0, 0, 0,
0, 0, 0, P_VCC_U, 0,
0, 0, 0, 0, 0,
// Goal
P_GOAL_SW1, P_GOAL_RLED_ON, 0, 0,
P_GOAL_SW2, P_GOAL_RLED_ON, 0, 0,
P_GOAL_SW3, P_GOAL_RLED_ON, 0, 0,
// Hand
P_BRIDGE_U, P_CORNER_U, P_CORNER_U, P_TPIECE_U, P_RLED_U,
0, 0, 0, 0, 0,
// LEVEL 28
// Puzzle
0, 0, P_GLED_AR_CB, 0, 0,
0, 0, 0, P_STRAIGHT_TB, 0,
0, 0, 0, P_DBL_CORNER_U, 0,
0, P_GND_RBL, 0, P_CORNER_U, P_YLED_AB_CT,
0, 0, P_BLOCKER, 0, 0,
// Goal
P_GOAL_YLED_ON, P_GOAL_GLED_ON, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
// Hand
P_STRAIGHT_U, P_CORNER_U, P_CORNER_U, P_CORNER_U, P_TPIECE_U,
P_TPIECE_U, P_VCC_U, 0, 0, 0,
// LEVEL 29
// Puzzle
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, P_GLED_AR_CB, 0,
0, 0, 0, 0, 0,
0, P_RLED_AR_CT, 0, 0, 0,
// Goal
P_GOAL_RLED_ON, P_GOAL_YLED_ON, P_GOAL_GLED_ON, 0,
0, 0, 0, 0,
0, 0, 0, 0,
// Hand
P_CORNER_U, P_STRAIGHT_U, P_TPIECE_U, P_YLED_U, P_VCC_U,
P_GND_U, 0, 0, 0, 0,
// LEVEL 30
// Puzzle
0, P_GND_TRB, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, P_GLED_AT_CR, 0, P_BLOCKER,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
// Goal
P_GOAL_RLED_ON, P_GOAL_YLED_ON, P_GOAL_GLED_ON, 0,
0, 0, 0, 0,
0, 0, 0, 0,
// Hand
P_TPIECE_U, P_BRIDGE_U, P_CORNER_U, P_CORNER_U, P_RLED_U,
P_YLED_U, P_VCC_U, 0, 0, 0,
// LEVEL 31
// Puzzle
0, 0, 0, 0, 0,
0, P_STRAIGHT_U, 0, P_VCC_T, 0,
0, 0, P_BLOCKER, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
// Goal
P_GOAL_RLED_ON, P_GOAL_YLED_ON, P_GOAL_GLED_ON, 0,
0, 0, 0, 0,
0, 0, 0, 0,
// Hand
P_CORNER_U, P_TPIECE_U, P_RLED_U, P_YLED_U, P_GLED_U,
P_GND_U, 0, 0, 0, 0,
// LEVEL 32
// Puzzle
0, 0, 0, 0, 0,
P_VCC_U, 0, P_CORNER_U, 0, 0,
0, 0, 0, 0, P_BLOCKER,
0, 0, P_CORNER_U, 0, P_CORNER_BL,
0, 0, 0, 0, 0,
// Goal
P_GOAL_RLED_ON, P_GOAL_GLED_ON, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
// Hand
P_STRAIGHT_U, P_TPIECE_U, P_DBL_CORNER_U, P_RLED_U, P_GLED_U,
P_GND_U, 0, 0, 0, 0,
// LEVEL 33