スパゲッティコード
#include <stdio.h>
#include <math.h>
#define DIS 1200
#define SPE 1200
#define VIT 1200
#define POW 1200
#define MEN 1200
#define WIS 1200
#define NIGE 0
#define SENK 1
#define SASH 2
#define OIKO 3
#define TEKI_S 0
#define TEKI_A 1
#define TEKI_B 2
#define TEKI_C 3
#define TEKI_D 4
#define TEKI_E 5
#define TEKI_F 6
#define TEKI_G 7
#define delta_t 0.001f
int kyakushitsu = NIGE;
int kyoritekisei = TEKI_A;
int babatekisei = TEKI_A;
int kyakushitsutekisei = TEKI_A;
float choice_kyakushitsu(void);
float calc_tekisei(int);
float hosei_speed(void);
float hosei_power(void);
float v_cur = 0;
float dis_cur = 0;
float hp_cur;
float a_cur;
int tmp_t = 0;
int dist = DIS;
int speed = SPE;
int vital = VIT;
int power = POW;
int ment = MEN;
int wis = WIS;
float hp_next(void);
float dis_next(void);
float v_next(void);
float v_wis_hosei(int);
float v_goal(void);
float a_next(void);
float choice_kyakushitsu(void);
void keisoku(void);
void keisoku2(void);
float choice_kyakushitsu(void)
{
float ret_keisu;
{
switch (kyakushitsu)
{
case NIGE:
ret_keisu = 1.0f;
break;
case SENK:
ret_keisu = 0.978f;
break;
case SASH:
ret_keisu = 0.938f;
break;
case OIKO:
ret_keisu = 0.931f;
break;
}
}
{
switch (kyakushitsu)
{
case NIGE:
ret_keisu = 0.98f;
break;
case SENK:
ret_keisu = 0.991f;
break;
case SASH:
ret_keisu = 0.998f;
break;
case OIKO:
ret_keisu = 1.0f;
break;
}
}
else // phase 2,3
{
switch (kyakushitsu)
{
case NIGE:
ret_keisu = 0.962f;
break;
case SENK:
ret_keisu = 0.975f;
break;
case SASH:
ret_keisu = 0.994f;
break;
case OIKO:
ret_keisu = 1.0f;
break;
}
}
return ret_keisu;
}
float v_wis_hosei(int wis1)
{
float ret_gosa;
ret_gosa = 1.0f + (log10(wis1 * 0.1f) * sqrt(wis1 / 5500.0f) - 0.325f) * 0.01f;
return ret_gosa;
}
float v_min(int konjo1)
{
float ret_v_min;
{
ret_a = -0.8f;
}
else if (v_cur < v_goal())
{
ret_a = 0.3f * sqrt(hosei_power() * 0.002f) * calc_tekisei(babatekisei);
}
else
{
ret_a = 0.0f;
}
{
return new_dis;
}
float hp_next(void)
{
float new_hp;
new_hp = hp_cur - v_cur * delta_t * 1; // 1 to hosei_konjo
return new_hp;
}
float hosei_speed(void)
{
float ret_speed;
ret_speed = (float)speed * calc_tekisei(babatekisei) * 1;
return ret_speed;
}
float hosei_power(void)
{
float ret_power;
ret_power = (float)power * calc_tekisei(babatekisei) * 1;
return ret_power;
}
void keisoku(void)
{
float t = 0.0f;
hp_cur = (float)dist + (float)vital;
v_cur = 0.0f;
a_cur = 24.0f;
dis_cur = 0.0f;
int tmp_t = 0;
float keisoku0_t = 0.0f;
float keisoku1_t = 0.0f;
float keisoku2_t = 0.0f;
int phase = 0;
#ifdef DEBUG
printf("\n");
#endif
while (dis_cur <= (float)dist)
{
#ifdef KASOKU
if (dis_cur < dist * 0.16667f)
{
keisoku0_t = keisoku0_t + delta_t;
if (((v_goal() - v_cur) <= 0.001f) & (phase == 0))
{
phase = 1;
printf("\njoban kasoku dist: %6.1f~%6.1fm, and kasoku time:%.1fs\n", dist * 0.0f, dis_cur, keisoku0_t);
}
}
else if (dis_cur < dist * 0.6668f)
{
keisoku0_t = 0.0f;
keisoku1_t = keisoku1_t + delta_t;
if (((v_goal() - v_cur) <= 0.001f) & (phase == 1))
{
phase = 2;
printf("chuban kasoku dist: %6.1f~%6.1fm, and kasoku time:%.1fs\n", dist * 0.16667f, dis_cur, keisoku1_t);
keisoku1_t = 0.0f;
}
}
else if (dis_cur < dist * 1.0f)
{
keisoku1_t = 0.0f;
keisoku2_t = keisoku2_t + delta_t;
if (((v_goal() - v_cur) <= 0.001f) & (phase == 2))
{
phase = 3;
printf("syuban kasoku dist: %6.1f~%6.1fm, and kasoku time:%.1fs\n", dist * 0.66667f, dis_cur, keisoku2_t);
keisoku2_t = 0.0f;
}
}
// tmp_t = tmp_t + 1;
// if (tmp_t >= 500)
// {
// if *7;
printf("v:%.2f, ", v_cur);
// printf("hp:%f\n", hp_cur);
printf("dis:%.1f\n", dis_cur);
tmp_t = 0;
}
#endif
}
printf("goal_time:%.2fs\n", t);
}
void keisoku2(void)
{
kyakushitsu = NIGE;
printf("[NIGE] ");
keisoku();
kyakushitsu = SENK;
printf("[SENK] ");
keisoku();
kyakushitsu = SASH;
printf("[SASH] ");
keisoku();
kyakushitsu = OIKO;
printf("[OIKO] ");
keisoku();
}
void main(void)
{
dist = 1200;
printf("\nDIS:%d, SPE:%d, STA:%d, POW:%d, KON:%d, WIS:%d \n", dist, speed, vital, power, ment, wis);
printf("BABA:A, KYORI:A, KYAKU:A \nlet's syussou\n");
keisoku2();
dist = 1600;
power = 1050;
printf("\nDIS:%d, SPE:%d, STA:%d, POW:%d, KON:%d, WIS:%d \n", dist, speed, vital, power, ment, wis);
printf("BABA:A, KYORI:A, KYAKU:A \nlet's syussou\n");
keisoku2();
dist = 2200;
power = 900;
printf("\nDIS:%d, SPE:%d, STA:%d, POW:%d, KON:%d, WIS:%d \n", dist, speed, vital, power, ment, wis);
printf("BABA:A, KYORI:A, KYAKU:A \nlet's syussou\n");
keisoku2();
dist = 3000;
power = 600;
printf("\nDIS:%d, SPE:%d, STA:%d, POW:%d, KON:%d, WIS:%d \n", dist, speed, vital, power, ment, wis);
printf("BABA:A, KYORI:A, KYAKU:A \nlet's syussou\n");
keisoku2();
}
return ret_v_min;
}
float calc_tekisei(int x)
{
float ret;
switch (x)
{
case TEKI_S: // S
ret = 1.05f;
break;
case TEKI_A: // A
ret = 1.0f;
break;
case TEKI_B: // B
ret = 0.85f;
break;
case TEKI_C: // C
ret = 0.75f;
break;
case TEKI_D: // D
ret = 0.6f;
break;
case TEKI_E: // E
ret = 0.4f;
break;
case TEKI_F: // F
ret = 0.2f;
break;
default: // G
ret = 0.1f;
break;
}
return ret;
}
float v_next(void)
{
float v_ret = v_cur + a_cur * delta_t;
return v_ret;
}
float a_next(void)
{
float ret_a;
if (v_cur <= 18.5f)
{
ret_a = 24 + 0.3f * sqrt(hosei_power() * 0.002f) * calc_tekisei(babatekisei);
}
else if ((hp_cur == 0) & (v_cur >= v_min(ment)))
{
ret_a = -1.2f;
}
// {
// ret_a = 0;
// }
return ret_a;
}
float v_goal(void)
{
}
else
{
return (20.0f - ((float)dist - 2000.0f) * 0.001f) * choice_kyakushitsu() + 2 * sqrt(hosei_speed() * 0.002f) * calc_tekisei(kyoritekisei) * choice_kyakushitsu();
}
}
float dis_next(void)
{
float new_dis;
new_dis = dis_cur + v_cur * v_wis_hosei((float)wis * calc_tekisei(kyakushitsutekisei
*7:a_cur > 0.0f & (a_next() > 0.0f)))
// {
// printf("v:%.2f, ", v_cur);
// printf("v_sabun:%.2f, ", fabs(v_cur - v_goal()));
// printf("dis:%.1f\n", dis_cur);
// }
// tmp_t = 0;
// }
#endif
v_cur = v_next();
hp_cur = hp_next();
a_cur = a_next();
dis_cur = dis_next();
t = t + delta_t;
#ifdef DEBUG
tmp_t = tmp_t + 1;
if (tmp_t >= 1000)
{
printf("time:%.1f, ", t);
// printf("a:%.2f, ", a_cur(