Skip to content

Instantly share code, notes, and snippets.

@GregLando113
Created January 2, 2017 09:00
Show Gist options
  • Save GregLando113/fcb65bc095bc440279391113153935af to your computer and use it in GitHub Desktop.
Save GregLando113/fcb65bc095bc440279391113153935af to your computer and use it in GitHub Desktop.
finds series of movements given a start angle to achieve a given end angle range in Zelda Ocarina of Time and Majoras Mask
#include <stdio.h>
#include <stdlib.h>
typedef struct _link_mvmt {
int offset;
char name[20];
} link_mvmt;
link_mvmt possible_movements[] = {
{32767, "180 TURN"},
{-16383, "90 TURN RIGHT"},
{16383, "90 TURN LEFT"},
{-15000, "BACKFLIP ROLL"},
{-7384, "SIDEHOP ROLL RIGHT"},
{7384, "SIDEHOP ROLL LEFT"}
};
unsigned sz_possible_mvmts = sizeof(possible_movements) / sizeof(*possible_movements);
int factorial(int n){
if(n == 0)
return 0;
else if(n == 1)
return 1;
else
return n * factorial(n-1);
}
typedef unsigned int movement;
int main(int argc, char** argv) {
if(argc != 5)
goto paramerrors;
int
src_ang = atoi(argv[1]),
dst_ang_lo = atoi(argv[2]),
dst_ang_hi = atoi(argv[3]),
moves_allowed = atoi(argv[4]);
if(!moves_allowed)
goto paramerrors;
int
possible_combinations = factorial(moves_allowed);
int i, j;
int working_combinations = 0;
trialcombinations:
{
int *m = malloc(sizeof(movement) * moves_allowed);
unsigned short trial_ang;
for (i = 0; i < moves_allowed; ++i)
m[i] = 0;
for (i = 0; i < possible_combinations; ++i)
{
trial_ang = src_ang;
m[0]++;
for (j = 1; j < moves_allowed; ++j)
{
if (m[j - 1] > sz_possible_mvmts)
{
m[j - 1] = 0;
m[j]++;
}
}
for (j = 0; j < moves_allowed; ++j)
{
if (m[j] == 0)
continue;
trial_ang += possible_movements[m[j] - 1].offset;
}
if (trial_ang <= dst_ang_hi && trial_ang >= dst_ang_lo)
{
printf("Setup found:\n");
int idx = 0;
for (j = 0; j < moves_allowed; ++j)
{
if (m[j] == 0)
continue;
printf("move %d: %s\n", idx++, possible_movements[m[j] - 1].name);
}
printf("end angle = %d\n", trial_ang);
return 0;
}
}
}
if(working_combinations == 0)
printf("No possible combinations found :c\n");
return 0;
paramerrors:
printf("Incorrect parameters, require <src angle> <dst angle range low> <dst angle range high> <allowed moves>");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment