nissy-fmc

A Rubik's cube FMC assistant
git clone https://git.tronto.net/nissy-fmc
Download | Log | Files | Refs | README | LICENSE

nissy.c (1658B)


      1 #include <inttypes.h>
      2 #include <stdbool.h>
      3 #include <string.h>
      4 
      5 #include "cube.h"
      6 #include "coord.h"
      7 #include "solve.h"
      8 #include "steps.h"
      9 
     10 static bool set_step(char *, Step **);
     11 static bool set_solutiontype(char *, SolutionType *);
     12 static bool set_trans(char *, Trans *);
     13 
     14 static bool
     15 set_step(char *str, Step **step)
     16 {
     17 	int i;
     18 
     19 	for (i = 0; steps[i] != NULL; i++) {
     20 		if (!strcmp(steps[i]->shortname, str)) {
     21 			*step = steps[i];
     22 			return true;
     23 		}
     24 	}
     25 	
     26 	return false;
     27 }
     28 
     29 static bool
     30 set_solutiontype(char *str, SolutionType *st)
     31 {
     32 	if (!strcmp(str, "normal")) {
     33 		*st = NORMAL;
     34 		return true;
     35 	}
     36 	if (!strcmp(str, "inverse")) {
     37 		*st = INVERSE;
     38 		return true;
     39 	}
     40 	if (!strcmp(str, "niss")) {
     41 		*st = NISS;
     42 		return true;
     43 	}
     44 
     45 	return false;
     46 }
     47 
     48 static bool
     49 set_trans(char *str, Trans *t)
     50 {
     51 	if (!strcmp(str, "uf")) {
     52 		*t = uf;
     53 		return true;
     54 	}
     55 	if (!strcmp(str, "fr")) {
     56 		*t = fr;
     57 		return true;
     58 	}
     59 	if (!strcmp(str, "rd")) {
     60 		*t = rd;
     61 		return true;
     62 	}
     63 
     64 	return false;
     65 }
     66 
     67 void
     68 nissy_init(char *buf)
     69 {
     70 	int i;
     71 	size_t b;
     72 
     73 	init_cube();
     74 
     75 	b = 0;
     76 	for (i = 0; coordinates[i] != NULL; i++)
     77 		b += read_coord(coordinates[i], &buf[b]);
     78 }
     79 
     80 int
     81 nissy_solve(char *step, char *trans, int d, char *type, char *scramble, char *sol)
     82 {
     83 	Cube c;
     84 	Step *s;
     85 	Trans t;
     86 	SolutionType st;
     87 
     88 	make_solved(&c);
     89 	if (!set_step(step, &s)) return 1;
     90 	if (!set_trans(trans, &t)) return 2;
     91 	if (!set_solutiontype(type, &st)) return 4;
     92 	if (!apply_scramble(scramble, &c)) return 5;
     93 
     94 	sol[0] = 'h'; sol[1] = 'e'; sol[2] = 'l'; sol[3] = 'o'; sol[5] = 0;
     95 	return 0;
     96 	//return solve(s, t, d, st, &c, sol);
     97 }
     98 
     99 void
    100 nissy_test(char *response)
    101 {
    102 	strcpy(response, "nissy is running");
    103 }