Skip to content

Instantly share code, notes, and snippets.

@ksheedlo
Created October 10, 2012 08:31
Show Gist options
  • Save ksheedlo/3864061 to your computer and use it in GitHub Desktop.
Save ksheedlo/3864061 to your computer and use it in GitHub Desktop.
Solver code for a puzzle in Bloodshot Stronghold - Borderlands 2
#include<stdint.h>
#include<stdio.h>
#define MAX_LEVEL 15
int32_t search(int32_t state, int32_t l, int32_t p, int32_t w, int32_t level) {
const int32_t table[3][4] = {
/* Pattern of XOR operations for the lever */
{ 20, 3, 20, 3 },
/* Pattern of XOR operations for the switch */
{ 13, 1, 13, 1 },
/* Pattern of XOR operations for the wheel */
{ 24, 21, 24, 21 }
};
const char *moves[] = {"lever", "switch", "wheel"};
for(int32_t i=0; i < 3; i++){
int32_t j;
switch(i) {
case 0: j = l; break;
case 1: j = p; break;
case 2: j = w; break;
}
int32_t res = state ^ table[i][j];
if(res == 0 && l == 0 && p == 0 && w == 0){
// Cycle detected
// printf("Found a cycle at level: %d\n", level);
continue;
}
if(res == 31){
// All green lights on
printf("%s ", moves[i]);
return 1;
}
int32_t lp = (i == 0) ? ((l+1) % 4) : l;
int32_t pp = (i == 1) ? ((p+1) % 4) : p;
int32_t wp = (i == 2) ? ((w+1) % 4) : w;
if(level < MAX_LEVEL && search(res, lp, pp, wp, level + 1)) {
printf("%s ", moves[i]);
return 1;
}
}
return 0;
}
int main(int argc, char **argv) {
search(0, 0, 0, 0, 1);
printf("\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment