WOWCube Docs logo
WOWCube Docs
Mission Control
Section Shortcuts
APIExamplesSourceWOWConnectChangelog
Filters
SDK and language defaults persist in cookies.
SDK version
Navigation Tree
Collapsed by default, focused on the active path.
Made byMcKay Seamons
GitHub
  1. Home
  2. Docs
  3. Source
  4. scramble.inc
Mission NodeSDK 6.1Pawnscramble.inc

scramble.inc

SDK Source File: scramble.inc

Source / SDK 6.1 / Pawn / Core

scramble.inc

scramble.inc
CPP
1/****h* PawnLibs/scramble
2 * Summary
3 * A helper library that facilitates level initialization.
4 * Description
5 * This library contains several useful utilities which simulate cube
6 * twists. An application can initialize its inner state data with wining
7 * condition and do some virtual twists to prepare initial arrangement for
8 * player like deck shuffling or Rubik'c cube scramble.
9 *
10 * To use this library several functions have to be defined:
11 * * RememberDataBeforeTwist()
12 * * SetDataAfterTwist(moduleTo, screenTo, moduleFrom, screenFrom)
13 * * VirtualTwist(twist[TOPOLOGY_TWIST_INFO])
14 *
15 * TBD - add detailed descriptions of required functions
16 * Example
17 * TBD - add example description
18 * new mapping[MODULES_MAX][SCREENS_MAX];
19 * new mappingTemp[MODULES_MAX][SCREENS_MAX];
20 *
21 * RememberDataBeforeTwist() {
22 * // Back up current mapping
23 * mappingTemp = mapping;
24 * }
25 *
26 * SetDataAfterTwist(moduleTo, screenTo, moduleFrom, screenFrom) {
27 * // Fill mapping according to the new topology after twise
28 * mapping[moduleTo][screenTo] = mappingTemp[moduleFrom][screenFrom];
29 * }
30 *
31 * VirtualTwist(twist[TOPOLOGY_TWIST_INFO]) {
32 * // Additional handling of virtual twist if necessary
33 * myTwist = twist;
34 * }
35 * History
36 * * v6.0 - added
37 ******/
38
39new scrambleTwist[TOPOLOGY_TWIST_INFO]; // .screen, .count, TOPOLOGY_twist: .direction
40new previosTwist[TOPOLOGY_TWIST_INFO] = [SCREENS_MAX, 0, TWIST_MAX];
41
42new ScrambleTopFaceletsStarting[SCREENS_MAX][MODULES_MAX / 2][TOPOLOGY_FACELET];
43new ScrambleTopFaceletsEnding[SCREENS_MAX][MODULES_MAX / 2][TOPOLOGY_FACELET];
44
45/****f* PawnLibs/scramble/Scramble
46 * Summary
47 * Scramble the cube randomly the specified number of times.
48 * Synopsis
49 */
50Scramble(twistsCount)
51/*
52 * Inputs
53 * * twistsCount - how many times to twist the cube for scramble
54 * Source
55 */
56{
57
58 if (twistsCount < 1) return;
59
60 scrambleTwist.count = 1;
61
62 for (new twistI = 0; twistI < twistsCount; ++twistI) {
63
64 RememberCurrentTopology();
65
66 scrambleTwist.screen = random(0, SCREENS_MAX - 1);
67 scrambleTwist.direction = random(TWIST_LEFT, TWIST_RIGHT);
68
69 if (scrambleTwist.screen == previosTwist.screen) {
70 scrambleTwist.screen = ++scrambleTwist.screen % SCREENS_MAX;
71 }
72
73 ScrambleRotate(scrambleTwist.screen, scrambleTwist.direction);
74
75 ScrambleTopFaceletsStarting = ScrambleTopFaceletsEnding;
76 previosTwist = scrambleTwist;
77 }
78}
79/******/
80
81/****f* PawnLibs/scramble/ScrambleRotate
82 * Summary
83 * Twist the cube around some screen in a specified direction.
84 * Synopsis
85 */
86ScrambleRotate(scr, dir)
87/*
88 * Inputs
89 * * scr - a screen to twist around
90 * * dir - a direction of the twist
91 * Source
92 */
93{
94
95 RememberDataBeforeTwist();
96
97 switch (dir) {
98 case TWIST_LEFT: {
99 for (new i = 0; i < MODULES_MAX / 2 - 1; ++i) {
100 ScrambleSwapFacelets(ScrambleTopFaceletsEnding[scr][i], ScrambleTopFaceletsEnding[scr][i + 1]);
101 }
102 }
103 case TWIST_RIGHT: {
104 for (new i = MODULES_MAX / 2 - 1; i >= 1; --i) {
105 ScrambleSwapFacelets(ScrambleTopFaceletsEnding[scr][i], ScrambleTopFaceletsEnding[scr][i - 1]);
106 }
107 }
108 }
109
110 for (new i = 0; i < MODULES_MAX / 2; ++i) {
111 for (new screen = 0; screen < SCREENS_MAX; ++screen) {
112 SetDataAfterTwist(
113 ScrambleTopFaceletsEnding[scr][i].module,
114 (ScrambleTopFaceletsEnding[scr][i].screen + screen) % SCREENS_MAX,
115 ScrambleTopFaceletsStarting[scr][i].module,
116 (ScrambleTopFaceletsStarting[scr][i].screen + screen) % SCREENS_MAX
117 );
118
119 }
120 }
121
122 VirtualTwist(scrambleTwist);
123}
124/******/
125
126ScrambleSwapFacelets(facelet1[TOPOLOGY_FACELET], facelet2[TOPOLOGY_FACELET]) {
127 new facelet[TOPOLOGY_FACELET];
128 facelet = facelet1;
129 facelet1 = facelet2;
130 facelet2 = facelet;
131}
132
133RememberCurrentTopology() {
134 new facelet[TOPOLOGY_FACELET];
135 new neighbor[TOPOLOGY_FACELET_INFO];
136
137 for (new screen = 0; screen < SCREENS_MAX; ++screen) {
138
139 facelet.module = 0;
140 facelet.screen = screen;
141 neighbor = TOPOLOGY_getAdjacentFacelet(facelet, NEIGHBOR_TOP);
142
143 for (new i = 0; i < MODULES_MAX / 2; ++i) {
144
145 facelet.module = neighbor.module;
146 facelet.screen = neighbor.screen;
147
148 ScrambleTopFaceletsStarting[screen][i] = facelet;
149
150 neighbor = TOPOLOGY_getAdjacentFacelet(facelet, NEIGHBOR_TOP);
151 facelet.module = neighbor.module;
152 facelet.screen = neighbor.screen;
153
154 neighbor = TOPOLOGY_getAdjacentFacelet(facelet, NEIGHBOR_RIGHT);
155 facelet.module = neighbor.module;
156 facelet.screen = neighbor.screen;
157 }
158 }
159 ScrambleTopFaceletsEnding = ScrambleTopFaceletsStarting;
160}
161
Wrapped for easier reading. Turn wrap off to inspect exact line lengths.
Context Rail

Related nodes

fixed.inc
Source / SDK 6.1 / Pawn / Core
graphics.inc
Source / SDK 6.1 / Pawn / Core
leaderboard.inc
Source / SDK 6.1 / Pawn / Core
log.inc
Source / SDK 6.1 / Pawn / Core
Previous Node
save.inc
Source / SDK 6.1 / Pawn / Core
Next Node
sound.inc
Source / SDK 6.1 / Pawn / Core